From e4e08938531224a440aecbddba8bedc3f5aef8e4 Mon Sep 17 00:00:00 2001 From: "Isaac A. Murchie" Date: Fri, 27 Mar 2020 08:46:28 -0400 Subject: [PATCH] fix: properly handle promise during wait for atom (#1187) * fix: properly handle promise during wait for atom * fix: cancel atom promise when alert is found * try: fix some and try ard * fix: back to published ard * remove some unnecessary cap --- .travis.yml | 1 + lib/commands/web.js | 20 ++++++++++++++----- lib/driver.js | 2 +- package.json | 2 +- .../web/safari-execute-e2e-specs.js | 3 --- .../web/safari-nativewebtap-e2e-specs.js | 6 ------ test/functional/web/safari-ssl-e2e-specs.js | 5 ----- 7 files changed, 18 insertions(+), 21 deletions(-) diff --git a/.travis.yml b/.travis.yml index 543ba12ff..3221c3d21 100644 --- a/.travis.yml +++ b/.travis.yml @@ -12,6 +12,7 @@ env: - _FORCE_LOGS=1 - RECURSIVE=--recursive - MAX_PARALLEL=0 + - _LOG_TIMESTAMP=1 - DEBUG=mocha-parallel-tests - secure: ls4nb5gcu0USHauJOkB9R5p86PMPJd/wCIQWjj/bhAfLNpSNNthtss2Ss9M7BjJg8lth8c85MrGfkAZOGgXknNtlQ2HHwKK4fbEiLAKLDS9diac6/OpAsxxE1/OvletYhkKLQSqb8d5Ju3S/xY6SmNDIzHUpeTYV2/5Ve+7Fh9zc1RztxsPwV1vxPtL6w0IAzNS9PQOmDXQ6x9KuZModtR7ohVKD47A91MzBlu3kk1CSaeQ4I8l7eXi4R9J6F81jkr51Vzoam4B6+4HTepSdfo02irBQWzaJ3VtRCbazFRBc/wfe4YgOPQTD9k69FiP19sa28lP9eSn6h5OCSXA9M803kju33Ml6OItRWDG0gUG1dzTroVXELEIcfnw1iTsFqKWoJLaEzEiXV8n2RsXLaLC5SHPgKwGEigGMfWDxM9leIC8hgervjQvApmx7btzq9S50tMcrzba5qwXDDrjJi1wKSjd4pQajhSj9VgOH9D5ihZBdn++VLwEvfAd4yQhjdsr9+COV1HrgK7Ro1HAHWgGnPtwBKiQdVU20QdQzNrhRdF2MLrJ4BfWpNm92JwlPxP/ojuA2l8mr9nDqlfBgXlnG32j59988gi85vaMfXssrUXtdJqsKJckI01c/mgaRh9pvG3UPX8K39quKBI5ftS8aCCa8tbF6bLq/ZuI2TRU= jobs: diff --git a/lib/commands/web.js b/lib/commands/web.js index 64454a178..d4e71d6a5 100644 --- a/lib/commands/web.js +++ b/lib/commands/web.js @@ -23,7 +23,7 @@ const NOTCHED_DEVICE_SIZES = [ {w: 1242, h: 2688}, // 11 Pro Max, Xs Max ]; -const ATOM_WAIT_TIMEOUT = 5 * 60000; +const ATOM_WAIT_TIMEOUT = 2 * 60000; const ATOM_WAIT_INITIAL_TIMEOUT = 1000; const ATOM_WAIT_ALERT_WAIT = 400; @@ -271,15 +271,24 @@ extensions.checkForAlert = async function checkForAlert () { extensions.waitForAtom = async function waitForAtom (promise) { const timer = new timing.Timer().start(); + // make sure the promise is cancellable, so when an alert is found it can + // be removed + B.config({ + cancellation: true, + }); + // need to check for alert while the atom is being executed. // so notify ourselves when it happens let done = false; let error = null; - B.resolve(promise) // eslint-disable-line promise/catch-or-return + promise = B.resolve(promise) // eslint-disable-line promise/catch-or-return .timeout(ATOM_WAIT_TIMEOUT) .catch(function (err) { // eslint-disable-line promise/prefer-await-to-callbacks log.debug(`Error received while executing atom: ${err.message}`); - // error gets swallowed, so save and check later + if (err instanceof B.TimeoutError) { + err = new Error(`Did not get any response for atom execution after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`); + } + // save and check later, or an Unhandled rejection will be reported error = err; }) .finally(function () { @@ -302,6 +311,7 @@ extensions.waitForAtom = async function waitForAtom (promise) { // check if there is an alert if (await this.checkForAlert()) { // we found an alert, and should just return control + promise.cancel(); return ''; } // check again, and pause if not done @@ -311,8 +321,8 @@ extensions.waitForAtom = async function waitForAtom (promise) { } const res = await promise; - if (error instanceof B.TimeoutError) { - throw new Error(`Did not get any response for atom execution after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`); + if (error) { + throw error; } return this.parseExecuteResponse(res); }; diff --git a/lib/driver.js b/lib/driver.js index 36b1bb6dc..740b4ab2c 100644 --- a/lib/driver.js +++ b/lib/driver.js @@ -260,7 +260,7 @@ class XCUITestDriver extends BaseDriver { } return [sessionId, caps]; } catch (e) { - log.error(e); + log.error(JSON.stringify(e)); await this.deleteSession(); throw e; } diff --git a/package.json b/package.json index 27bd7caf4..652c07bf7 100644 --- a/package.json +++ b/package.json @@ -49,7 +49,7 @@ "appium-ios-device": "^1.4.1", "appium-ios-driver": "^4.6.0", "appium-ios-simulator": "^3.20.0", - "appium-remote-debugger": "^8.6.1", + "appium-remote-debugger": "^8.8.1", "appium-support": "^2.41.0", "appium-webdriveragent": "^2.9.0", "appium-xcode": "^3.8.0", diff --git a/test/functional/web/safari-execute-e2e-specs.js b/test/functional/web/safari-execute-e2e-specs.js index f442166e4..b907a8e8c 100644 --- a/test/functional/web/safari-execute-e2e-specs.js +++ b/test/functional/web/safari-execute-e2e-specs.js @@ -5,7 +5,6 @@ import http from 'http'; import { SAFARI_CAPS } from '../desired'; import { initSession, deleteSession, MOCHA_TIMEOUT } from '../helpers/session'; import { openPage, GUINEA_PIG_PAGE } from './helpers'; -import { killAllSimulators } from '../helpers/simulator'; chai.should(); @@ -22,7 +21,6 @@ describe('safari - execute -', function () { let driver; before(async function () { - await killAllSimulators(); const caps = _.defaults({ safariInitialUrl: GUINEA_PIG_PAGE, showSafariConsoleLog: true, @@ -31,7 +29,6 @@ describe('safari - execute -', function () { }); after(async function () { await deleteSession(); - await killAllSimulators(); }); async function runTests (secure = false) { // eslint-disable-line require-await diff --git a/test/functional/web/safari-nativewebtap-e2e-specs.js b/test/functional/web/safari-nativewebtap-e2e-specs.js index 11614ac0d..4fd519260 100644 --- a/test/functional/web/safari-nativewebtap-e2e-specs.js +++ b/test/functional/web/safari-nativewebtap-e2e-specs.js @@ -7,7 +7,6 @@ import { openPage, spinTitleEquals, spinTitle, GUINEA_PIG_PAGE, GUINEA_PIG_SCROLLABLE_PAGE, GUINEA_PIG_APP_BANNER_PAGE } from './helpers'; -import { killAllSimulators } from '../helpers/simulator'; import { retryInterval } from 'asyncbox'; import B from 'bluebird'; import Simctl from 'node-simctl'; @@ -44,8 +43,6 @@ describe('Safari - coordinate conversion -', function () { let devices = []; before(async function () { - await killAllSimulators(); - if (process.env.REAL_DEVICE) { // skip, by not having any devices in the list } else if (process.env.ALL_DEVICES) { @@ -78,8 +75,6 @@ describe('Safari - coordinate conversion -', function () { let driver; const localCaps = _.defaults({ deviceName, - fullReset: true, - noReset: false, }, caps); let skipped = false; @@ -100,7 +95,6 @@ describe('Safari - coordinate conversion -', function () { }); after(async function () { await deleteSession(); - await killAllSimulators(); }); it('should be able to tap on an element', async function () { diff --git a/test/functional/web/safari-ssl-e2e-specs.js b/test/functional/web/safari-ssl-e2e-specs.js index 2a145675e..0dc269709 100644 --- a/test/functional/web/safari-ssl-e2e-specs.js +++ b/test/functional/web/safari-ssl-e2e-specs.js @@ -2,7 +2,6 @@ import chai from 'chai'; import chaiAsPromised from 'chai-as-promised'; import _ from 'lodash'; import B from 'bluebird'; -import { killAllSimulators } from '../helpers/simulator'; import { MOCHA_TIMEOUT, initSession, deleteSession } from '../helpers/session'; import { doesIncludeCookie, doesNotIncludeCookie, newCookie, oldCookie1 } from './safari-basic-e2e-specs'; @@ -32,10 +31,6 @@ if (!process.env.REAL_DEVICE && !process.env.CLOUD) { let sslServer, driver; before(async function () { - if (!process.env.CLOUD) { - await killAllSimulators(); - } - // Create a random pem certificate const privateKey = await pem.createPrivateKeyAsync(); const keys = await pem.createCertificateAsync({