Skip to content

Commit

Permalink
fix: Add missing await (#396)
Browse files Browse the repository at this point in the history
  • Loading branch information
mykola-mokhnach authored Jul 31, 2024
1 parent 64d4b24 commit b213787
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 34 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ jobs:
strategy:
matrix:
include:
- os: macos-14
xcode: '15.1'
- os: macos-13
xcode: '15.2'
ios: '17.2'
device: iPhone 15
- os: macos-13
Expand Down Expand Up @@ -37,7 +37,7 @@ jobs:
udid=$(xcrun simctl list devices available -j | \
node -p "Object.entries(JSON.parse(fs.readFileSync(0)).devices).filter((x) => x[0].includes('$PLATFORM_VERSION'.replace('.', '-'))).reduce((acc, x) => [...acc, ...x[1]], []).find(({name}) => name === '$DEVICE_NAME').udid")
xcrun simctl bootstatus $udid -b
xcrun simctl openurl $udid "https://google.com"
xcrun simctl openurl $udid "https://google.com" &
- run: npm install
- run: |
export PATH="${PATH}:$(python -c 'import site; print(site.USER_BASE)')/bin"
Expand Down
9 changes: 7 additions & 2 deletions lib/mixins/connect.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {
getPossibleDebuggerAppKeys,
} from '../utils';
import events from './events';
import { timing } from '@appium/support';
import { timing, util } from '@appium/support';
import { retryInterval, waitForCondition } from 'asyncbox';
import _ from 'lodash';

Expand Down Expand Up @@ -56,14 +56,19 @@ export async function connect (timeout = APP_CONNECT_TIMEOUT_MS) {

// get the connection information about the app
try {
this.setConnectionKey();
await this.setConnectionKey();
if (timeout) {
const timer = new timing.Timer().start();
this.log.debug(`Waiting up to ${timeout}ms for applications to be reported`);
try {
await waitForCondition(() => !_.isEmpty(this.appDict), {
waitMs: timeout,
intervalMs: APP_CONNECT_INTERVAL_MS,
});
this.log.debug(
`Retrieved ${util.pluralize('application', _.size(this.appDict), true)} ` +
`within ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`
);
} catch (err) {
this.log.debug(`Timed out waiting for applications to be reported`);
}
Expand Down
38 changes: 9 additions & 29 deletions test/functional/safari-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,10 @@ describe('Safari remote debugger', function () {
this.retries(2);

let chai;
/** @type {import('appium-ios-simulator').Simulator} */
let sim;
let simCreated = false;
/** @type {string} */
let address;
before(async function () {
chai = await import('chai');
Expand Down Expand Up @@ -75,6 +77,7 @@ describe('Safari remote debugger', function () {
stopHttpServer();
});

/** @type {import('../../lib/remote-debugger').RemoteDebugger} */
let rd;
beforeEach(async function () {
rd = createRemoteDebugger({
Expand All @@ -90,34 +93,24 @@ describe('Safari remote debugger', function () {
}, false);

await sim.openUrl(address);

await rd.connect(process.env.CI ? 180000 : 5000);
if (_.isEmpty(rd.appDict)) {
throw new Error('The remote debugger did not return any connected applications');
}
});
afterEach(async function () {
if (rd) {
await rd.disconnect();
}
await rd?.disconnect();
rd = null;
});

async function connect (rd) {
await rd.connect();
return await retryInterval(30, 1000, async function () {
if (!_.isEmpty(rd.appDict)) {
return rd.appDict;
}
await rd.setConnectionKey();
throw new Error('No apps connected');
});
}

it('should be able to connect and get app', async function () {
await connect(rd);
const pageArray = await rd.selectApp(address);
_.filter(pageArray, (page) => page.title === PAGE_TITLE)
.should.have.length.at.least(1);
});

it('should be able to execute an atom', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -128,7 +121,6 @@ describe('Safari remote debugger', function () {
});

it('should be able to find an element', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -139,7 +131,6 @@ describe('Safari remote debugger', function () {
});

it('should be able to send text to an element and get attribute values', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -159,7 +150,6 @@ describe('Safari remote debugger', function () {
describe('executeAtomAsync', function () {
const timeout = 1000;
it('should be able to execute an atom asynchronously', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -170,7 +160,6 @@ describe('Safari remote debugger', function () {
});

it('should bubble up JS errors', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -181,7 +170,6 @@ describe('Safari remote debugger', function () {
});

it('should timeout when callback is not invoked', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -192,7 +180,6 @@ describe('Safari remote debugger', function () {
});

it('should be able to execute asynchronously in frame', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -209,7 +196,6 @@ describe('Safari remote debugger', function () {
});

it('capture full viewport', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -219,7 +205,6 @@ describe('Safari remote debugger', function () {
});

it('capture rect on a viewport', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -229,7 +214,6 @@ describe('Safari remote debugger', function () {
});

it('capture full page', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -239,7 +223,6 @@ describe('Safari remote debugger', function () {
});

it('capture rect on a page', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -250,7 +233,6 @@ describe('Safari remote debugger', function () {

it(`should be able to call 'selectApp' after already connecting to app`, async function () {
// this mimics the situation of getting all contexts multiple times
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand All @@ -263,7 +245,6 @@ describe('Safari remote debugger', function () {
});

it('should be able to get console logs from a remote page', async function () {
await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand Down Expand Up @@ -298,7 +279,6 @@ describe('Safari remote debugger', function () {
}).apply(null, arguments)`;
}

await connect(rd);
const page = _.find(await rd.selectApp(address), (page) => page.title === PAGE_TITLE);
const [appIdKey, pageIdKey] = page.id.split('.').map((id) => parseInt(id, 10));
await rd.selectPage(appIdKey, pageIdKey);
Expand Down

0 comments on commit b213787

Please sign in to comment.