diff --git a/docs/en/about-appium/getting-started.md b/docs/en/about-appium/getting-started.md index 6a1250ca9..2c077bfb0 100644 --- a/docs/en/about-appium/getting-started.md +++ b/docs/en/about-appium/getting-started.md @@ -168,7 +168,7 @@ So here is how we begin to construct a session in our test file: // javascript const opts = { port: 4723, - desiredCapabilities: { + capabilities: { platformName: "Android", platformVersion: "8.0", deviceName: "Android Emulator", @@ -193,13 +193,12 @@ session: ```js // javascript -client - .init() - .click("~App") - .click("~Alert Dialogs") - .back() - .back() - .end(); +const elementId = await client.findElement("accessibility id","TextField1"); +client.elementSendKeys(elementId.ELEMENT, "Hello World!"); +const elementValue = await client.findElement("accessibility id","TextField1"); +await client.getElementAttribute(elementValue.ELEMENT,"value").then((attr) => { +assert.equal(attr,"Hello World!"); +}); ``` What's going on here is that after creating a session and launching our app, @@ -220,7 +219,7 @@ const wdio = require("webdriverio"); const opts = { port: 4723, - desiredCapabilities: { + capabilities: { platformName: "Android", platformVersion: "8.0", deviceName: "Android Emulator", @@ -231,13 +230,11 @@ const opts = { const client = wdio.remote(opts); -client - .init() - .click("~App") - .click("~Alert Dialogs") - .back() - .back() - .end(); +const elementId = await client.findElement("accessibility id","TextField1"); client.elementSendKeys(elementId.ELEMENT, "Hello World!"); +const elementValue = await client.findElement("accessibility id","TextField1"); +await client.getElementAttribute(elementValue.ELEMENT,"value").then((attr) => { +assert.equal(attr,"Hello World!"); +}); ``` You can try and run this test on your own. Simply save it and execute it using diff --git a/sample-code/javascript-webdriverio/helpers/caps.js b/sample-code/javascript-webdriverio/helpers/caps.js index 53234d11d..f977466af 100644 --- a/sample-code/javascript-webdriverio/helpers/caps.js +++ b/sample-code/javascript-webdriverio/helpers/caps.js @@ -44,33 +44,33 @@ const androidWebCaps = { const serverConfig = { host: process.env.APPIUM_HOST || "localhost", port: process.env.APPIUM_PORT || 4723, - logLevel: "verbose" + logLevel: "info" }; const androidOptions = Object.assign( { - desiredCapabilities: androidCaps + capabilities: androidCaps }, serverConfig ); const iosOptions = Object.assign( { - desiredCapabilities: iosCaps + capabilities: iosCaps }, serverConfig ); const androidWebOptions = Object.assign( { - desiredCapabilities: androidWebCaps + capabilities: androidWebCaps }, serverConfig ); const iosWebOptions = Object.assign( { - desiredCapabilities: iosWebCaps + capabilities: iosWebCaps }, serverConfig ); diff --git a/sample-code/javascript-webdriverio/package.json b/sample-code/javascript-webdriverio/package.json index 44629d3ab..ce601cc00 100644 --- a/sample-code/javascript-webdriverio/package.json +++ b/sample-code/javascript-webdriverio/package.json @@ -12,6 +12,6 @@ "assert": "^1.4.1", "chai": "^4.1.2", "mocha": "^5.0.0", - "webdriverio": "^4.12.0" + "webdriverio": "^5.1.0" } } diff --git a/sample-code/javascript-webdriverio/test/basic/android-create-session.test.js b/sample-code/javascript-webdriverio/test/basic/android-create-session.test.js index f813897e4..dc13ab0ca 100644 --- a/sample-code/javascript-webdriverio/test/basic/android-create-session.test.js +++ b/sample-code/javascript-webdriverio/test/basic/android-create-session.test.js @@ -3,30 +3,21 @@ const androidOptions = require("../../helpers/caps").androidOptions; const app = require("../../helpers/apps").androidApiDemos; const assert = require("chai").assert; -androidOptions.desiredCapabilities.app = app; +androidOptions.capabilities.app = app; describe("Create Android session", function() { let client; - before(function() { - client = webdriverio.remote(androidOptions); - return client.init(); + before(async() => { + client = await webdriverio.remote(androidOptions); }); - it("should create and destroy a session", function() { - return client - .sessions(function(res) { - assert.isAbove(res.value.length, 0); - }) - .currentActivity(function(res) { - assert.equals(res.value, ".ApiDemos"); - }) - .getCurrentPackage(function(res) { - assert.equals(res.value, "io.appium.android.apis"); - }) - .end() - .sessions(function(res) { - assert.equals(res.value.length, 0); - }); + it("should create and destroy a session", async function() { + const res = await client.status(); + assert.isObject(res.build); + const current_package = await client.getCurrentPackage(); + assert.equal(current_package, "io.appium.android.apis"); + const delete_session = await client.deleteSession(); + assert.isNull(delete_session); }); }); diff --git a/sample-code/javascript-webdriverio/test/basic/android-create-web-session.test.js b/sample-code/javascript-webdriverio/test/basic/android-create-web-session.test.js index 728457b15..f2ab94060 100644 --- a/sample-code/javascript-webdriverio/test/basic/android-create-web-session.test.js +++ b/sample-code/javascript-webdriverio/test/basic/android-create-web-session.test.js @@ -1,29 +1,23 @@ const webdriverio = require("webdriverio"); const androidOptions = require("../../helpers/caps").androidWebOptions; -const app = require("../../helpers/apps").androidApiDemos; const assert = require("chai").assert; describe("Create Chrome web session", function() { let client; - before(function() { - client = webdriverio.remote(androidOptions); - return client.init(); + before(async function() { + client = await webdriverio.remote(androidOptions); }); - after(function() { - return client.end(); + after(async function() { + return await client.deleteSession(); }); it("should create and destroy Android browser session", async function() { // Navigate to google.com - return client - .url("https://www.google.com") - .title(function(res) { - assert.equal(res.value, "Google"); - }) - .source(function(res) { - assert.match(/ { + assert.equal(attr,"Hello World!"); + }); }); it("should click a button that opens an alert", async function() { - return client - .waitForExist("~show alert", 5000) - .element("~show alert") - .click() - .waitForExist("~Cool title", 5000) - .getText("~Cool title", function(result) { - assert.equal(result.value, "Cool title"); - }); + const element = await client.findElement("accessibility id","show alert"); + await client.elementClick(element.ELEMENT); + assert.equal(await client.getAlertText(),"Cool title\nthis alert is so cool."); }); }); diff --git a/sample-code/javascript-webdriverio/test/basic/ios-create-session.test.js b/sample-code/javascript-webdriverio/test/basic/ios-create-session.test.js index 7d34f53c6..3456c0429 100644 --- a/sample-code/javascript-webdriverio/test/basic/ios-create-session.test.js +++ b/sample-code/javascript-webdriverio/test/basic/ios-create-session.test.js @@ -3,34 +3,23 @@ const iosOptions = require("../../helpers/caps").iosOptions; const app = require("../../helpers/apps").iosTestApp; const assert = require("chai").assert; -iosOptions.desiredCapabilities.app = app; +iosOptions.capabilities.app = app; describe("Create session", function() { let client; - beforeEach(function() { - client = webdriverio.remote(iosOptions); + beforeEach(async function() { + client = await webdriverio.remote(iosOptions); }); - afterEach(function() { - return client.end(); - }); - - it("should create and destroy IOS sessions", function() { - return client - .sessions(function(result) { - assert.equal(result.value.length, 0); - }) - .sessions(function(result) { - assert.equal(result.value.length, 1); - }) - .init() - .getAttribute("XCUIElementTypeApplication", "name", function(result) { - assert.equal(result.value, "TestApp"); - }) - .end() - .sessions(function(result) { - assert.equal(result.value.length, 0); - }); + it("should create and destroy IOS sessions", async function() { + const res = await client.status(); + assert.isObject(res.build); + const element = await client.findElement("class name","XCUIElementTypeApplication"); + client.getElementAttribute(element.ELEMENT,"name").then((attr) => { + assert.equal(attr,"TestApp"); + }); + const destroySession = await client.deleteSession(); + assert.isNull(destroySession); }); }); diff --git a/sample-code/javascript-webdriverio/test/basic/ios-create-web-session.test.js b/sample-code/javascript-webdriverio/test/basic/ios-create-web-session.test.js index 7fefb74df..4d39bf0b1 100644 --- a/sample-code/javascript-webdriverio/test/basic/ios-create-web-session.test.js +++ b/sample-code/javascript-webdriverio/test/basic/ios-create-web-session.test.js @@ -5,13 +5,10 @@ const assert = require("chai").assert; describe("Create Safari session", function() { it("should create and destroy IOS Safari session", async function() { - let client = webdriverio.remote(iosOptions); - return client - .init() - .url("https://www.google.com") - .title(function(result) { - assert.equal(result.value, "Google"); - }) - .end(); + let client = await webdriverio.remote(iosOptions); + await client.url("https://www.google.com"); + const title = await client.getTitle(); + assert.equal(title, "Google"); + await client.deleteSession(); }); });