appium-xcuitest-driver
Version:
Appium driver for iOS using XCUITest for backend
167 lines • 8.23 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const desired_1 = require("../desired");
const session_1 = require("../helpers/session");
const helpers_1 = require("./helpers");
const chai_1 = __importStar(require("chai"));
const chai_as_promised_1 = __importDefault(require("chai-as-promised"));
chai_1.default.use(chai_as_promised_1.default);
const SCROLL_INTO_VIEW = `return arguments[0].scrollIntoView(true);`;
const GET_RIGHT_INNERHTML = `return document.body.innerHTML.indexOf('I am some page content') > 0`;
const GET_WRONG_INNERHTML = `return document.body.innerHTML.indexOf('I am not some page content') > 0`;
const GET_ELEM_BY_TAGNAME = `return document.getElementsByTagName('a');`;
describe('safari - execute -', function () {
this.timeout(session_1.MOCHA_TIMEOUT);
let driver;
before(async function () {
const caps = (0, desired_1.amendCapabilities)(desired_1.SAFARI_CAPS, {
'appium:safariInitialUrl': helpers_1.GUINEA_PIG_PAGE,
'appium:showSafariConsoleLog': true,
});
driver = await (0, session_1.initSession)(caps);
});
after(async function () {
await (0, session_1.deleteSession)();
});
async function runTests(secure = false) {
describe('mobile: x methods', function () {
it('should run in native context', async function () {
await (0, chai_1.expect)(driver.executeScript('mobile: scroll', [{ direction: 'down' }])).to.not.be.rejected;
});
});
describe('synchronous', function () {
it('should bubble up javascript errors', async function () {
await (0, chai_1.expect)(driver.executeScript(`'nan'--`, [])).to.be.rejected;
});
it('should eval javascript', async function () {
await (0, chai_1.expect)(driver.executeScript('return 1 + 1', [])).to.eventually.equal(2);
});
it('should not be returning hardcoded results', async function () {
await (0, chai_1.expect)(driver.executeScript('return 1+1', [])).to.eventually.equal(2);
});
it(`should return nothing when you don't explicitly return`, async function () {
(0, chai_1.expect)(await driver.executeScript('1+1', [])).to.not.exist;
});
if (!secure) {
it('should execute code inside the web view', async function () {
await (0, chai_1.expect)(driver.executeScript(GET_RIGHT_INNERHTML, [])).to.eventually.be.ok;
await (0, chai_1.expect)(driver.executeScript(GET_WRONG_INNERHTML, [])).to.eventually.not.be.ok;
});
it('should convert selenium element arg to webview element', async function () {
const el = await driver.findElement('id', 'useragent');
await driver.executeScript(SCROLL_INTO_VIEW, [el]);
});
it('should catch stale or undefined element as arg', async function () {
const el = await driver.findElement('id', 'useragent');
await (0, chai_1.expect)(driver.executeScript(SCROLL_INTO_VIEW, [{ ELEMENT: el.value + 1 }])).to.be
.rejected;
});
it('should be able to return multiple elements from javascript', async function () {
await (0, chai_1.expect)(driver
.executeScript(GET_ELEM_BY_TAGNAME, [])).to.eventually.have.length.above(0);
});
}
it('should pass along non-element arguments', async function () {
const arg = 'non-element-argument';
await (0, chai_1.expect)(driver
.executeScript('var args = Array.prototype.slice.call(arguments, 0); return args[0];', [
arg,
])).to.eventually.equal(arg);
});
it('should handle return values correctly', async function () {
const arg = ['one', 'two', 'three'];
await (0, chai_1.expect)(driver
.executeScript('var args = Array.prototype.slice.call(arguments, 0); return args;', arg)).to.eventually.eql(arg);
});
});
// TODO: Update for WdIO compatibility
// describe('asynchronous', function () {
// it('should execute async javascript', async function () {
// await driver.setAsyncScriptTimeout(1000);
// await driver.executeAsync(`arguments[arguments.length - 1](123);`)
// .should.eventually.equal(123);
// });
// it('should bubble up errors', async function () {
// await driver.executeAsync(`arguments[arguments.length - 1]('nan'--);`)
// .should.be.rejectedWith(/operator applied to value that is not a reference/);
// });
// it('should timeout when callback is not invoked', async function () {
// await driver.setAsyncScriptTimeout(1000);
// await driver.executeAsync(`return 1 + 2`)
// .should.be.rejectedWith(/Timed out waiting for/);
// });
// });
}
describe('http', function () {
runTests();
// TODO: Update for WdIO compatibility
// describe('cors', function () {
// let server;
// const host = '127.0.0.1';
// const port = 8080;
// before(function () {
// // create an http server so we can test CORS handling without
// // going to an external site
// server = http.createServer(function (req, res) {
// res.writeHead(200, {'Content-Type': 'text/html'});
// res.write('appium-xcuitest-driver async execute tests');
// res.end();
// }).listen({host, port});
// });
// after(function () {
// if (server) {
// server.close();
// }
// });
// it('should execute async javascript from a different site', async function () {
// await driver.navigateTo(`http://${host}:${port}`);
// await driver.setAsyncScriptTimeout(1000);
// await driver.executeAsync(`arguments[arguments.length - 1](123);`)
// .should.eventually.equal(123);
// });
// });
});
describe('https', function () {
before(async function () {
await (0, helpers_1.openPage)(driver, 'https://google.com');
});
runTests(true);
});
});
//# sourceMappingURL=safari-execute-e2e-specs.js.map