mirror of
https://github.com/appium/appium.git
synced 2026-04-27 05:52:35 -05:00
node.js examples fixes
This commit is contained in:
@@ -21,6 +21,7 @@ chaiAsPromised.transferPromiseness = wd.transferPromiseness;
|
||||
var host, port, username, accessKey, desired;
|
||||
|
||||
var desired = {
|
||||
browserName: '',
|
||||
'appium-version': '1.0',
|
||||
platformName: 'iOS',
|
||||
platformVersion: '7.1',
|
||||
@@ -65,8 +66,8 @@ browser
|
||||
})
|
||||
.elementByIosUIAutomation('.buttons()')
|
||||
.click()
|
||||
// .elementByTagName('staticText')
|
||||
// .text().should.become("5")
|
||||
.elementByClassName('UIAStaticText')
|
||||
.text().should.become("5")
|
||||
.catch(function(err) { console.log(err); })
|
||||
.fin(function () {
|
||||
return browser
|
||||
|
||||
@@ -2,9 +2,6 @@
|
||||
"use strict";
|
||||
|
||||
/*
|
||||
TODO: UICatalog was recently updated, we need to adapt this sample code.
|
||||
TODO: Lots of click errors.
|
||||
|
||||
First you need to install node > 0.11 to run this.
|
||||
(You may use this https://github.com/visionmedia/n for easy install/switch
|
||||
between node versions)
|
||||
@@ -19,7 +16,6 @@ APPIUM ON SAUCE LABS USING SAUCE CONNECT:
|
||||
*/
|
||||
|
||||
var wd = require("yiewd")
|
||||
, o_O = require("monocle-js").o_O
|
||||
, path = require("path");
|
||||
|
||||
require("colors");
|
||||
@@ -33,6 +29,7 @@ var staticServer = require('node-static'),
|
||||
var host, port, username, accessKey, desired, server;
|
||||
|
||||
var desired = {
|
||||
browserName: '',
|
||||
'appium-version': '1.0',
|
||||
platformName: 'iOS',
|
||||
platformVersion: '7.1',
|
||||
@@ -57,34 +54,10 @@ if (process.env.SAUCE_CONNECT) {
|
||||
|
||||
desired.name = "Appium: with WD";
|
||||
desired.app = 'http://localhost:8080/UICatalog6.1.app.zip';
|
||||
|
||||
// desired = {
|
||||
// platform: 'ios',
|
||||
// version: '7.1',
|
||||
// device: 'iPhone Simulator',
|
||||
// deviceName: 'iPhone Retina (4-inch 64-bit)',
|
||||
// name: "Appium: with WD",
|
||||
// app: 'http://localhost:8080/UICatalog6.1.app.zip',
|
||||
// newCommandTimeout: 60
|
||||
// };
|
||||
} else {
|
||||
// local config
|
||||
|
||||
host = "localhost";
|
||||
port = 4723;
|
||||
|
||||
var appPath = path.resolve(__dirname, "..", "..", "apps", "UICatalog", "build",
|
||||
"Release-iphonesimulator", "UICatalog.app");
|
||||
desired.app = appPath;
|
||||
// desired = {
|
||||
// device: 'iPhone Simulator',
|
||||
// name: "Appium: with WD",
|
||||
// platform: "Mac",
|
||||
// app: appPath,
|
||||
// // version: "6.0",
|
||||
// browserName: "",
|
||||
// newCommandTimeout: 60
|
||||
// };
|
||||
desired.app = 'assets/UICatalog6.1.app.zip';
|
||||
}
|
||||
|
||||
var browser = wd.remote(host, port, username, accessKey);
|
||||
@@ -96,69 +69,57 @@ browser.on('command', function (meth, path, data) {
|
||||
console.log(' > ' + meth.yellow, path.grey, data || '');
|
||||
});
|
||||
|
||||
var scrollToElement = o_O(function* (element) {
|
||||
var y = (yield element.getLocation()).y;
|
||||
while (y === 0 || y > 400) {
|
||||
// move so top of screen is y - 10
|
||||
var swipeOpts = {
|
||||
duration: 0.5,
|
||||
startY: 0.7,
|
||||
endY: 0.3
|
||||
};
|
||||
yield browser.execute("mobile: swipe", [swipeOpts]);
|
||||
y = (yield element.getLocation()).y;
|
||||
yield browser.sleep(0.5);
|
||||
}
|
||||
});
|
||||
|
||||
browser.run(function* () {
|
||||
try {
|
||||
yield this.init(desired);
|
||||
yield this.elementByName("Buttons, Various uses of UIButton").click();
|
||||
var btns = yield this.elementsByIosUIAutomation('.buttons()');
|
||||
var btns = yield this
|
||||
.elementsByClassName('UIAButton');
|
||||
for (var i = 1; i < 4; i++) {
|
||||
yield btns[i].click();
|
||||
}
|
||||
yield btns[0].click();
|
||||
yield this.elementByName("Controls, Various uses of UIControl").click();
|
||||
var stdSwitch = yield this.elementByXPath("//switch[@name='Standard']");
|
||||
var stdSwitch = yield this.elementByXPath("//UIASwitch[@name='Standard']");
|
||||
yield stdSwitch.sendKeys(true);
|
||||
yield stdSwitch.sendKeys(false);
|
||||
var stdSlider = yield this.elementByXPath("//slider[@name='Standard']");
|
||||
var stdSlider = yield this.elementByXPath("//UIASlider[@name='Standard']");
|
||||
yield stdSlider.sendKeys("0.25");
|
||||
yield stdSlider.sendKeys("0.8");
|
||||
yield this.execute("mobile: swipe", [{endY: 0.05, duration: 0.8}]);
|
||||
var cstSlider = yield this.elementByXPath("//slider[@name='Custom']");
|
||||
yield scrollToElement(cstSlider);
|
||||
var cstSlider = yield this.elementByXPath("//UIASlider[@name='Custom']");
|
||||
yield cstSlider.sendKeys("1.0");
|
||||
// var pages = yield this.elementByTagName("pageIndicator");
|
||||
// yield scrollToElement(pages);
|
||||
// for (i = 0; i < 10; i += 2) {
|
||||
// TODO: not visible, cannot scroll to it in ios71
|
||||
// var pages = yield this.elementByClassName("UIAPageIndicator");
|
||||
// yield pages.moveTo();
|
||||
// for (var i = 0; i < 10; i += 2) {
|
||||
// yield pages.sendKeys(i);
|
||||
// yield this.sleep(3000);
|
||||
// }
|
||||
yield this.elementByName("Back").click();
|
||||
|
||||
yield this.elementByName("TextFields, Uses of UITextField").click();
|
||||
yield this.elementByIosUIAutomation(".textFields();").sendKeys("Hello World!\n");
|
||||
yield this.elementByName("Back").click();
|
||||
yield this.elementByName("Pickers, Uses of UIDatePicker, UIPickerView").click();
|
||||
// var pickers = yield this.elementsByTagName("picker");
|
||||
// console.log(pickers[2].elementsByTagName);
|
||||
// var wheels = yield pickers[2].elementsByTagName("pickerwheel");
|
||||
// yield wheels[0].sendKeys("Serena Auroux");
|
||||
// yield this.elementByName("Back").click();
|
||||
// yield this.elementByName("Images, Use of UIImageView").click();
|
||||
// yield this.elementByTagName("slider").sendKeys("0.8");
|
||||
// yield this.sleep(2);
|
||||
yield this.elementByClassName("UIATextField").sendKeys("Hello World!\n");
|
||||
yield this.elementByName("Back").click();
|
||||
|
||||
// todo: This part didn't work on Sauce 6.1
|
||||
// yield this.elementByName("Web, Use of UIWebView").click();
|
||||
//var handles = yield this.windowHandles();
|
||||
//yield this.windowHandle(handles[0]);
|
||||
// yield this.get("https://www.saucelabs.com");
|
||||
// yield this.execute("mobile: leaveWebView");
|
||||
// yield this.elementByName("Back").click();
|
||||
yield this.elementByName("Pickers, Uses of UIDatePicker, UIPickerView").click();
|
||||
var pickers = yield this.elementsByClassName("UIAPicker");
|
||||
/*var wheels =*/ yield pickers[0].elementsByClassName("UIAPickerWheel");
|
||||
// TODO: sendKey to picker is not working
|
||||
//yield wheels[0].sendKeys("Serena Auroux");
|
||||
yield this.elementByName("Back").click();
|
||||
|
||||
yield this.elementByName("Images, Use of UIImageView").click();
|
||||
yield this.elementByClassName("UIASlider").sendKeys("0.8");
|
||||
yield this.sleep(2);
|
||||
yield this.elementByName("Back").click();
|
||||
|
||||
yield this.elementByName("Web, Use of UIWebView").click();
|
||||
yield this.sleep(3000);
|
||||
yield this.contexts();
|
||||
yield this.context("WEBVIEW");
|
||||
yield this.get("https://www.saucelabs.com");
|
||||
yield this.context("NATIVE_APP");
|
||||
yield this.elementByName("Back").click();
|
||||
|
||||
console.log(yield this.source());
|
||||
} catch (e) {
|
||||
|
||||
@@ -55,7 +55,6 @@ browser
|
||||
.text()
|
||||
.should.eventually.include('Some@example.com')
|
||||
]);
|
||||
//console.log(elements.length);
|
||||
})
|
||||
.elementByName("Save")
|
||||
.click()
|
||||
|
||||
@@ -28,42 +28,43 @@ var desired = {
|
||||
// Default is for very slow ARM emulator
|
||||
var TIME_BASE_UNIT = parseInt(process.env.TIME_BASE_UNIT || 5000);
|
||||
|
||||
var bc = function(t) { return "//button[contains(@text, '" + t + "')]"; };
|
||||
var ec = function(t) { return "//editText[contains(@text, '" + t + "')]"; };
|
||||
var tc = function(t) { return "//text[contains(@text, '" + t + "')]"; };
|
||||
var bc = function(t) { return "//android.widget.Button[contains(@text, '" + t + "')]"; };
|
||||
var ec = "//android.widget.EditText";
|
||||
var tc = function(t) { return "//android.widget.TextView[contains(@text, '" + t + "')]"; };
|
||||
|
||||
var browser = wd.remote('localhost', 4723);
|
||||
var driver = wd.remote('localhost', 4723);
|
||||
// See whats going on
|
||||
browser.driver.on('status', function(info) {
|
||||
driver.on('status', function(info) {
|
||||
console.log(info.cyan);
|
||||
});
|
||||
browser.driver.on('command', function(meth, path, data) {
|
||||
driver.on('command', function(meth, path, data) {
|
||||
console.log(' > ' + meth.yellow, path.grey, data || '');
|
||||
});
|
||||
|
||||
var deleteUser = function(name, timeout) {
|
||||
return o_O(function*() {
|
||||
yield browser.waitForElementByXPath(tc(name), timeout).click();
|
||||
yield browser.elementByName('More options').click();
|
||||
yield browser.waitForElementByXPath(tc('Delete')).click();
|
||||
yield browser.elementByXPath(bc('OK'), TIME_BASE_UNIT).click();
|
||||
yield driver.waitForElementByXPath(tc(name), timeout).click();
|
||||
yield driver.elementByName('More options').click();
|
||||
yield driver.waitForElementByXPath(tc('Delete')).click();
|
||||
yield driver.elementByXPath(bc('OK'), TIME_BASE_UNIT).click();
|
||||
})();
|
||||
};
|
||||
|
||||
// Run the test
|
||||
browser.run(function*() {
|
||||
// Run the testå
|
||||
driver.run(function*() {
|
||||
try {
|
||||
yield this.init(desired);
|
||||
|
||||
// TODO: this sleep should not be necessary
|
||||
yield this.sleep(3000);
|
||||
// waiting for app initialization
|
||||
yield this.waitForElementByXPath(tc('contacts'), 10*TIME_BASE_UNIT);
|
||||
yield this.waitForElementByXPath(tc('Contact Manager'), 10*TIME_BASE_UNIT);
|
||||
|
||||
//try to delete contact if it is there
|
||||
try{
|
||||
yield deleteUser('John Smith', TIME_BASE_UNIT/10);
|
||||
} catch(ignore) {}
|
||||
|
||||
yield this.waitForElementByXPath(bc('Create'), 2*TIME_BASE_UNIT).click();
|
||||
yield this.waitForElementByXPath(bc('Add Contact'), 2*TIME_BASE_UNIT).click();
|
||||
|
||||
// There may be a confirmation stage
|
||||
try {
|
||||
@@ -71,21 +72,25 @@ browser.run(function*() {
|
||||
} catch(ignore) {}
|
||||
|
||||
// Adding user
|
||||
yield this.waitForElementByXPath(ec('Name'), 2*TIME_BASE_UNIT).sendKeys("John Smith");
|
||||
yield this.elementByXPath(ec('Phone')).sendKeys("(555) 555-5555");
|
||||
yield this.elementByXPath(ec('Email')).sendKeys("john.smith@google.io");
|
||||
yield this.elementByXPath(tc('Done')).click();
|
||||
|
||||
// Editing user
|
||||
yield this.waitForElementByName("Edit", TIME_BASE_UNIT*10); // superslow
|
||||
yield this.elementByName("Edit").click();
|
||||
yield this.waitForElementByXPath(bc('Add another field'), 2*TIME_BASE_UNIT).click();
|
||||
yield this.waitForElementByXPath(tc('Address'), 2*TIME_BASE_UNIT).click();
|
||||
yield this.waitForElementByXPath(ec('Address'), 2*TIME_BASE_UNIT).sendKeys("123 Appium Street");
|
||||
yield this.elementByXPath(tc('Done')).click();
|
||||
yield this.waitForElementByXPath(ec, 2*TIME_BASE_UNIT);
|
||||
var ecs = yield this.elementsByXPath(ec);
|
||||
yield ecs[0].sendKeys("John Smith");
|
||||
yield ecs[1].sendKeys("(555) 555-5555");
|
||||
yield ecs[2].sendKeys("john.smith@google.io");
|
||||
yield this.elementByXPath(bc('Save')).click();
|
||||
|
||||
// Deleting user
|
||||
yield deleteUser('John Smith', 2*TIME_BASE_UNIT);
|
||||
// TODO: The contact manager is crashing right here.
|
||||
|
||||
// // Editing user
|
||||
// yield this.waitForElementByName("Edit", TIME_BASE_UNIT*10); // superslow
|
||||
// yield this.elementByName("Edit").click();
|
||||
// yield this.waitForElementByXPath(bc('Add another field'), 2*TIME_BASE_UNIT).click();
|
||||
// yield this.waitForElementByXPath(tc('Address'), 2*TIME_BASE_UNIT).click();
|
||||
// yield this.waitForElementByXPath(ec('Address'), 2*TIME_BASE_UNIT).sendKeys("123 Appium Street");
|
||||
// yield this.elementByXPath(tc('Done')).click();
|
||||
|
||||
// // Deleting user
|
||||
// yield deleteUser('John Smith', 2*TIME_BASE_UNIT);
|
||||
} catch(e) {
|
||||
console.log(e);
|
||||
}
|
||||
|
||||
@@ -28,6 +28,7 @@ var host = "ondemand.saucelabs.com",
|
||||
var timeout = process.env.TIMEOUT || 300000;
|
||||
|
||||
var desired = {
|
||||
browserName: '',
|
||||
'appium-version': '1.0',
|
||||
platformName: 'Android',
|
||||
platformVersion: '4.3',
|
||||
@@ -67,11 +68,12 @@ describe('notes app', function() {
|
||||
browser
|
||||
.elementByName("New note")
|
||||
.click()
|
||||
.elementByTagName("textfield")
|
||||
.sleep(10000)
|
||||
.elementByClassName('android.widget.TextView')
|
||||
.sendKeys("This is a new note!")
|
||||
.elementByName("Save")
|
||||
.click()
|
||||
.elementsByTagName("text")
|
||||
.elementsByClassName("android.widget.TextView")
|
||||
.then(function(els) {
|
||||
return Q.all([
|
||||
els[2].text().should.become("This is a new note!"),
|
||||
|
||||
@@ -45,6 +45,7 @@ var timeout = process.env.TIMEOUT || 300000;
|
||||
// Browser/app config
|
||||
var appUrl = 'http://localhost:8080/TestApp6.0.app.zip';
|
||||
var desired = {
|
||||
browserName: '',
|
||||
'appium-version': '1.0',
|
||||
platformName: 'iOS',
|
||||
platformVersion: '7.1',
|
||||
@@ -96,11 +97,11 @@ describe('notes app', function() {
|
||||
})
|
||||
.elementByIosUIAutomation('.buttons()')
|
||||
.click()
|
||||
// .elementByTagName('staticText')
|
||||
// .text().then(function(text) {
|
||||
// var sum = values[0] + values[1];
|
||||
// sum.should.equal(parseInt(text, 10));
|
||||
// })
|
||||
.elementByClassName('UIAStaticText')
|
||||
.text().then(function(text) {
|
||||
var sum = values[0] + values[1];
|
||||
sum.should.equal(parseInt(text, 10));
|
||||
})
|
||||
.nodeify(done);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -29,6 +29,7 @@ var host = "ondemand.saucelabs.com",
|
||||
var timeout = process.env.TIMEOUT || 300000;
|
||||
|
||||
var desired = {
|
||||
browserName: '',
|
||||
'appium-version': '1.0',
|
||||
platformName: 'iOS',
|
||||
platformVersion: '7.1',
|
||||
@@ -79,11 +80,11 @@ describe('notes app', function() {
|
||||
})
|
||||
.elementByIosUIAutomation('.buttons()')
|
||||
.click()
|
||||
// .elementByTagName('staticText')
|
||||
// .text().then(function(text) {
|
||||
// var sum = values[0] + values[1];
|
||||
// sum.should.equal(parseInt(text, 10));
|
||||
// })
|
||||
.elementByClassName('UIAStaticText')
|
||||
.text().then(function(text) {
|
||||
var sum = values[0] + values[1];
|
||||
sum.should.equal(parseInt(text, 10));
|
||||
})
|
||||
.nodeify(done);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user