From 4ccc8665f8b9edf3f5818dd986e10a6ba58ab1e3 Mon Sep 17 00:00:00 2001 From: "Isaac A. Murchie" Date: Tue, 23 Apr 2019 12:58:42 -0400 Subject: [PATCH] Begin running sample code in CI (#12519) * Make stage in Travis to run wd sample code * Clean up wd sample code for Sauce runs * Restrict to master/non-PR builds --- .travis.yml | 16 +++- .../basic/android-basic-interactions.test.js | 37 +++++++-- .../test/basic/android-create-session.test.js | 54 +++++++++---- .../basic/android-create-web-session.test.js | 63 +++++++++++----- .../test/basic/android-selectors.test.js | 40 ++++++++-- .../test/basic/ios-basic-interactions.test.js | 40 ++++++++-- .../test/basic/ios-create-session.test.js | 65 +++++++++++----- .../test/basic/ios-create-web-session.test.js | 68 +++++++++++------ .../test/basic/ios-selectors.test.js | 40 ++++++++-- .../javascript-wd/test/helpers/apps.js | 14 ---- .../javascript-wd/test/helpers/caps.js | 32 -------- .../javascript-wd/test/helpers/config.js | 75 +++++++++++++++++++ 12 files changed, 395 insertions(+), 149 deletions(-) delete mode 100644 sample-code/javascript-wd/test/helpers/apps.js delete mode 100644 sample-code/javascript-wd/test/helpers/caps.js create mode 100644 sample-code/javascript-wd/test/helpers/config.js diff --git a/.travis.yml b/.travis.yml index a804e4af3..4ed117066 100644 --- a/.travis.yml +++ b/.travis.yml @@ -104,7 +104,8 @@ jobs: if: tag os: osx env: - - HUB_VERBOSE=true GITHUB_TOKEN=$TRIAGER_BOT_TOKEN + - HUB_VERBOSE=true + - GITHUB_TOKEN=$TRIAGER_BOT_TOKEN before_script: - brew install hub - pip install mkdocs==0.16.3 @@ -121,3 +122,16 @@ jobs: - git commit -a -n -m 'Updated docs for latest Appium version' - git push origin docs-$TRAVIS_TAG - hub pull-request -b "appium:gh-pages" -h "appium:docs-$TRAVIS_TAG" -m "Update documentation for latest version" | exit 0 # The PR command works but always returns non-negative + + - stage: Sample Code + name: JavaScript (wd) + # only want to run this on the main master branch + if: branch = master AND type != pull_request + node_js: "8" + env: + - SAUCE_LABS=1 + install: + - cd sample-code/javascript-wd + - npm install + script: + - npm run test diff --git a/sample-code/javascript-wd/test/basic/android-basic-interactions.test.js b/sample-code/javascript-wd/test/basic/android-basic-interactions.test.js index 8309b6733..cc715de0e 100644 --- a/sample-code/javascript-wd/test/basic/android-basic-interactions.test.js +++ b/sample-code/javascript-wd/test/basic/android-basic-interactions.test.js @@ -1,6 +1,9 @@ import wd from 'wd'; import chai from 'chai'; -import { androidCaps, serverConfig } from '../helpers/caps'; +import { + androidCaps, serverConfig, androidApiDemos, + SAUCE_TESTING, SAUCE_USERNAME, SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; @@ -10,21 +13,43 @@ const ALERT_DIALOG_ACTIVITY = '.app.AlertDialogSamples'; describe('Basic Android interactions', function () { let driver; + let allPassed = true; before(async function () { // Connect to Appium server - driver = await wd.promiseChainRemote(serverConfig); + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); - // Start the session - await driver.init({ + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'Android Basic Interactions Test', + } + : {}; + + // merge all the capabilities + const caps = { ...androidCaps, - app: require('../helpers/apps').androidApiDemos, + ...sauceCaps, + app: androidApiDemos, appActivity: SEARCH_ACTIVITY, // Android-specific capability. Can open a specific activity. - }); + }; + + // Start the session, merging all the caps + await driver.init(caps); + }); + + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); after(async function () { await driver.quit(); + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } }); it('should send keys to search box and then check the value', async function () { diff --git a/sample-code/javascript-wd/test/basic/android-create-session.test.js b/sample-code/javascript-wd/test/basic/android-create-session.test.js index 19be9d0eb..e5cb6b9ea 100644 --- a/sample-code/javascript-wd/test/basic/android-create-session.test.js +++ b/sample-code/javascript-wd/test/basic/android-create-session.test.js @@ -1,26 +1,52 @@ import wd from 'wd'; import chai from 'chai'; -import { androidCaps, serverConfig } from '../helpers/caps'; +import { + androidCaps, serverConfig, androidApiDemos, SAUCE_TESTING, + SAUCE_USERNAME, SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Create Android session', function () { + let driver; + let allPassed = true; + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); + }); + after(async function () { + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } + }); it('should create and destroy Android sessions', async function () { - // Connect to Appium server - const driver = await wd.promiseChainRemote(serverConfig); + try { + // Connect to Appium server + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); - // Start the session - await driver.init({ - ...androidCaps, - app: require('../helpers/apps').androidApiDemos - }); + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'Android Create Session Test', + } + : {}; - // Check that we're running the ApiDemos app by checking package and activity - const activity = await driver.getCurrentActivity(); - const pkg = await driver.getCurrentPackage(); - assert.equal(`${pkg}${activity}`, 'io.appium.android.apis.ApiDemos'); + // Start the session + await driver.init({ + ...androidCaps, + ...sauceCaps, + app: androidApiDemos, + }); - // Quit the session - await driver.quit(); + // Check that we're running the ApiDemos app by checking package and activity + const activity = await driver.getCurrentActivity(); + const pkg = await driver.getCurrentPackage(); + assert.equal(`${pkg}${activity}`, 'io.appium.android.apis.ApiDemos'); + } finally { + // Quit the session, no matter what happens + await driver.quit(); + } }); }); diff --git a/sample-code/javascript-wd/test/basic/android-create-web-session.test.js b/sample-code/javascript-wd/test/basic/android-create-web-session.test.js index c67f7abf2..53b5b74cf 100644 --- a/sample-code/javascript-wd/test/basic/android-create-web-session.test.js +++ b/sample-code/javascript-wd/test/basic/android-create-web-session.test.js @@ -1,31 +1,58 @@ import wd from 'wd'; import chai from 'chai'; -import { androidCaps, serverConfig } from '../helpers/caps'; +import { + androidCaps, serverConfig, SAUCE_TESTING, SAUCE_USERNAME, SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Create Chrome web session', function () { let driver; - before(async function () { - // Connect to Appium server - driver = await wd.promiseChainRemote(serverConfig); - - // Start the session - await driver.init({ - ...androidCaps, - browserName: 'Chrome' - }); + let allPassed = true; + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); after(async function () { - // Quit the session - await driver.quit(); + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } }); - it('should create and destroy Android browser session', async function () { - // Navigate to google.com - await driver.get('https://www.google.com'); - // Test that it was successful by checking the document title - const pageTitle = await driver.title(); - assert.equal(pageTitle, 'Google'); + it('should create and destroy Android browser session', async function () { + try { + // Connect to Appium server + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); + + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'Android Create Web Session Test', + } + : {}; + + // Start the session + await driver.init({ + ...androidCaps, + ...sauceCaps, + browserName: 'Chrome', + }); + + // Navigate to google.com + await driver.get('https://www.google.com'); + + // Test that it was successful by checking the document title + const pageTitle = await driver.title(); + assert.equal(pageTitle, 'Google'); + } finally { + // Quit the session, no matter what happens + await driver.quit(); + } + }); + + it('should create and destroy Android browser session', async function () { + }); }); diff --git a/sample-code/javascript-wd/test/basic/android-selectors.test.js b/sample-code/javascript-wd/test/basic/android-selectors.test.js index 038d9c5c2..1cae872cd 100644 --- a/sample-code/javascript-wd/test/basic/android-selectors.test.js +++ b/sample-code/javascript-wd/test/basic/android-selectors.test.js @@ -1,26 +1,50 @@ import wd from 'wd'; import chai from 'chai'; -import { androidCaps, serverConfig } from '../helpers/caps'; +import { + androidCaps, serverConfig, androidApiDemos, SAUCE_TESTING, SAUCE_USERNAME, + SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Basic Android selectors', function () { - let driver; + let allPassed = true; before(async function () { // Connect to Appium server - driver = await wd.promiseChainRemote(serverConfig); + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); - // Start the session - await driver.init({ + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'Android Selectors Tests', + } + : {}; + + // merge all the capabilities + const caps = { ...androidCaps, - app: require('../helpers/apps').androidApiDemos - }); + ...sauceCaps, + app: androidApiDemos, + }; + + // Start the session, merging all the caps + await driver.init(caps); + }); + + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); after(async function () { await driver.quit(); + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } }); it('should find elements by Accessibility ID', async function () { @@ -46,4 +70,4 @@ describe('Basic Android selectors', function () { const linearLayoutElements = await driver.elementsByXPath(`//*[@class='android.widget.FrameLayout']`); assert.isAbove(linearLayoutElements.length, 1); }); -}); \ No newline at end of file +}); diff --git a/sample-code/javascript-wd/test/basic/ios-basic-interactions.test.js b/sample-code/javascript-wd/test/basic/ios-basic-interactions.test.js index 09e36c50d..83915feef 100644 --- a/sample-code/javascript-wd/test/basic/ios-basic-interactions.test.js +++ b/sample-code/javascript-wd/test/basic/ios-basic-interactions.test.js @@ -1,26 +1,50 @@ import wd from 'wd'; import chai from 'chai'; -import { iosCaps, serverConfig } from '../helpers/caps'; +import { + iosCaps, serverConfig, iosTestApp, SAUCE_TESTING, SAUCE_USERNAME, + SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Basic IOS interactions', function () { - let driver; + let allPassed = true; before(async function () { // Connect to Appium server - driver = await wd.promiseChainRemote(serverConfig); + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); - // Start the session - await driver.init({ + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'iOS Basic Interactions Test', + } + : {}; + + // merge all the capabilities + const caps = { ...iosCaps, - app: require('../helpers/apps').iosTestApp - }); + ...sauceCaps, + app: iosTestApp, + }; + + // Start the session, merging all the caps + await driver.init(caps); + }); + + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); after(async function () { await driver.quit(); + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } }); it('should send keys to inputs', async function () { @@ -54,4 +78,4 @@ describe('Basic IOS interactions', function () { const alertTitle = await alertTitleElement.text(); assert.equal(alertTitle, `Cool title`); }); -}); \ No newline at end of file +}); diff --git a/sample-code/javascript-wd/test/basic/ios-create-session.test.js b/sample-code/javascript-wd/test/basic/ios-create-session.test.js index c32c523ed..268999793 100644 --- a/sample-code/javascript-wd/test/basic/ios-create-session.test.js +++ b/sample-code/javascript-wd/test/basic/ios-create-session.test.js @@ -1,26 +1,53 @@ import wd from 'wd'; import chai from 'chai'; -import { iosCaps, serverConfig } from '../helpers/caps'; +import { + iosCaps, serverConfig, iosTestApp, SAUCE_TESTING, SAUCE_USERNAME, + SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Create session', function () { - it('should create and destroy IOS sessions', async function () { - // Connect to Appium server - const driver = await wd.promiseChainRemote(serverConfig); - - // Start the session - await driver.init({ - ...iosCaps, - app: require('../helpers/apps').iosTestApp - }); - - // Check that the XCUIElementTypeApplication was what we expect it to be - const applicationElement = await driver.elementByClassName('XCUIElementTypeApplication'); - const applicationName = await applicationElement.getAttribute('name'); - assert.equal(applicationName, 'TestApp'); - - // Quit the session - await driver.quit(); + let driver; + let allPassed = true; + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); -}); \ No newline at end of file + after(async function () { + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } + }); + + it('should create and destroy iOS sessions', async function () { + try { + // Connect to Appium server + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); + + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'iOS Create Session Test', + } + : {}; + + // Start the session + await driver.init({ + ...iosCaps, + ...sauceCaps, + app: iosTestApp, + }); + + // Check that the XCUIElementTypeApplication was what we expect it to be + const applicationElement = await driver.elementByClassName('XCUIElementTypeApplication'); + const applicationName = await applicationElement.getAttribute('name'); + assert.equal(applicationName, 'TestApp'); + } finally { + // Quit the session, no matter what happens + await driver.quit(); + } + }); +}); diff --git a/sample-code/javascript-wd/test/basic/ios-create-web-session.test.js b/sample-code/javascript-wd/test/basic/ios-create-web-session.test.js index 0c0785d85..6aabc7fb9 100644 --- a/sample-code/javascript-wd/test/basic/ios-create-web-session.test.js +++ b/sample-code/javascript-wd/test/basic/ios-create-web-session.test.js @@ -1,28 +1,54 @@ import wd from 'wd'; import chai from 'chai'; -import { iosCaps, serverConfig } from '../helpers/caps'; +import { + iosCaps, serverConfig, SAUCE_TESTING, SAUCE_USERNAME, SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Create Safari session', function () { - it('should create and destroy IOS Safari session', async function () { - // Connect to Appium server - const driver = await wd.promiseChainRemote(serverConfig); - - // Start the session - await driver.init({ - ...iosCaps, - browserName: 'Safari' - }); - - // Navigate to google.com - await driver.get('https://www.google.com'); - - // Test that it was successful by checking the document title - const pageTitle = await driver.title(); - assert.equal(pageTitle, 'Google'); - - // Quit the session - await driver.quit(); + let driver; + let allPassed = true; + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); -}); \ No newline at end of file + after(async function () { + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } + }); + + it('should create and destroy iOS Safari sessions', async function () { + try { + // Connect to Appium server + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); + + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'iOS Create Web Session Test', + } + : {}; + + // Start the session + await driver.init({ + ...iosCaps, + ...sauceCaps, + browserName: 'Safari', + }); + + // Navigate to google.com + await driver.get('https://www.google.com'); + + // Test that it was successful by checking the document title + const pageTitle = await driver.title(); + assert.equal(pageTitle, 'Google'); + } finally { + // Quit the session, no matter what happens + await driver.quit(); + } + }); +}); diff --git a/sample-code/javascript-wd/test/basic/ios-selectors.test.js b/sample-code/javascript-wd/test/basic/ios-selectors.test.js index bdefcfed0..6763ff406 100644 --- a/sample-code/javascript-wd/test/basic/ios-selectors.test.js +++ b/sample-code/javascript-wd/test/basic/ios-selectors.test.js @@ -1,26 +1,50 @@ import wd from 'wd'; import chai from 'chai'; -import { iosCaps, serverConfig } from '../helpers/caps'; +import { + iosCaps, serverConfig, iosTestApp, SAUCE_TESTING, SAUCE_USERNAME, + SAUCE_ACCESS_KEY +} from '../helpers/config'; const {assert} = chai; describe('Basic IOS selectors', function () { - let driver; + let allPassed = true; before(async function () { // Connect to Appium server - driver = await wd.promiseChainRemote(serverConfig); + driver = SAUCE_TESTING + ? await wd.promiseChainRemote(serverConfig) + : await wd.promiseChainRemote(serverConfig, SAUCE_USERNAME, SAUCE_ACCESS_KEY); - // Start the session - await driver.init({ + // add the name to the desired capabilities + const sauceCaps = SAUCE_TESTING + ? { + name: 'iOS Selectors Test', + } + : {}; + + // merge all the capabilities + const caps = { ...iosCaps, - app: require('../helpers/apps').iosTestApp - }); + ...sauceCaps, + app: iosTestApp, + }; + + // Start the session, merging all the caps + await driver.init(caps); + }); + + afterEach(function () { + // keep track of whether all the tests have passed, since mocha does not do this + allPassed = allPassed && (this.currentTest.state === 'passed'); }); after(async function () { await driver.quit(); + if (SAUCE_TESTING && driver) { + await driver.sauceJobStatus(allPassed); + } }); it('should find elements by Accessibility ID', async function () { @@ -45,7 +69,7 @@ describe('Basic IOS selectors', function () { it('should find elements by class chain', async function () { // This is also an IOS-specific selector strategy. Similar to XPath. This is recommended over XPath. const windowElement = await driver.elements('-ios class chain', 'XCUIElementTypeWindow[1]/*'); - assert.equal(windowElement.length, 1); + assert.equal(windowElement.length, 3); }); it('should find elements by XPath', async function () { diff --git a/sample-code/javascript-wd/test/helpers/apps.js b/sample-code/javascript-wd/test/helpers/apps.js deleted file mode 100644 index 1485e137d..000000000 --- a/sample-code/javascript-wd/test/helpers/apps.js +++ /dev/null @@ -1,14 +0,0 @@ -import path from 'path'; - - -const githubAssetBase = 'http://appium.github.io/appium/assets'; -const localAssetBase = path.resolve(__dirname, '..', '..', '..', 'apps'); - -if (process.env.SAUCE_LABS) { - // TODO: Change thes URL's to updated locations - exports.iosTestApp = `${githubAssetBase}/TestApp7.1.app.zip`; - exports.androidApiDemos = `${githubAssetBase}/ApiDemos-debug.apk`; -} else { - exports.iosTestApp = path.resolve(localAssetBase, 'TestApp.app.zip'); - exports.androidApiDemos = path.resolve(localAssetBase, 'ApiDemos-debug.apk'); -} diff --git a/sample-code/javascript-wd/test/helpers/caps.js b/sample-code/javascript-wd/test/helpers/caps.js deleted file mode 100644 index a7b53d454..000000000 --- a/sample-code/javascript-wd/test/helpers/caps.js +++ /dev/null @@ -1,32 +0,0 @@ -const iosCaps = { - platformName: 'iOS', - automationName: 'XCUITest', - deviceName: process.env.IOS_DEVICE_NAME || 'iPhone 6s', - platformVersion: process.env.IOS_PLATFORM_VERSION || '12.1', - app: undefined, // Will be added in tests -}; - -// Leave the Android platformVersion blank and set deviceName to a random string -// (Android deviceName is ignored by Appium but is still required) -// If we're using SauceLabs, set the Android deviceName and platformVersion to -// the latest supported SauceLabs device and version -const DEFAULT_ANDROID_DEVICE_NAME = process.env.SAUCE_LABS ? 'Android GoogleAPI Emulator' : 'My Android Device'; -const DEFAULT_ANDROID_PLATFORM_VERSION = process.env.SAUCE_LABS ? '7.1' : null; - -const androidCaps = { - platformName: 'Android', - automationName: 'UiAutomator2', - deviceName: process.env.ANDROID_DEVICE_NAME || DEFAULT_ANDROID_DEVICE_NAME, - platformVersion: process.env.ANDROID_PLATFORM_VERSION || DEFAULT_ANDROID_PLATFORM_VERSION, - app: undefined, // Will be added in tests -}; - -const serverConfig = process.env.SAUCE_LABS ? { - host: 'ondemand.saucelabs.com', - port: 80 -} : { - host: process.env.APPIUM_HOST || 'localhost', - port: process.env.APPIUM_PORT || 4723 -}; - -export { iosCaps, androidCaps, serverConfig }; diff --git a/sample-code/javascript-wd/test/helpers/config.js b/sample-code/javascript-wd/test/helpers/config.js new file mode 100644 index 000000000..27868c463 --- /dev/null +++ b/sample-code/javascript-wd/test/helpers/config.js @@ -0,0 +1,75 @@ +import path from 'path'; + + +const SAUCE_TESTING = process.env.SAUCE_LABS; +const SAUCE_USERNAME = process.env.SAUCE_USERNAME; +const SAUCE_ACCESS_KEY = process.env.SAUCE_ACCESS_KEY; + + +const sauceCaps = SAUCE_TESTING + ? { + name: undefined, // will be added in tests + build: `JavaScript (wd) Sample Code ${new Date()}`, + tags: ['e2e', 'appium', 'sample-code'], + } + : {}; + +const iosCaps = { + platformName: 'iOS', + automationName: 'XCUITest', + deviceName: process.env.IOS_DEVICE_NAME || 'iPhone 6', + platformVersion: process.env.IOS_PLATFORM_VERSION || '12.0', + app: undefined, // Will be added in tests + // appiumVersion: '1.12.1', + showIOSLog: false, + ... sauceCaps, +}; + +// Leave the Android platformVersion blank and set deviceName to a random string +// (Android deviceName is ignored by Appium but is still required) +// If we're using SauceLabs, set the Android deviceName and platformVersion to +// the latest supported SauceLabs device and version +const DEFAULT_ANDROID_DEVICE_NAME = process.env.SAUCE_LABS ? 'Android GoogleAPI Emulator' : 'My Android Device'; +const DEFAULT_ANDROID_PLATFORM_VERSION = process.env.SAUCE_LABS ? '7.1' : null; + +const androidCaps = { + platformName: 'Android', + automationName: 'UiAutomator2', + deviceName: process.env.ANDROID_DEVICE_NAME || DEFAULT_ANDROID_DEVICE_NAME, + platformVersion: process.env.ANDROID_PLATFORM_VERSION || DEFAULT_ANDROID_PLATFORM_VERSION, + app: undefined, // Will be added in tests + ...sauceCaps, +}; + +// figure out where the Appium server should be pointing to +const serverConfig = SAUCE_TESTING + ? { + host: 'ondemand.saucelabs.com', + port: 80 + } + : { + host: process.env.APPIUM_HOST || 'localhost', + port: process.env.APPIUM_PORT || 4723 + }; + + +// figure out the location of the apps under test +const GITHUB_ASSET_BASE = 'http://appium.github.io/appium/assets'; +const LOCAL_ASSET_BASE = path.resolve(__dirname, '..', '..', '..', 'apps'); + +let iosTestApp, androidApiDemos; +if (SAUCE_TESTING) { + // TODO: Change thes URLs to updated locations + iosTestApp = `${GITHUB_ASSET_BASE}/TestApp9.4.app.zip`; + androidApiDemos = `${GITHUB_ASSET_BASE}/ApiDemos-debug.apk`; +} else { + iosTestApp = path.resolve(LOCAL_ASSET_BASE, 'TestApp.app.zip'); + androidApiDemos = path.resolve(LOCAL_ASSET_BASE, 'ApiDemos-debug.apk'); +} + +export { + iosTestApp, androidApiDemos, + iosCaps, androidCaps, sauceCaps, + serverConfig, + SAUCE_TESTING, SAUCE_USERNAME, SAUCE_ACCESS_KEY, +};