Skip to content

Commit e0c4106

Browse files
authored
Lint and update JS sample code (appium#11927)
* Lint and update JS wd sample code * Lint and update JS webdriverio sample code * Add JS sample code to greenkeeper
1 parent 844094a commit e0c4106

21 files changed

+124
-86
lines changed

.eslintignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
sample-code
21
coverage
2+
node_modules

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ jobs:
1515
os: linux
1616
script: npm run test && npm run e2e-test
1717
node_js: "11"
18+
after_script: npm run coverage
1819
- stage:
1920
os: linux
2021
script: npm run test && npm run e2e-test

package.json

+13
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,19 @@
122122
"heapdump": "0.x"
123123
},
124124
"greenkeeper": {
125+
"groups": {
126+
"appium": {
127+
"packages": [
128+
"package.json"
129+
]
130+
},
131+
"sample-code": {
132+
"packages": [
133+
"sample-code/javascript-wd/package.json",
134+
"sample-code/javascript-webdriverio/package.json"
135+
]
136+
}
137+
},
125138
"ignore": []
126139
}
127140
}

sample-code/javascript-wd/.babelrc

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
11
{
2-
"presets": ["es2015", "stage-0"]
3-
}
2+
"presets": [
3+
[
4+
"@babel/preset-env",
5+
{
6+
"targets": {
7+
"node": "6"
8+
}
9+
}
10+
]
11+
]
12+
}

sample-code/javascript-wd/README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Setup
44

5-
* Must have NodeJS and NPM installed (https://nodejs.org/en/)
5+
* Must have NodeJS (6+) and NPM installed (https://nodejs.org/en/)
66
* Install dependencies by running `npm install`
77

88
## Running Tests
@@ -12,7 +12,7 @@
1212

1313
## Troubleshooting
1414

15-
* ```Original error: '11.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: x.y```
16-
* By default, these example tests expect IOS version 11.1
17-
* If 11.1 isn't available on your system, set the version by setting environment variable `IOS_PLATFORM_VERSION` or install with Xcode
18-
(e.g.: `IOS_PLATFORM_VERSION=11.2 $(npm bin)/mocha -t 6000000 test/path/to/test.js`)
15+
* ```Original error: '12.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: x.y```
16+
* By default, these example tests expect IOS version 12.1
17+
* If 12.1 isn't available on your system, set the version by setting environment variable `IOS_PLATFORM_VERSION`
18+
(e.g., `IOS_PLATFORM_VERSION=11.2 $(npm bin)/mocha -t 6000000 test/path/to/test.js`), or install the iOS 12.1 SDK with Xcode.

sample-code/javascript-wd/package.json

+10-6
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33
"version": "1.0.0",
44
"description": "Appium sample code using 'wd'",
55
"scripts": {
6-
"test": "mocha test/**/*.test.js"
6+
"test": "mocha test/**/*.test.js",
7+
"clean": "rm -rf node_modules && rm -f package-lock.json && npm install"
78
},
89
"author": "Dan Graham",
910
"license": "Apache-2.0",
11+
"engines": {
12+
"node": ">=6",
13+
"npm": ">=6"
14+
},
1015
"devDependencies": {
11-
"babel-core": "^6.26.0",
12-
"babel-polyfill": "^6.26.0",
13-
"babel-preset-es2015": "^6.24.1",
14-
"babel-preset-stage-0": "^6.24.1",
16+
"@babel/register": "^7.0.0",
17+
"@babel/core": "^7.0.0",
18+
"@babel/preset-env": "^7.0.0",
1519
"chai": "^4.1.2",
16-
"mocha": "^4.1.0",
20+
"mocha": "^5.2.0",
1721
"wd": "^1.5.0"
1822
}
1923
}

sample-code/javascript-wd/test/basic/android-basic-interactions.test.js

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import wd from 'wd';
22
import chai from 'chai';
33
import { androidCaps, serverConfig } from '../helpers/caps';
4-
54
const {assert} = chai;
65

6+
77
const PACKAGE = 'io.appium.android.apis';
88
const SEARCH_ACTIVITY = '.app.SearchInvoke';
99
const ALERT_DIALOG_ACTIVITY = '.app.AlertDialogSamples';
1010

1111
describe('Basic Android interactions', function () {
12-
1312
let driver;
1413

1514
before(async function () {
@@ -60,4 +59,4 @@ describe('Basic Android interactions', function () {
6059
// Close the dialog
6160
await closeDialogButton.click();
6261
});
63-
});
62+
});

sample-code/javascript-wd/test/basic/android-create-session.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import wd from 'wd';
22
import chai from 'chai';
3-
import { iosCaps, androidCaps, serverConfig } from '../helpers/caps';
3+
import { androidCaps, serverConfig } from '../helpers/caps';
44

55
const {assert} = chai;
66

@@ -23,4 +23,4 @@ describe('Create Android session', function () {
2323
// Quit the session
2424
await driver.quit();
2525
});
26-
});
26+
});

sample-code/javascript-wd/test/basic/android-create-web-session.test.js

+10-7
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,27 @@ import { androidCaps, serverConfig } from '../helpers/caps';
55
const {assert} = chai;
66

77
describe('Create Chrome web session', function () {
8-
it('should create and destroy Android browser session', async function () {
8+
let driver;
9+
before(async function () {
910
// Connect to Appium server
10-
const driver = await wd.promiseChainRemote(serverConfig);
11+
driver = await wd.promiseChainRemote(serverConfig);
1112

1213
// Start the session
1314
await driver.init({
1415
...androidCaps,
1516
browserName: 'Chrome'
1617
});
17-
18+
});
19+
after(async function () {
20+
// Quit the session
21+
await driver.quit();
22+
});
23+
it('should create and destroy Android browser session', async function () {
1824
// Navigate to google.com
1925
await driver.get('https://www.google.com');
2026

2127
// Test that it was successful by checking the document title
2228
const pageTitle = await driver.title();
2329
assert.equal(pageTitle, 'Google');
24-
25-
// Quit the session
26-
await driver.quit();
2730
});
28-
});
31+
});

sample-code/javascript-wd/test/basic/ios-selectors.test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ describe('Basic IOS selectors', function () {
4444

4545
it('should find elements by class chain', async function () {
4646
// This is also an IOS-specific selector strategy. Similar to XPath. This is recommended over XPath.
47-
const windowElement = await driver.elements('-ios class chain', 'XCUIElementTypeWindow[1]/*[2]');
47+
const windowElement = await driver.elements('-ios class chain', 'XCUIElementTypeWindow[1]/*');
4848
assert.equal(windowElement.length, 1);
4949
});
5050

@@ -54,4 +54,4 @@ describe('Basic IOS selectors', function () {
5454
const buttons = await driver.elementsByXPath('//XCUIElementTypeWindow//XCUIElementTypeButton');
5555
assert.isAbove(buttons.length, 1, 'Should have more than one button');
5656
});
57-
});
57+
});
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
import path from 'path';
22

3+
4+
const githubAssetBase = "http://appium.github.io/appium/assets";
5+
const localAssetBase = path.resolve(__dirname, "..", "..", "..", "apps");
6+
37
if (process.env.SAUCE_LABS) {
48
// TODO: Change thes URL's to updated locations
5-
exports.iosTestApp = "http://appium.github.io/appium/assets/TestApp7.1.app.zip";
6-
exports.androidApiDemos = "http://appium.github.io/appium/assets/ApiDemos-debug.apk";
9+
exports.iosTestApp = `${githubAssetBase}/TestApp7.1.app.zip`;
10+
exports.androidApiDemos = `${githubAssetBase}/ApiDemos-debug.apk`;
711
} else {
8-
exports.iosTestApp = path.resolve(__dirname, "..", "..", "apps", "TestApp.app.zip");
9-
exports.androidApiDemos = path.resolve(__dirname, "..", "..", "apps", "ApiDemos-debug.apk");
12+
exports.iosTestApp = path.resolve(localAssetBase, "TestApp.app.zip");
13+
exports.androidApiDemos = path.resolve(localAssetBase, "ApiDemos-debug.apk");
1014
}

sample-code/javascript-wd/test/helpers/caps.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
import path from 'path';
2-
31
const iosCaps = {
42
platformName: 'iOS',
53
automationName: 'XCUITest',
6-
deviceName: process.env.IOS_DEVICE_NAME || 'iPhone 6s',
7-
platformVersion: process.env.IOS_PLATFORM_VERSION || '11.1',
4+
deviceName: process.env.IOS_DEVICE_NAME || 'iPhone 6s',
5+
platformVersion: process.env.IOS_PLATFORM_VERSION || '12.1',
86
app: undefined, // Will be added in tests
97
};
108

11-
// Leave the Android platformVersion blank and set deviceName to a random string (Android deviceName is ignored by Appium but is still required)
12-
// If we're using SauceLabs, set the Android deviceName and platformVersion to the latest supported SauceLabs device and version
9+
// Leave the Android platformVersion blank and set deviceName to a random string
10+
// (Android deviceName is ignored by Appium but is still required)
11+
// If we're using SauceLabs, set the Android deviceName and platformVersion to
12+
// the latest supported SauceLabs device and version
1313
const DEFAULT_ANDROID_DEVICE_NAME = process.env.SAUCE_LABS ? 'Android GoogleAPI Emulator' : 'My Android Device';
1414
const DEFAULT_ANDROID_PLATFORM_VERSION = process.env.SAUCE_LABS ? '7.1' : null;
1515

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
--compilers babel-core/register
2-
--require babel-polyfill
1+
--require @babel/register
32
--timeout 1800000

sample-code/javascript-webdriverio/README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
## Troubleshooting
1414

15-
* ```Original error: '11.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: x.y```
16-
* By default, these example tests expect IOS version 11.1
17-
* If 11.1 isn't available on your system, set the version by setting environment variable `IOS_PLATFORM_VERSION` or install with Xcode
18-
(e.g.: `IOS_PLATFORM_VERSION=11.2 $(npm bin)/mocha -t 6000000 test/path/to/test.js`)
15+
* ```Original error: '12.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: x.y```
16+
* By default, these example tests expect IOS version 12.1
17+
* If 12.1 isn't available on your system, set the version by setting environment variable `IOS_PLATFORM_VERSION`
18+
(e.g., `IOS_PLATFORM_VERSION=11.2 $(npm bin)/mocha -t 6000000 test/path/to/test.js`), or install the iOS 12.1 SDK with Xcode.

sample-code/javascript-webdriverio/helpers/caps.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
1-
const path = require("path");
2-
31
const iosCaps = {
42
platformName: "iOS",
53
automationName: "XCUITest",
64
deviceName: process.env.IOS_DEVICE_NAME || "iPhone 6s",
7-
platformVersion: process.env.IOS_PLATFORM_VERSION || "11.1",
5+
platformVersion: process.env.IOS_PLATFORM_VERSION || "12.1",
86
app: undefined // Will be added in tests
97
};
108

119
const iosWebCaps = {
1210
platformName: "iOS",
1311
automationName: "XCUITest",
1412
deviceName: process.env.IOS_DEVICE_NAME || "iPhone 6s",
15-
platformVersion: process.env.IOS_PLATFORM_VERSION || "11.1",
13+
platformVersion: process.env.IOS_PLATFORM_VERSION || "12.1",
1614
browserName: "Safari"
1715
};
1816

sample-code/javascript-webdriverio/package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"description": "Sample tests using webdriverio",
55
"main": "index.js",
66
"scripts": {
7-
"test": "mocha --timeout 6000000 test/basic"
7+
"test": "mocha test/basic",
8+
"clean": "rm -rf node_modules && rm -f package-lock.json && npm install"
89
},
910
"author": "Daniel Graham",
1011
"license": "Apache-2.0",

sample-code/javascript-webdriverio/test/basic/android-create-session.test.js

+11-9
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ const assert = require("chai").assert;
55

66
androidOptions.capabilities.app = app;
77

8-
describe("Create Android session", function() {
8+
describe("Create Android session", function () {
99
let client;
1010

11-
before(async() => {
11+
before(async function () {
1212
client = await webdriverio.remote(androidOptions);
1313
});
1414

15-
it("should create and destroy a session", async function() {
16-
const res = await client.status();
17-
assert.isObject(res.build);
18-
const current_package = await client.getCurrentPackage();
19-
assert.equal(current_package, "io.appium.android.apis");
20-
const delete_session = await client.deleteSession();
21-
assert.isNull(delete_session);
15+
it("should create and destroy a session", async function () {
16+
const res = await client.status();
17+
assert.isObject(res.build);
18+
19+
const current_package = await client.getCurrentPackage();
20+
assert.equal(current_package, "io.appium.android.apis");
21+
22+
const delete_session = await client.deleteSession();
23+
assert.isNull(delete_session);
2224
});
2325
});

sample-code/javascript-webdriverio/test/basic/android-create-web-session.test.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@ const webdriverio = require("webdriverio");
22
const androidOptions = require("../../helpers/caps").androidWebOptions;
33
const assert = require("chai").assert;
44

5-
describe("Create Chrome web session", function() {
5+
describe("Create Chrome web session", function () {
66
let client;
77

8-
before(async function() {
8+
before(async function () {
99
client = await webdriverio.remote(androidOptions);
1010
});
1111

12-
after(async function() {
12+
after(async function () {
1313
return await client.deleteSession();
1414
});
1515

16-
it("should create and destroy Android browser session", async function() {
16+
it("should create and destroy Android browser session", async function () {
1717
// Navigate to google.com
18-
let client = await webdriverio.remote(iosOptions);
18+
const client = await webdriverio.remote(androidOptions);
1919
await client.url("https://www.google.com");
20+
2021
const title = await client.getTitle();
2122
assert.equal(title, "Google");
2223
});

sample-code/javascript-webdriverio/test/basic/ios-basic-interactions.test.js

+14-12
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,31 @@ const assert = require("chai").assert;
55

66
iosOptions.capabilities.app = app;
77

8-
describe("Basic IOS interactions", function() {
8+
describe("Basic IOS interactions", function () {
99
let client;
1010

11-
beforeEach(async function() {
11+
beforeEach(async function () {
1212
client = await webdriverio.remote(iosOptions);
1313
});
1414

15-
afterEach(async function() {
16-
await client.deleteSession();
15+
afterEach(async function () {
16+
await client.deleteSession();
1717
});
1818

19-
it("should send keys to inputs", async function() {
20-
const elementId = await client.findElement("accessibility id","TextField1");
19+
it("should send keys to inputs", async function () {
20+
const elementId = await client.findElement("accessibility id", "TextField1");
2121
client.elementSendKeys(elementId.ELEMENT, "Hello World!");
22-
const elementValue = await client.findElement("accessibility id","TextField1");
23-
await client.getElementAttribute(elementValue.ELEMENT,"value").then((attr) => {
24-
assert.equal(attr,"Hello World!");
22+
23+
const elementValue = await client.findElement("accessibility id", "TextField1");
24+
await client.getElementAttribute(elementValue.ELEMENT, "value").then((attr) => {
25+
assert.equal(attr, "Hello World!");
2526
});
2627
});
2728

28-
it("should click a button that opens an alert", async function() {
29-
const element = await client.findElement("accessibility id","show alert");
29+
it("should click a button that opens an alert", async function () {
30+
const element = await client.findElement("accessibility id", "show alert");
3031
await client.elementClick(element.ELEMENT);
31-
assert.equal(await client.getAlertText(),"Cool title\nthis alert is so cool.");
32+
33+
assert.equal(await client.getAlertText(), "Cool title\nthis alert is so cool.");
3234
});
3335
});

0 commit comments

Comments
 (0)