Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include UI tests for blocks with Appium #676

Merged
merged 146 commits into from
Apr 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
146 commits
Select commit Hold shift + click to select a range
702077a
Changed accessibility of block elements, included .nvmrc
JavonDavis Feb 16, 2019
aa306fa
combining blockID and client ID to make testID for locating blocks
JavonDavis Feb 17, 2019
2bfd973
included testID for simple editor check
JavonDavis Feb 22, 2019
03858c7
renamed test files to better match with intent
JavonDavis Feb 22, 2019
9e9fa98
Update jest to ignoer page objects and locators
JavonDavis Feb 25, 2019
88b7391
simple interaction with blocks
JavonDavis Feb 26, 2019
2a76cd6
merge in changes for master and use environment variable to determine…
JavonDavis Feb 26, 2019
8e949ac
instability in type function, had to resort to a typing letter by letter
JavonDavis Feb 26, 2019
5fea42b
simplified to type, this works well on android but not so much on ios
JavonDavis Feb 27, 2019
06535c2
update before and after step in test to handle starting and stopping …
JavonDavis Feb 27, 2019
f4f7e22
use relative path for app paths
JavonDavis Feb 27, 2019
879c5e3
updated README
JavonDavis Feb 28, 2019
fd163ae
started refactoring into page object model
JavonDavis Mar 11, 2019
89ab16f
removed page and block functions from spec file
JavonDavis Mar 11, 2019
16ef7ab
reverted type function for consistency on iOS
JavonDavis Mar 11, 2019
409e1ac
remove console logs
JavonDavis Mar 11, 2019
815ba1d
fix majority of travis checks
JavonDavis Mar 12, 2019
5fd1d39
Merge branch 'develop' of https://github.com/wordpress-mobile/gutenbe…
JavonDavis Mar 12, 2019
55c994e
resolved flow errors
JavonDavis Mar 12, 2019
98a576f
resolved all eslint problems
JavonDavis Mar 12, 2019
5a203c8
excluding device tests from jest config
JavonDavis Mar 13, 2019
2a8b1c8
* resolved build error caused by initial data set
JavonDavis Mar 13, 2019
1e8a20e
submodule update
JavonDavis Mar 13, 2019
397e645
delete large file
JavonDavis Mar 13, 2019
65b7be6
updated submodule
JavonDavis Mar 13, 2019
e09284e
reverted intiial-html.js file
JavonDavis Mar 13, 2019
e644985
include simple test for editor load
JavonDavis Mar 13, 2019
be9d6fd
move afterall to end of describe
JavonDavis Mar 13, 2019
b5905fd
moved helper code out of test file into utils.js
JavonDavis Mar 13, 2019
2f54ed3
small fix to typo in accessibility label for block-toolbar
JavonDavis Mar 13, 2019
0f5fb54
rename toolbar button test IDs
JavonDavis Mar 13, 2019
1f6ff72
removal of redudant uses of testID props
JavonDavis Mar 14, 2019
f854050
remove local test config
JavonDavis Mar 14, 2019
7f6fcab
started integration to sauce labs
JavonDavis Mar 15, 2019
5627c28
Complete basic connection to sauce labs with two possible device conf…
JavonDavis Mar 16, 2019
928ec07
revert intial html changes
JavonDavis Mar 16, 2019
f13ae1c
update circle ci config with parameters for device-checks job
JavonDavis Mar 16, 2019
e8c0c4b
add android on device tests to ci
JavonDavis Mar 16, 2019
baad98a
rename Block to BlockInteraction
JavonDavis Mar 17, 2019
1efa97c
remove nvmrc
JavonDavis Mar 17, 2019
b998c81
fixed typo in ParagraphBlockInteraction class name
JavonDavis Mar 17, 2019
b5f0c36
fixed error caused from Block to BlockInteraction refactor
JavonDavis Mar 17, 2019
ce2d03e
included additional inline comments
JavonDavis Mar 17, 2019
eb3727d
included pre and post step in ui tests to change out initial-html.js
JavonDavis Mar 18, 2019
fc7d3f6
included pre and post step in ui tests to change out initial-html.js
JavonDavis Mar 18, 2019
2f38b81
Merge branch 'add/ci-support-ui-tests' of https://github.com/wordpres…
JavonDavis Mar 18, 2019
78c954e
updated jest ui tests config to use main override main jest config
JavonDavis Mar 18, 2019
546fa49
create script option for running tests without environment variable a…
JavonDavis Mar 18, 2019
fc61bf4
try1: update circleci config to build android and upload to sauce labs
JavonDavis Mar 18, 2019
af7490f
try2: update circleci config to build android and upload to sauce labs
JavonDavis Mar 18, 2019
39bdd7e
try3: update circleci config to build android and upload to sauce labs
JavonDavis Mar 18, 2019
43abeba
try4: update circleci config to build android and upload to sauce labs
JavonDavis Mar 18, 2019
410af64
try4: update circleci config to build android app
JavonDavis Mar 18, 2019
12ca311
try5: remove bundle step in build-android
JavonDavis Mar 18, 2019
adac5a6
try5: remove bundle step in build-android
JavonDavis Mar 18, 2019
57c8de4
try5: use android environment for android-device-checks job
JavonDavis Mar 18, 2019
b4030ce
try5: use android environment for android-device-checks job
JavonDavis Mar 18, 2019
67faed2
try5: use android environment for android-device-checks job
JavonDavis Mar 18, 2019
a73029d
try5: use android environment for android-device-checks job
JavonDavis Mar 18, 2019
503f643
try5: use android environment for android-device-checks job
JavonDavis Mar 18, 2019
78b8590
try5: use android environment for android-device-checks job
JavonDavis Mar 18, 2019
7a0de83
try5: try android image with correct node version
JavonDavis Mar 18, 2019
1de03f6
try5: try android image with correct node version
JavonDavis Mar 18, 2019
5ad81d1
try5: try android image 27 instead of 28
JavonDavis Mar 18, 2019
af0294c
try6: try bundling RN again
JavonDavis Mar 18, 2019
457ffd6
try6: try bundling RN again
JavonDavis Mar 19, 2019
a3de56c
try6: try bundling RN again
JavonDavis Mar 19, 2019
b7b16ed
try6: try bundling RN again
JavonDavis Mar 19, 2019
9de759b
try6: try bundling RN again
JavonDavis Mar 19, 2019
d0ee88d
try6: try bundling RN again
JavonDavis Mar 19, 2019
438ab7d
try6: try bundling RN again
JavonDavis Mar 19, 2019
2891b0b
try6: try bundling RN again
JavonDavis Mar 19, 2019
e3d0a34
try7: change android run step to update initial html
JavonDavis Mar 19, 2019
0172399
try7: change android run step to update initial html
JavonDavis Mar 19, 2019
46bb8a6
switch to macos environment on ios
JavonDavis Mar 19, 2019
36cffaa
switch to macos environment on ios
JavonDavis Mar 19, 2019
bff1bc5
remove yarn cache step in ios device tests and remove yarn install st…
JavonDavis Mar 19, 2019
37ad5b6
remove build android step from ios check
JavonDavis Mar 19, 2019
002678f
include missing yarn install step
JavonDavis Mar 19, 2019
a089058
include missing yarn install step
JavonDavis Mar 19, 2019
662f5ab
try running device tests with sudo access
JavonDavis Mar 19, 2019
70245d4
invlude step to brew install yarn
JavonDavis Mar 19, 2019
66a2d0c
upgrade yarn version
JavonDavis Mar 19, 2019
2d2fb69
upgrade yarn version
JavonDavis Mar 19, 2019
19c1979
set env variables inline
JavonDavis Mar 19, 2019
390ebe2
remove sudo yarn call
JavonDavis Mar 19, 2019
eeec9e1
include npm install step for yan
JavonDavis Mar 19, 2019
708585e
include npm install step for yan
JavonDavis Mar 19, 2019
dc9b881
include npm install step for yan
JavonDavis Mar 19, 2019
9e9e10c
include npm install step for yan
JavonDavis Mar 19, 2019
bcc9842
quit driver after sauce status publish
JavonDavis Mar 19, 2019
d7ea6ee
patch to how driver is dismissed
JavonDavis Mar 19, 2019
367d201
revert initial html
JavonDavis Mar 19, 2019
bf389da
try waiting a little longer for driver to initialize on iOS
JavonDavis Mar 20, 2019
f3ad2b2
include ios build steps in circleci configg
JavonDavis Mar 20, 2019
af4db53
try debug configuration
JavonDavis Mar 20, 2019
e80ac18
experiement with yarn ios
JavonDavis Mar 20, 2019
143589f
experiement with yarn ios
JavonDavis Mar 20, 2019
113ca5e
experiement with sudo yarn
JavonDavis Mar 20, 2019
2f1bb34
try sudo yarn install
JavonDavis Mar 20, 2019
63017ab
try without sudo again
JavonDavis Mar 20, 2019
a0a5444
try without sudo again
JavonDavis Mar 20, 2019
6dbb9e3
reorder config step
JavonDavis Mar 20, 2019
2f2dbfc
remove yarn start
JavonDavis Mar 20, 2019
8bacf67
remove build ios step
JavonDavis Mar 20, 2019
3c182ab
resolved error in zip command
JavonDavis Mar 21, 2019
744ce55
resolved error in zip command missing recursive flag
JavonDavis Mar 21, 2019
b345050
removed bundle file and included in gitignore
JavonDavis Mar 21, 2019
6915a74
reset bundle to develop
JavonDavis Mar 21, 2019
8f32b72
reset bundle to develop
JavonDavis Mar 21, 2019
139ebdf
change yarn ios to preios
JavonDavis Mar 21, 2019
05d8813
Update yarn-install cache key
jtreanor Mar 21, 2019
9ee8294
Add Carthage caching
jtreanor Mar 21, 2019
9debb49
Better caching and use xcodebuild
jtreanor Mar 21, 2019
98aa40d
Fix yarn cache and don't use xcodebuild
jtreanor Mar 21, 2019
7416ffd
Build debug
jtreanor Mar 21, 2019
c83c5ad
revert to the Release configuration
JavonDavis Mar 21, 2019
beb523b
resolve typo in app file location for CI
JavonDavis Mar 21, 2019
a53cea8
check for accessibility label updates
JavonDavis Mar 21, 2019
c4f45c1
wait a little longer on driver
JavonDavis Mar 21, 2019
1ecaa54
use block index instead of client ID for easier construction of block…
JavonDavis Mar 22, 2019
a3bd9ab
resolve conflicts with master
JavonDavis Mar 25, 2019
590a98e
resolve empty initial-html causing ci check errors
JavonDavis Mar 25, 2019
986d999
remove release configuration
JavonDavis Mar 26, 2019
ce4e9bb
update bundle output path
JavonDavis Mar 26, 2019
8be80dd
update circleci images
JavonDavis Mar 26, 2019
ce8d880
update circleci images
JavonDavis Mar 26, 2019
8dda3ae
remove cache for aztech
JavonDavis Mar 26, 2019
ac716ee
reuse original bundle command
JavonDavis Mar 26, 2019
509bdfb
accept licenses
JavonDavis Mar 26, 2019
8de552d
clean install yarn
JavonDavis Mar 26, 2019
19f32e3
update zip loation based on derived data
JavonDavis Mar 26, 2019
5b67b1f
fix device tests html file
JavonDavis Mar 26, 2019
6179d5a
include cache again
JavonDavis Mar 26, 2019
0469e42
fix error to accept licenses
JavonDavis Mar 26, 2019
27426a2
wait for sdkmanager license acceptance
JavonDavis Mar 26, 2019
43449b0
resolve merge conflict with develop
JavonDavis Mar 26, 2019
197accb
ignore non zero exit status on run ios failure
JavonDavis Mar 26, 2019
2302279
localize accessibilitylabel search in editor page
JavonDavis Mar 27, 2019
628bb9e
fixed linter error and merged in develop
JavonDavis Mar 27, 2019
a0fb6a8
changes to labels and indentation in certain areas
JavonDavis Mar 28, 2019
f045042
fixed linter error with extra space
JavonDavis Mar 28, 2019
92e359b
code indentation cleanup and undo change in scheme config
JavonDavis Apr 1, 2019
0743395
redo config change
JavonDavis Apr 1, 2019
8da08a7
remove react native install and add bundle scripts to package.json
JavonDavis Apr 1, 2019
339c207
remove unnecessary config owner update
JavonDavis Apr 1, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 118 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,45 @@ commands:
- restore_cache:
name: Restore Yarn Cache
keys:
- yarn-{{ checksum "yarn.lock" }}
- yarn-v2-{{ arch }}-{{ checksum "yarn.lock" }}
- run:
name: Yarn Install
command: yarn install --frozen-lockfile
command: YARN_CACHE_FOLDER=~/.cache/yarn yarn install --frozen-lockfile
- save_cache:
name: Save Yarn Cache
key: yarn-{{ checksum "yarn.lock" }}
key: yarn-v2-{{ arch }}-{{ checksum "yarn.lock" }}
paths:
- ~/.cache/yarn
build-android:
steps:
- run:
name: Change initial HTML file
command: |
cp ./bin/tmp/initial-device-tests-html.js ./src/app/initial-html.js
- run:
name: Bundle Debug android
command: yarn bundle:android:test
- run:
name: Gradle assemble debug android apk
command: |
cd android
./gradlew clean
./gradlew assembleDebug
build-ios:
steps:
- run:
name: Change initial HTML file
command: |
cp ./bin/tmp/initial-device-tests-html.js ./src/app/initial-html.js
- run:
name: Bundle iOS
command: |
yarn bundle:ios:test
- run:
name: Generate .app file
command: |
set +e
yarn react-native run-ios --configuration Release

jobs:
checks:
Expand Down Expand Up @@ -47,6 +77,87 @@ jobs:
- run:
name: Run Checks
command: bin/ci-checks-js.sh
android-device-checks:
docker:
- image: circleci/android:api-27-node8-alpha
steps:
- checkout
- run:
name: Checkout Gutenberg
command: |
git submodule init
git submodule update --recursive
- yarn-install
- run:
name: Accept Licenses
command: |
yes | sdkmanager --licenses > /dev/null
sleep 10
sdkmanager --update
background: true
- run:
name: Set Environment Variables
command: |
echo 'export TEST_RN_PLATFORM=android' >> $BASH_ENV
echo 'export TEST_ENV=sauce' >> $BASH_ENV
- build-android
- run:
name: Upload apk to sauce labs
command: |
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/automattic/Gutenberg.apk?overwrite=true --data-binary @./android/app/build/outputs/apk/debug/app-debug.apk
- run:
name: Run Device Tests
command: yarn device-tests
ios-device-checks:
macos:
xcode: "10.0"
steps:
- checkout
- run:
name: Checkout Gutenberg
command: |
git submodule init
git submodule update --recursive
- run: yarn clean:install
- run:
name: Set Environment Variables
command: |
echo 'export TEST_RN_PLATFORM=ios' >> $BASH_ENV
echo 'export TEST_ENV=sauce' >> $BASH_ENV
- restore_cache:
name: Restore Dependencies Cache
keys:
- dependencies-{{ checksum "react-native-aztec/ios/Cartfile.resolved" }}-{{
checksum "yarn.lock" }}
- dependencies-{{ checksum "react-native-aztec/ios/Cartfile.resolved" }}
- dependencies-
- run:
name: Yarn preios
command: yarn preios
- save_cache:
name: Save Dependencies Cache
key: dependencies-{{ checksum "react-native-aztec/ios/Cartfile.resolved" }}-{{
checksum "yarn.lock" }}
paths:
- react-native-aztec/ios/Carthage
- ~/.rncache
- build-ios
- run:
name: Zip up .app file
command: |
cp ./ios/main.jsbundle ./ios/build/Gutenberg/Build/Products/Release-iphonesimulator/gutenberg.app/main.jsbundle
cd ./ios/build/Gutenberg/Build/Products/Release-iphonesimulator/
zip -r ./Gutenberg.app.zip ./gutenberg.app
mv ./Gutenberg.app.zip ../../../../../../Gutenberg.app.zip
cd ../../../../../../
- run:
name: Upload .app to sauce labs
command: |
curl -u "$SAUCE_USERNAME:$SAUCE_ACCESS_KEY" -X POST -H "Content-Type: application/octet-stream" https://saucelabs.com/rest/v1/storage/automattic/Gutenberg.app.zip?overwrite=true --data-binary @./Gutenberg.app.zip
- run:
name: Run Device Tests
command: |
yarn device-tests

workflows:
gutenberg-mobile:
Expand All @@ -62,3 +173,7 @@ workflows:
name: Test Android
platform: android
check-tests: true
- ios-device-checks:
name: Test iOS on Device
- android-device-checks:
name: Test Android on Device
7 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ yarn-error.log*
*.apk
*.ap_
.gradle/
android/app/src/main/assets/

# files for the dex VM
*.dex
Expand Down Expand Up @@ -95,4 +96,8 @@ buck-out/
!.vscode/extensions.json

*.pot
bin/wp-cli.phar

# e2e output log
appium-out.log

bin/wp-cli.phar
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,23 @@ Then, open `chrome://inspect` in Chrome to attach the debugger (look into the "R

This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test.js` extension to have the files loaded by jest. See an example test [here](https://github.com/wordpress-mobile/gutenberg-mobile/blob/develop/src/app/App.test.js). The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html).

## UI Tests

This repository uses appium to run UI tests. The tests live in `__device-tests__` and are written using Appium to run tests against simulators and real devices. To run these you'll need to check off a few things:

* For now you'll need run `yarn start`, and then either `yarn ios` or `yarn android` at least once before trying to run the tests on the respective platform
* [Appium cli](https://github.com/appium/appium/blob/master/docs/en/about-appium/getting-started.md) installed and available globally, I'd also recommend using [appium doctor](https://github.com/appium/appium-doctor) to ensure all of appium's dependencies are good to go. You don't have to worry about starting the server yourself, the tests handle starting the server on port 4728, just be sure that the port is free or feel free to change the port number in the test file.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't look like installing appium globally is actually necessary. It seems to work fine if we add it to our dev dependencies and just boot it using yarn appium.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right! I'll make that change, thanks!

* For iOS a simulator should automatically launch but for Android you'll need to have an emulator fired up and running.

After those are checked off to run the UI tests on ios run

`yarn test:ui:ios`

and for android run,

`yarn test:ui:android`

Alternatively if you're experiencing problems that seem to be related to the tests starting the appium server, for example errors that say `Connection Refused`, `Connection Reset` or `The requested environment is not available`. Sorry about that this is still a WIP, you can manually start the appium server via [appium desktop](https://github.com/appium/appium-desktop) or the cli, then change the port number in the tests while commenting out the `beforeAll` and `afterAll` block.

## Static analysis and code style

Expand Down
73 changes: 73 additions & 0 deletions __device-tests__/blocks/block-interaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/** @flow
* @format */

/**
* External dependencies
*/
import wd from 'wd';
/**
* Internal dependencies
*/
import { isAndroid } from '../helpers/utils';

// Common code across used to interact with all blocks
export default class BlockInteraction {
driver: wd.PromiseChainWebdriver;
accessibilityIdKey: string;
name: string;
blockName: string;
element: wd.PromiseChainWebdriver.Element;
accessibilityId: string;
accessibilityIdXPathAttrib: string;
static index = 0;

constructor( driver: wd.PromiseChainWebdriver, name: string = 'Unsupported Block' ) {
this.driver = driver;
this.accessibilityIdKey = 'name';
this.accessibilityIdXPathAttrib = 'name';
this.name = name;

if ( isAndroid() ) {
this.accessibilityIdXPathAttrib = 'content-desc';
this.accessibilityIdKey = 'contentDescription';
}
}

// Each subclass must include a method to do the following:
// * Initialise the element and accessibilityId(By calling this.setupElement in most cases)
// * Initialise any elements specific to interactions with that block
async setup() {
throw 'Unimplemented setup function for this block';
}

async getAttribute( attributeName: string ) {
return await this.element.getAttribute( attributeName );
}

// Finds the wd element for new block that was added and sets the element attribute
// and accessibilityId attributes on this object
async setupElement( blockName: string, blocks: Set<string> ) {
await this.driver.sleep( 2000 );
const blockLocator = `block-${ BlockInteraction.index }-${ blockName }`;
this.element = await this.driver.elementByAccessibilityId( blockLocator );
this.accessibilityId = await this.getAttribute( this.accessibilityIdKey );

BlockInteraction.index += 1;
return blocks;
}

// attempts to type a string to a given element, need for this stems from
// https://github.com/appium/appium/issues/12285#issuecomment-471872239
// https://github.com/facebook/WebDriverAgent/issues/1084
async typeString( element: wd.PromiseChainWebdriver.Element, str: string ) {
await element.clear();
if ( isAndroid() ) {
return await element.type( str );
}
// iOS: Problem with Appium type function requiring me to do a little hacking to get it work,
// as a result typing on iOS will be slower
for ( let i = 0; i < str.length; i++ ) {
await element.type( str.charAt( i ) );
}
}
}
56 changes: 56 additions & 0 deletions __device-tests__/blocks/paragraph-block-interaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** @flow
* @format */

/**
* Internal dependencies
*/
import BlockInteraction from './block-interaction';
/**
* External dependencies
*/
import wd from 'wd';
import { isAndroid } from '../helpers/utils';

/**
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';

export default class ParagraphBlockInteraction extends BlockInteraction {
// FLow complaining about type annotation on Set class here but Set<string>(); doesn't resolve
// $FlowFixMe
static blocks = new Set();
textViewElement: wd.PromiseChainWebdriver.Element;

constructor( driver: wd.PromiseChainWebdriver ) {
super( driver, __( 'Paragraph' ) );
this.driver = driver;
this.blockName = 'core/paragraph';
}

// gets the TextView wd element for this paragraph block and sets it to
// the textViewElement attribute for this object
async setupTextView() {
await this.driver.sleep( 2000 );
let textViewElement = 'XCUIElementTypeTextView';
if ( isAndroid() ) {
textViewElement = 'android.widget.EditText';
}
const blockLocator = `//*[@${ this.accessibilityIdXPathAttrib }="${ this.accessibilityId }"]//${ textViewElement }`;
this.textViewElement = await this.driver.elementByXPath( blockLocator );
}

async setup() {
await this.setupElement( this.blockName, ParagraphBlockInteraction.blocks );
await this.setupTextView();
}

async sendText( str: string ) {
return await this.typeString( this.textViewElement, str );
}

async getText() {
const text = await this.textViewElement.text();
return text.toString().trim();
}
}
74 changes: 74 additions & 0 deletions __device-tests__/gutenberg-editor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/**
* @format
* */

/**
* Internal dependencies
*/
import EditorPage from './pages/editor-page';
import ParagraphBlockInteraction from './blocks/paragraph-block-interaction';
import { setupAppium, setupDriver, isLocalEnvironment, timer } from './helpers/utils';

jasmine.DEFAULT_TIMEOUT_INTERVAL = 120000;

describe( 'Gutenberg Editor tests', () => {
let appium;
let driver;
let editorPage;
let allPassed = true;

// Use reporter for setting status for saucelabs Job
if ( ! isLocalEnvironment() ) {
const reporter = {
specDone: async ( result ) => {
allPassed = allPassed && result.status !== 'failed';
},
};

jasmine.getEnv().addReporter( reporter );
}

beforeAll( async () => {
if ( isLocalEnvironment() ) {
appium = await setupAppium();
}

driver = await setupDriver();
} );

it( 'should be able to see visual editor', async () => {
editorPage = new EditorPage( driver );
await editorPage.expect();
} );

it( 'should be able to add a new Paragraph block', async () => {
let paragraphBlockInteraction = new ParagraphBlockInteraction( driver );
paragraphBlockInteraction = await editorPage.addNewBlock( paragraphBlockInteraction );
await paragraphBlockInteraction.sendText( 'Hello Gutenberg!' );
await timer( 3000 );
expect( await paragraphBlockInteraction.getText() ).toBe( 'Hello Gutenberg!' );
} );

afterAll( async () => {
if ( isLocalEnvironment() ) {
if ( driver === undefined ) {
if ( appium !== undefined ) {
await appium.kill( 'SIGINT' );
}
return;
}

await driver.quit();
await appium.kill( 'SIGINT' );
} else {
if ( driver === undefined ) {
if ( appium !== undefined ) {
await appium.kill( 'SIGINT' );
}
return;
}
driver.sauceJobStatus( allPassed );
await driver.quit();
}
} );
} );
Loading