Bring Sample Code into master (#10880)

* Sample code stub (#9887)

* WD tests

* WD sample code (#9918)

* WebdriverIO sample code (#10166)

* Ruby sample code (#10331)

* PHP Sample Code (#10209)

* Basic Android java test

* Java sample code (#10427)

* Sample code (#10834)

* Sample code stub (#9887)

* WD tests

* WD sample code (#9918)

* WebdriverIO sample code (#10166)

* Ruby sample code (#10331)

* PHP Sample Code (#10209)

* Basic Android java test

* Java sample code (#10427)

* fixed WDIO test

* Update .npmignore
This commit is contained in:
Isaac A. Murchie
2018-06-15 08:23:42 -04:00
committed by GitHub
parent aab1649996
commit 04f6543561
68 changed files with 2098 additions and 27 deletions

View File

@@ -0,0 +1,18 @@
# Javascript WebdriverIO Client Sample Code
## Setup
* Must have NodeJS and NPM installed (https://nodejs.org/en/)
* Install dependencies by running `npm install`
## Running Tests
* To run all of the tests, run `npm test`
* To run individual tests, run `$(npm bin)/mocha test/path/to/test.js`
## Troubleshooting
* ```Original error: '11.1' does not exist in the list of simctl SDKs. Only the following Simulator SDK versions are available on your system: x.y```
* By default, these example tests expect IOS version 11.1
* If 11.1 isn't available on your system, set the version by setting environment variable `IOS_PLATFORM_VERSION` or install with Xcode
(e.g.: `IOS_PLATFORM_VERSION=11.2 $(npm bin)/mocha -t 6000000 test/path/to/test.js`)

View File

@@ -0,0 +1,9 @@
const path = require('path');
if (process.env.SAUCE_LABS) {
exports.iosTestApp = "http://appium.github.io/appium/assets/TestApp7.1.app.zip";
exports.androidApiDemos = "http://appium.github.io/appium/assets/ApiDemos-debug.apk";
} else {
exports.iosTestApp = path.resolve(__dirname, "..", "..", "apps", "TestApp.app.zip");
exports.androidApiDemos = path.resolve(__dirname, "..", "..", "apps", "ApiDemos-debug.apk");
}

View File

@@ -0,0 +1,83 @@
const path = require("path");
const iosCaps = {
platformName: "iOS",
automationName: "XCUITest",
deviceName: process.env.IOS_DEVICE_NAME || "iPhone 6s",
platformVersion: process.env.IOS_PLATFORM_VERSION || "11.1",
app: undefined // Will be added in tests
};
const iosWebCaps = {
platformName: "iOS",
automationName: "XCUITest",
deviceName: process.env.IOS_DEVICE_NAME || "iPhone 6s",
platformVersion: process.env.IOS_PLATFORM_VERSION || "11.1",
browserName: "Safari"
};
// Leave the Android platformVersion blank and set deviceName to a random string (Android deviceName is ignored by Appium but is still required)
// If we're using SauceLabs, set the Android deviceName and platformVersion to the latest supported SauceLabs device and version
const DEFAULT_ANDROID_DEVICE_NAME = process.env.SAUCE
? "Android GoogleAPI Emulator"
: "My Android Device";
const DEFAULT_ANDROID_PLATFORM_VERSION = process.env.SAUCE ? "7.1" : null;
const androidCaps = {
platformName: "Android",
automationName: "UiAutomator2",
deviceName: process.env.ANDROID_DEVICE_NAME || DEFAULT_ANDROID_DEVICE_NAME,
platformVersion:
process.env.ANDROID_PLATFORM_VERSION || DEFAULT_ANDROID_PLATFORM_VERSION,
app: undefined // Will be added in tests
};
const androidWebCaps = {
platformName: "Android",
automationName: "UiAutomator2",
deviceName: process.env.ANDROID_DEVICE_NAME || DEFAULT_ANDROID_DEVICE_NAME,
platformVersion:
process.env.ANDROID_PLATFORM_VERSION || DEFAULT_ANDROID_PLATFORM_VERSION,
browserName: "chrome"
};
const serverConfig = {
host: process.env.APPIUM_HOST || "localhost",
port: process.env.APPIUM_PORT || 4723,
logLevel: "verbose"
};
const androidOptions = Object.assign(
{
desiredCapabilities: androidCaps
},
serverConfig
);
const iosOptions = Object.assign(
{
desiredCapabilities: iosCaps
},
serverConfig
);
const androidWebOptions = Object.assign(
{
desiredCapabilities: androidWebCaps
},
serverConfig
);
const iosWebOptions = Object.assign(
{
desiredCapabilities: iosWebCaps
},
serverConfig
);
module.exports = {
androidOptions,
iosOptions,
androidWebOptions,
iosWebOptions
};

View File

@@ -0,0 +1,17 @@
{
"name": "webdriverio-sample-appium-tests",
"version": "1.0.0",
"description": "Sample tests using webdriverio",
"main": "index.js",
"scripts": {
"test": "mocha --timeout 6000000 test/basic"
},
"author": "Daniel Graham",
"license": "Apache-2.0",
"devDependencies": {
"assert": "^1.4.1",
"chai": "^4.1.2",
"mocha": "^5.0.0",
"webdriverio": "^4.12.0"
}
}

View File

@@ -0,0 +1,32 @@
const webdriverio = require("webdriverio");
const androidOptions = require("../../helpers/caps").androidOptions;
const app = require("../../helpers/apps").androidApiDemos;
const assert = require("chai").assert;
androidOptions.desiredCapabilities.app = app;
describe("Create Android session", function() {
let client;
before(function() {
client = webdriverio.remote(androidOptions);
return client.init();
});
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);
});
});
});

View File

@@ -0,0 +1,29 @@
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();
});
after(function() {
return client.end();
});
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(/<html/g);
});
});
});

View File

@@ -0,0 +1,40 @@
const webdriverio = require("webdriverio");
const iosOptions = require("../../helpers/caps").iosOptions;
const app = require("../../helpers/apps").iosTestApp;
const assert = require("chai").assert;
iosOptions.desiredCapabilities.app = app;
describe("Basic IOS interactions", function() {
let client;
beforeEach(function() {
client = webdriverio.remote(iosOptions);
return client.init();
});
afterEach(function() {
return client.end();
});
it("should send keys to inputs", function() {
return client
.waitForExist("~TextField1", 5000)
.element("~TextField1")
.setValue("Hello World!")
.getText("~TextField1", function(result) {
assert.equal(result.value, "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");
});
});
});

View File

@@ -0,0 +1,36 @@
const webdriverio = require("webdriverio");
const iosOptions = require("../../helpers/caps").iosOptions;
const app = require("../../helpers/apps").iosTestApp;
const assert = require("chai").assert;
iosOptions.desiredCapabilities.app = app;
describe("Create session", function() {
let client;
beforeEach(function() {
client = 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);
});
});
});

View File

@@ -0,0 +1,17 @@
const webdriverio = require("webdriverio");
const iosOptions = require("../../helpers/caps").iosWebOptions;
const app = require("../../helpers/apps").iosTestApp;
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();
});
});

View File

@@ -0,0 +1 @@
--timeout 1800000