Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: fix and enable some commands e2e specs #576

Merged
merged 14 commits into from
Jan 27, 2023
7 changes: 6 additions & 1 deletion .github/workflows/functional-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on: [pull_request]
jobs:
test:
strategy:
fail-fast: false
matrix:
include:
- chromedriverVersion: "74.0.3729.6"
Expand Down Expand Up @@ -54,6 +55,8 @@ jobs:
--port=$APPIUM_TEST_SERVER_PORT \
--address=$APPIUM_TEST_SERVER_HOST \
--relaxed-security \
--log-no-colors \
--log-timestamp \
2>&1 > "$cwd/appium.log" &
popd
name: Start Appium server
Expand All @@ -62,7 +65,9 @@ jobs:
- uses: reactivecircus/android-emulator-runner@v2
name: e2e_api${{ matrix.apiLevel }}
with:
script: npm run e2e-test:driver
script: |
npm run e2e-test:driver
npm run e2e-test:commands
Copy link
Contributor Author

@rerorero rerorero Jan 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to have it run in a different step but resulted in a connection error to Appium server 🤔
Please let me know if you have better approaches to run multiple tests.

avd-name: ${{ env.ANDROID_AVD }}
sdcard-path-or-size: 1500M
api-level: ${{ matrix.apiLevel }}
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@
"precommit-lint": "lint-staged",
"prepare": "npm run build",
"test": "mocha --exit --timeout 1m \"./test/unit/**/*-specs.js\"",
"e2e-test:driver": "mocha --exit --timeout 10m \"./test/functional/driver-e2e-specs.js\""
"e2e-test:driver": "mocha --exit --timeout 10m \"./test/functional/driver-e2e-specs.js\"",
"e2e-test:commands": "mocha --exit --timeout 10m \"./test/functional/commands\""
},
"pre-commit": [
"precommit-msg",
Expand Down
4 changes: 3 additions & 1 deletion test/functional/commands/file-movement-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ describe('file movement', function () {
zipStream
.pipe(unzipper.Parse())
.on('entry', function (entry) {
entryCount++;
if (entry.type === 'File') {
entryCount++;
}
entry.autodrain();
})
.on('close', function () {
Expand Down
20 changes: 10 additions & 10 deletions test/functional/commands/geo-location-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,35 +24,31 @@ describe('geo-location -', function () {

it('should set geo location', async function () {
// If we hit the permission screen, click the 'Continue Button' (sdk >= 28)
const continueButtons = await driver.elementsById('com.android.permissioncontroller:id/continue_button');
const continueButtons = await driver.$$('id:com.android.permissioncontroller:id/continue_button');
if (continueButtons.length > 0) {
await continueButtons[0].click();
}

// Get rid of the modal window saying that the app was built for an old version
await B.delay(1000);
const okButtons = await driver.elementsById('android:id/button1');
const okButtons = await driver.$$('id:android:id/button1');
if (okButtons.length > 0) {
await okButtons[0].click();
}

// Get the text in the app that tells us the latitude and logitude
const getText = async function () {
return await retryInterval(10, 1000, async function () {
const textViews = await driver.elementsByClassName('android.widget.TextView');
const textViews = await driver.$$('android.widget.TextView');
textViews.length.should.be.at.least(2);
return await textViews[1].text();
return await textViews[1].getText();
});
};

const latitude = getRandomInt(-90, 90);
const longitude = getRandomInt(-180, 180);

let text = await getText();
text.should.not.include(`Latitude: ${latitude}`);
text.should.not.include(`Longitude: ${longitude}`);

await driver.setGeoLocation(latitude, longitude);
await driver.setGeoLocation({latitude, longitude});

// wait for the text to change
await retryInterval(10, 1000, async () => {
Expand All @@ -62,9 +58,13 @@ describe('geo-location -', function () {
});

await retryInterval(30, 1000, async function () {
text = await getText();
const text = await getText();
text.should.include(`Latitude: ${latitude}`);
text.should.include(`Longitude: ${longitude}`);
});

const loc = await driver.getGeoLocation();
loc.latitude.should.equal(latitude);
loc.longitude.should.equal(longitude);
});
});
32 changes: 12 additions & 20 deletions test/functional/commands/language-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import ADB from 'appium-adb';
import { initSession, deleteSession } from '../helpers/session';
import { APIDEMOS_CAPS } from '../desired';
import { APIDEMOS_CAPS, amendCapabilities } from '../desired';
import { androidHelpers } from 'appium-android-driver';
import { getLocale } from '../helpers/helpers';

Expand All @@ -16,42 +16,34 @@ describe('Localization - locale @skip-ci @skip-real-device', function () {
let adb;

before(async function () {
if (process.env.TESTOBJECT_E2E_TESTS) {
this.skip();
}

// restarting doesn't work on Android 7+
let adb = new ADB();
if (await adb.getApiLevel() > 23) return this.skip(); //eslint-disable-line curly
adb = new ADB();
if (await adb.getApiLevel() <= 23) return this.skip(); //eslint-disable-line curly

initialLocale = await getLocale(adb);
});

let driver;
after(async function () {
if (driver) {
if (await adb.getApiLevel() > 23) {
let [language, country] = initialLocale.split('-');
await androidHelpers.ensureDeviceLocale(driver.adb, language, country);
} else {
await androidHelpers.ensureDeviceLocale(driver.adb, null, initialLocale);
}
let [language, country] = initialLocale.split('-');
await androidHelpers.ensureDeviceLocale(adb, language, country);
await deleteSession();
}
});

it('should start as FR', async function () {
let frCaps = Object.assign({}, APIDEMOS_CAPS, {
language: 'fr',
locale: 'FR',
let frCaps = amendCapabilities(APIDEMOS_CAPS, {
'appium:language': 'fr',
'appium:locale': 'FR',
});
driver = await initSession(frCaps);
const driver = await initSession(frCaps);
await getLocale(driver.adb).should.eventually.equal('fr-FR');
});
it('should start as US', async function () {
let usCaps = Object.assign({}, APIDEMOS_CAPS, {
language: 'en',
locale: 'US',
let usCaps = amendCapabilities(APIDEMOS_CAPS, {
'appium:language': 'en',
'appium:locale': 'US',
});
driver = await initSession(usCaps);
await getLocale(driver.adb).should.eventually.equal('en-US');
Expand Down
24 changes: 12 additions & 12 deletions test/functional/commands/orientation-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import B from 'bluebird';
import { APIDEMOS_CAPS } from '../desired';
import { APIDEMOS_CAPS, amendCapabilities } from '../desired';
import { initSession, deleteSession } from '../helpers/session';


Expand All @@ -17,30 +17,30 @@ describe('apidemo - orientation -', function () {
await deleteSession();
});
it('should have portrait orientation if requested', async function () {
driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {
appActivity: '.view.TextFields',
orientation: 'PORTRAIT',
driver = await initSession(amendCapabilities(APIDEMOS_CAPS, {
'appium:appActivity': '.view.TextFields',
'appium:orientation': 'PORTRAIT',
}));
await driver.getOrientation().should.eventually.eql('PORTRAIT');
});
it('should have landscape orientation if requested', async function () {
driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {
appActivity: '.view.TextFields',
orientation: 'LANDSCAPE',
driver = await initSession(amendCapabilities(APIDEMOS_CAPS, {
'appium:appActivity': '.view.TextFields',
'appium:orientation': 'LANDSCAPE',
}));
await driver.getOrientation().should.eventually.eql('LANDSCAPE');
});
it('should have portrait orientation if nothing requested', async function () {
driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {
appActivity: '.view.TextFields',
driver = await initSession(amendCapabilities(APIDEMOS_CAPS, {
'appium:appActivity': '.view.TextFields',
}));
await driver.getOrientation().should.eventually.eql('PORTRAIT');
});
});
describe('setting -', function () {
before(async function () {
driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {
appActivity: '.view.TextFields'
driver = await initSession(amendCapabilities(APIDEMOS_CAPS, {
'appium:appActivity': '.view.TextFields'
}));
});
after(async function () {
Expand All @@ -53,7 +53,7 @@ describe('apidemo - orientation -', function () {
await B.delay(3000);
await driver.getOrientation().should.eventually.become('LANDSCAPE');
});
it('should rotate screen to landscape', async function () {
it('should rotate screen to portrait', async function () {
await driver.setOrientation('LANDSCAPE');
await B.delay(3000);
await driver.setOrientation('PORTRAIT');
Expand Down
36 changes: 11 additions & 25 deletions test/functional/commands/strings-e2e-specs.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import chai from 'chai';
import chaiAsPromised from 'chai-as-promised';
import { APIDEMOS_CAPS } from '../desired';
import { APIDEMOS_CAPS, amendCapabilities } from '../desired';
import ADB from 'appium-adb';
import { initSession, deleteSession } from '../helpers/session';
import { getLocale } from '../helpers/helpers';
import _ from 'lodash';
import { androidHelpers } from 'appium-android-driver';


Expand All @@ -16,26 +15,19 @@ describe('strings', function () {

describe('specific language', function () {
before(async function () {
// Don't run these tests on TestObject. On TO, we don't have access to the .apk
// which is necessary for extracting the app strings
if (process.env.TESTOBJECT_E2E_TESTS) {
this.skip();
}
driver = await initSession(APIDEMOS_CAPS);
});
after(async function () {
if (!process.env.TESTOBJECT_E2E_TESTS) {
await deleteSession();
}
await deleteSession();
});

it('should return app strings', async function () {
let strings = await driver.getAppStrings('en');
let strings = await driver.getStrings('en');
strings.hello_world.should.equal('Hello, World!');
});

it('should return app strings for different language', async function () {
let strings = await driver.getAppStrings('fr');
let strings = await driver.getStrings('fr');
strings.hello_world.should.equal('Bonjour, Monde!');
});
});
Expand All @@ -44,10 +36,6 @@ describe('strings', function () {
let initialLocale;
let adb;
before(async function () {
// Don't test ADB on test object
if (process.env.TESTOBJECT_E2E_TESTS) {
this.skip();
}
// restarting doesn't work on Android 7+
adb = new ADB();
initialLocale = await getLocale(adb);
Expand All @@ -71,19 +59,17 @@ describe('strings', function () {
it('should return app strings with default locale/language', async function () {
driver = await initSession(APIDEMOS_CAPS);

let strings = await driver.getAppStrings();
let strings = await driver.getStrings();
strings.hello_world.should.equal('Hello, World!');
});
it('should return app strings when language/locale set @skip-ci', async function () {
if (process.env.TESTOBJECT_E2E_TESTS) {
this.skip();
}
driver = await initSession(_.defaults({
language: 'fr',
locale: 'CA',
}, APIDEMOS_CAPS));
const caps = amendCapabilities(APIDEMOS_CAPS, {
'appium:language': 'fr',
'appium:locale': 'CA',
});
const driver = await initSession(caps);

let strings = await driver.getAppStrings();
let strings = await driver.getStrings();
strings.hello_world.should.equal('Bonjour, Monde!');
});
});
Expand Down
14 changes: 7 additions & 7 deletions test/functional/commands/viewport-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('testViewportCommands', function () {
});

it('should get device pixel ratio, status bar height, and viewport rect', async function () {
const {viewportRect, statBarHeight, pixelRatio} = await driver.sessionCapabilities();
const {viewportRect, statBarHeight, pixelRatio} = await driver.getSession();
pixelRatio.should.exist;
pixelRatio.should.not.equal(0);
statBarHeight.should.exist;
Expand All @@ -34,27 +34,27 @@ describe('testViewportCommands', function () {
});

it('should get scrollable element', async function () {
let scrollableEl = await driver.elementByXPath('//*[@scrollable="true"]');
let scrollableEl = await driver.$('//*[@scrollable="true"]');
scrollableEl.should.exist;
});

it('should get content size from scrollable element found as uiobject', async function () {
let scrollableEl = await driver.elementByXPath('//*[@scrollable="true"]');
let scrollableEl = await driver.$('//*[@scrollable="true"]');
let contentSize = await scrollableEl.getAttribute('contentSize');
contentSize.should.exist;
JSON.parse(contentSize).scrollableOffset.should.exist;
});

it('should get content size from scrollable element found as uiobject2', async function () {
let scrollableEl = await driver.elementByXPath('//android.widget.ScrollView');
let scrollableEl = await driver.$('//android.widget.ScrollView');
let contentSize = await scrollableEl.getAttribute('contentSize');
contentSize.should.exist;
JSON.parse(contentSize).scrollableOffset.should.exist;
});

it('should get first element from scrollable element', async function () {
let scrollableEl = await driver.elementByXPath('//*[@scrollable="true"]');
let element = await scrollableEl.elementByXPath('/*[@firstVisible="true"]');
let scrollableEl = await driver.$('//*[@scrollable="true"]');
let element = await scrollableEl.$('/*[@firstVisible="true"]');
element.should.exist;
});

Expand All @@ -63,7 +63,7 @@ describe('testViewportCommands', function () {
if (process.env.CI) {
return this.skip();
}
const {viewportRect, statBarHeight} = await driver.sessionCapabilities();
const {viewportRect, statBarHeight} = await driver.getSession();
const fullScreen = await driver.takeScreenshot();
const viewScreen = await driver.execute('mobile: viewportScreenshot');
const fullB64 = Buffer.from(fullScreen, 'base64');
Expand Down