From e7ed9763dfab6e80d4b4c1410318e1ce69df428e Mon Sep 17 00:00:00 2001 From: Oskar Lindgren Date: Sat, 29 Dec 2018 15:32:38 +0900 Subject: [PATCH 1/2] add webdriverio appium desired capabilities --- types/webdriverio/index.d.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/types/webdriverio/index.d.ts b/types/webdriverio/index.d.ts index 48fb31af47..4a1f585808 100644 --- a/types/webdriverio/index.d.ts +++ b/types/webdriverio/index.d.ts @@ -6,6 +6,7 @@ // Tanvir ul Islam // Dave Parslow // Phil Leger +// Oskar Lindgren // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped /// @@ -273,6 +274,11 @@ declare namespace WebdriverIO { [name: string]: any; }; + // Appium specific + platformVersion?: string; + automationName?: string; + app?: string; + cleanSession?: boolean; // Chrome specific From 6ae5225037c41b3ffd3d90dd1e0ede947b932cc9 Mon Sep 17 00:00:00 2001 From: Oskar Lindgren Date: Sat, 29 Dec 2018 15:35:36 +0900 Subject: [PATCH 2/2] refactor webdriverio tests --- types/webdriverio/webdriverio-tests.ts | 162 ++++++++++++++----------- 1 file changed, 89 insertions(+), 73 deletions(-) diff --git a/types/webdriverio/webdriverio-tests.ts b/types/webdriverio/webdriverio-tests.ts index 11b473066b..f5e33e776e 100644 --- a/types/webdriverio/webdriverio-tests.ts +++ b/types/webdriverio/webdriverio-tests.ts @@ -2,11 +2,18 @@ import * as webdriverio from "webdriverio"; import { assert } from "chai"; // Stub mocha functions -const {describe, it, before, after, beforeEach, afterEach} = null as any as { - [s: string]: ((s: string, cb: (done: any) => void) => void) & ((cb: (done: any) => void) => void) & {only: any, skip: any}; +const { describe, it, before, after, beforeEach, afterEach } = null as any as { + [s: string]: ((s: string, cb: (done: any) => void) => void) & ((cb: (done: any) => void) => void) & { only: any, skip: any }; }; -describe("webdriver.io page", () => { +describe("my webdriverio tests", () => { + let client: webdriverio.Client; + + before(async () => { + client = webdriverio.remote({ deprecationWarnings: true, desiredCapabilities: { browserName: "phantomjs" } }); + await client.init(); + }); + it("should have the right title - the good old callback way", () => { assert.equal( browser @@ -23,15 +30,6 @@ describe("webdriver.io page", () => { assert.equal(title, "WebdriverIO - Selenium 2.0 javascript bindings for nodejs"); }); }); -}); - -describe.only("my webdriverio tests", () => { - let client: webdriverio.Client; - - before(async () => { - client = webdriverio.remote({ deprecationWarnings: true, desiredCapabilities: { browserName: "phantomjs" } }); - await client.init(); - }); it("Github test", async () => { await client.url("https://github.com/"); @@ -57,76 +55,94 @@ describe.only("my webdriverio tests", () => { }); }); -const matrix = webdriverio.multiremote({ - browserA: { - desiredCapabilities: { - browserName: "chrome", - chromeOptions: { - args: [ - "use-fake-device-for-media-stream", - "use-fake-ui-for-media-stream", - ] - } - } - }, - browserB: { - desiredCapabilities: { - browserName: "chrome", - chromeOptions: { - args: [ - "use-fake-device-for-media-stream", - "use-fake-ui-for-media-stream", - ] - } - } - } +describe("multiremote test", () => { + let matrix: webdriverio.Client; + + before(async () => { + matrix = webdriverio.multiremote({ + browserA: { + desiredCapabilities: { + browserName: "chrome", + chromeOptions: { + args: [ + "use-fake-device-for-media-stream", + "use-fake-ui-for-media-stream", + ], + }, + }, + }, + browserB: { + desiredCapabilities: { + browserName: "chrome", + chromeOptions: { + args: [ + "use-fake-device-for-media-stream", + "use-fake-ui-for-media-stream", + ], + }, + }, + }, + }); }); -const channel = Math.round(Math.random() * 100000000000); + it("clicks a button in a random channel at apprtc", () => { + const channel = Math.round(Math.random() * 100000000000); -matrix - .init() - .url("https://apprtc.appspot.com/r/" + channel) - .click("#confirm-join-button") - .pause(5000) - .end(); + matrix + .init() + .url("https://apprtc.appspot.com/r/" + channel) + .click("#confirm-join-button") + .pause(5000) + .end(); + }); -const options = { - desiredCapabilities: { - browserName: "chrome" - } -}; + after(async () => { + await matrix.end(); + }); +}); -webdriverio - .remote(options) - .init() - .url("https://news.ycombinator.com/") - .selectorExecute("//div", (inputs: HTMLElement[], message: string) => { - return `${inputs.length} ${message}`; - }, "divs on the page") - .then((res: string) => { - console.log(res); - }) - .end(); +describe("testing feaures with chrome", () => { + const options = { + desiredCapabilities: { + browserName: "chrome", + }, + }; -webdriverio - .remote(options) - .init() - .url("http://www.google.com/") - .waitForVisible("//input[@type='submit']", 5000) - .then((visible) => { - console.log(visible); // Should return true - }) - .end(); + it("can use selectorExecute", () => { + webdriverio + .remote(options) + .init() + .url("https://news.ycombinator.com/") + .selectorExecute("//div", (inputs: HTMLElement[], message: string) => { + return `${inputs.length} ${message}`; + }, "divs on the page") + .then((res: string) => { + console.log(res); + }) + .end(); + }); -let hooks: webdriverio.Hooks = {}; + it("can waitForVisible", () => { + webdriverio + .remote(options) + .init() + .url("http://www.google.com/") + .waitForVisible("//input[@type='submit']", 5000) + .then((visible) => { + console.log(visible); // Should return true + }) + .end(); + }); +}); + +let hooks: webdriverio.Hooks = {}; hooks = { - // Hooks can be a noop function - onPrepare: () => undefined, - onError() { - // Hooks don't have to return a value - } + // Hooks can be a noop function + onPrepare: () => undefined, + onError() { + // Hooks don't have to return a value + } }; hooks.onComplete = async () => {