Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async function ensureUnlocked (driver) {
// on Travis the device is sometimes not unlocked
await retryInterval(10, 1000, async function () {
if (!await driver.isLocked()) {
return;
}
console.log(`\n\nDevice locked. Attempting to unlock`); // eslint-disable-line
await driver.unlock();
// trigger another iteration
throw new Error(`The device is locked.`);
});
}
it('should type a url in the text field', async function () {
// in Travis this sometimes gets the wrong text
let retries = process.env.CI ? 5 : 1;
await retryInterval(retries, 100, async () => {
let el = await driver.elementByClassName('XCUIElementTypeTextField');
await el.clear();
await el.type(text3);
let text = await el.text();
text.should.eql(text3);
});
});
it('should be able to type into two text fields', async function () {
async tailLogsUntil (bootedIndicator, timeoutMs) {
let simLog = path.resolve(this.getLogDir(), 'system.log');
// we need to make sure log file exists before we can tail it
await retryInterval(200, 200, async () => {
let exists = await fs.exists(simLog);
if (!exists) {
throw new Error(`Could not find Simulator log: '${simLog}'`);
}
});
log.info(`Simulator log at '${simLog}'`);
log.info(`Tailing simulator logs until we encounter the string "${bootedIndicator}"`);
log.info(`We will time out after ${timeoutMs}ms`);
try {
await tailUntil(simLog, bootedIndicator, timeoutMs);
} catch (err) {
log.debug('Simulator startup timed out. Continuing anyway.');
}
}
let navigate = async () => {
let oldImpWait = this.implicitWaitMs;
this.implicitWaitMs = 7000;
// find the url bar, and tap on it. retry to make sure we don't try
// too soon while the view is still loading
let el = await retryInterval(3, 1000, async () => {
return await this.findElement('accessibility id', 'URL');
});
this.implicitWaitMs = oldImpWait;
try {
await this.nativeTap(el.ELEMENT);
} catch (err) {
if (_.includes(err.message, 'could not be tapped')) {
if (tries++ >= MAX_TRIES) throw err; // eslint-disable-line curly
// generally this means that Safari is in page viewing mode
// so try to open a new page and then redo the navigation
await openNewPage();
return await navigate();
} else {
throw err;
helpers.getCPUInfo = async function getCPUInfo (packageName, dataReadTimeout = 2) {
// TODO: figure out why this is
// sometimes, the function of 'adb.shell' fails. when I tested this function on the target of 'Galaxy Note5',
// adb.shell(dumpsys cpuinfo) returns cpu datas for other application packages, but I can't find the data for packageName.
// It usually fails 30 times and success for the next time,
// Since then, he has continued to succeed.
return await retryInterval(dataReadTimeout, RETRY_PAUSE, async () => {
const cmd = ['dumpsys', 'cpuinfo', '|', 'grep', `'${packageName}'`];
const data = await this.adb.shell(cmd);
if (_.isEmpty(data)) {
throw new Error('No data from dumpsys');
}
// `data` will be something like
// +0% 2209/io.appium.android.apis: 0.1% user + 0.2% kernel
const userMatch = /([\d.]+)%\s+user/.exec(data);
const kernelMatch = /([\d.]+)%\s+kernel/.exec(data);
if (!userMatch || !kernelMatch) {
throw new Error(`Unable to parse cpu data: '${data}'`);
}
return [_.clone(CPU_KEYS), [userMatch[1], kernelMatch[1]]];
});
};
async function runTextEditTest (driver, testText, keys = false) {
let el = await getElement(driver, EDITTEXT_CLASS);
await el.clear();
await el.click();
if (keys) {
await driver.keys([testText]);
} else {
await el.sendKeys(testText);
}
await retryInterval(process.env.TESTOBJECT_E2E_TESTS ? 100 : 10, 1000, async () => {
let text = await el.text();
deSamsungify(text).should.be.equal(testText);
});
return el;
}
beforeEach(async function () {
await retryInterval(5, 1000, async () => {
await killAllSimulators();
});
});
async function loadPage (driver, url) {
await retryInterval(5, 1000, async function () {
await openPage(driver, url);
const title = await spinTitle(driver);
title.should.not.include('Cannot Open Page');
});
}
before(async function () {
driver = await initSession(Object.assign({}, APIDEMOS_CAPS, {appActivity: textFieldsActivity}));
el = await retryInterval(5, 1000, async function () {
const els = await driver.elementsByClassName('android.widget.EditText');
els.should.have.length.at.least(1);
return _.last(els);
});
});
after(async function () {