Skip to content

Commit

Permalink
fix: properly handle promise during wait for atom (appium#1187)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
imurchie authored Mar 27, 2020
1 parent 1d615c3 commit e4e0893
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 21 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
20 changes: 15 additions & 5 deletions lib/commands/web.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 () {
Expand All @@ -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
Expand All @@ -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);
};
Expand Down
2 changes: 1 addition & 1 deletion lib/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 0 additions & 3 deletions test/functional/web/safari-execute-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -22,7 +21,6 @@ describe('safari - execute -', function () {

let driver;
before(async function () {
await killAllSimulators();
const caps = _.defaults({
safariInitialUrl: GUINEA_PIG_PAGE,
showSafariConsoleLog: true,
Expand All @@ -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
Expand Down
6 changes: 0 additions & 6 deletions test/functional/web/safari-nativewebtap-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -78,8 +75,6 @@ describe('Safari - coordinate conversion -', function () {
let driver;
const localCaps = _.defaults({
deviceName,
fullReset: true,
noReset: false,
}, caps);
let skipped = false;

Expand All @@ -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 () {
Expand Down
5 changes: 0 additions & 5 deletions test/functional/web/safari-ssl-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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({
Expand Down

0 comments on commit e4e0893

Please sign in to comment.