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

Fix flakey geo-location tests #310

Merged
merged 2 commits into from
Mar 21, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions test/functional/commands/geo-location-e2e-specs.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,31 @@ chai.should();
chai.use(chaiAsPromised);

describe('geo-location -', function () {
this.retries(2);

let driver;
before(async function () {
beforeEach(async function () {
driver = await initSession(GPS_DEMO_CAPS);
});
after(async function () {
afterEach(async function () {
await deleteSession();
});

function getRandomInt (min, max) {
return Math.floor(Math.random() * (max - min + 1) + min);
}

it('should set geo location', async function () {
let getText = async () => {
return await retryInterval(5, 1000, async function () {
const getText = async function () {
return await retryInterval(10, 1000, async function () {
const textViews = await driver.elementsByClassName('android.widget.TextView');
textViews.length.should.be.at.least(2);
return await textViews[1].text();
});
};

let latitude = '27.1';
let longitude = '78.0';
const latitude = getRandomInt(-90, 90);
const longitude = getRandomInt(-180, 180);

let text = await getText();
text.should.not.include(`Latitude: ${latitude}`);
Expand All @@ -36,14 +42,16 @@ describe('geo-location -', function () {
await driver.setGeoLocation(latitude, longitude);

// wait for the text to change
await retryInterval(6, 1000, async () => {
await retryInterval(10, 1000, async () => {
if (await getText() === 'GPS Tutorial') {
throw new Error('Location not set yet. Retry.');
}
});

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