mirror of
https://github.com/appium/appium.git
synced 2026-02-10 11:59:45 -06:00
added/fixed doc js sample code.
This commit is contained in:
@@ -40,7 +40,7 @@ driver.lockScreen(3);
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.lock(3)
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -68,7 +68,7 @@ driver.runAppInBackground(5);
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.backgroundApp(5)
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -96,7 +96,7 @@ driver.hideKeyboard();
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.hideKeyboard()
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -125,7 +125,8 @@ driver.isAppInstalled("com.example.android.apis")
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.isAppInstalled("com.example.android.apis")
|
||||
.then(function (isAppInstalled) { /*...*/ })
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -153,7 +154,7 @@ driver.installApp("path/to/my.apk")
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.installApp("path/to/my.apk")
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -181,7 +182,7 @@ driver.removeApp("com.example.android.apis")
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.removeApp("com.example.android.apis")
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -209,7 +210,7 @@ driver.shake()
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.shake()
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -237,7 +238,7 @@ driver.closeApp()
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.closeApp()
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -265,7 +266,7 @@ driver.launchApp()
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.launchApp()
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -293,7 +294,7 @@ driver.resetApp()
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.resetApp()
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -321,7 +322,7 @@ driver.getContextHandles()
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.contexts().then(function (contexts) { /*...*/ })
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -350,7 +351,7 @@ driver.getContext()
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.currentContext().then(function (context) { /*...*/ })
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -378,7 +379,7 @@ driver.context();
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.context()
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -406,7 +407,7 @@ driver.getAppString();
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.getAppStrings().then(function (appStrings) { /*...*/ })
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -435,7 +436,7 @@ driver.sendKeyEvent(AndroidKeyCode.HOME);
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.deviceKeyEvent(wd.SPECIAL_KEYS.Home)
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -463,7 +464,7 @@ driver.currentActivity();
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.getCurrentActivity().then(function (activity) { /*...*/ })
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -498,7 +499,11 @@ perform();
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
var action = new wd.TouchAction(driver);
|
||||
action
|
||||
.tap({el: el, x: 10, y: 10})
|
||||
.release();
|
||||
return action.perform(); // returns a promise
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -528,13 +533,9 @@ $multiAction->perform();
|
||||
```
|
||||
|
||||
```csharp
|
||||
var touchAction1 = new TouchActions(this);
|
||||
touchAction1.Down(10, 10).Up(10, 10);
|
||||
|
||||
var multiTouchAction = new MultiTouchAction(this);
|
||||
multiTouchAction.Add(touchAction1);
|
||||
|
||||
PerformMultiTouchAction(multiTouchAction);
|
||||
ITouchAction action = new TouchAction(driver);
|
||||
action.Press(el, 10, 10).Release();
|
||||
action.Perform ();
|
||||
```
|
||||
|
||||
## Swipe
|
||||
@@ -554,7 +555,19 @@ driver.swipe(startx=75, starty=500, endx=75, endy=0, duration=800)
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
function swipe(opts) {
|
||||
var action = new wd.TouchAction(this);
|
||||
action
|
||||
.press({x: opts.startX, y: opts.startY})
|
||||
.wait(opts.duration)
|
||||
.moveTo({x: opts.endX, y: opts.endY})
|
||||
.release();
|
||||
return action.perform();
|
||||
}
|
||||
wd.addPromiseChainMethod('swipe', swipe);
|
||||
// ...
|
||||
return driver.swipe({ startX: 75, startY: 500,
|
||||
endX: 75, endY: 0, duration: 800 });
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -582,7 +595,34 @@ driver.pinch(element);
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
function pinch(el) {
|
||||
return Q.all([
|
||||
el.getSize(),
|
||||
el.getLocation(),
|
||||
]).then(function(res) {
|
||||
var size = res[0];
|
||||
var loc = res[1];
|
||||
var center = {
|
||||
x: loc.x + size.width / 2,
|
||||
y: loc.y + size.height / 2
|
||||
};
|
||||
var a1 = new wd.TouchAction(this);
|
||||
a1.press({el: el, x: center.x, y:center.y - 100}).moveTo({el: el}).release();
|
||||
var a2 = new wd.TouchAction(this);
|
||||
a2.press({el: el, x: center.x, y: center.y + 100}).moveTo({el: el}).release();
|
||||
var m = new wd.MultiAction(this);
|
||||
m.add(a1, a2);
|
||||
return m.perform();
|
||||
}.bind(this));
|
||||
};
|
||||
wd.addPromiseChainMethod('pinch', pinch);
|
||||
wd.addElementPromiseChainMethod('pinch', function() {
|
||||
return this.browser.pinch(this);
|
||||
});
|
||||
// ...
|
||||
return driver.pinch(el);
|
||||
// ...
|
||||
return el.pinch();
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -610,7 +650,34 @@ driver.zoom(element);
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
function zoom(el) {
|
||||
return Q.all([
|
||||
this.getWindowSize(),
|
||||
this.getLocation(el),
|
||||
]).then(function(res) {
|
||||
var size = res[0];
|
||||
var loc = res[1];
|
||||
var center = {
|
||||
x: loc.x + size.width / 2,
|
||||
y: loc.y + size.height / 2
|
||||
};
|
||||
var a1 = new wd.TouchAction(this);
|
||||
a1.press({el: el}).moveTo({el: el, x: center.x, y: center.y - 100}).release();
|
||||
var a2 = new wd.TouchAction(this);
|
||||
a2.press({el: el}).moveTo({el: el, x: center.x, y: center.y + 100}).release();
|
||||
var m = new wd.MultiAction(this);
|
||||
m.add(a1, a2);
|
||||
return m.perform();
|
||||
}.bind(this));
|
||||
};
|
||||
wd.addPromiseChainMethod('zoom', zoom);
|
||||
wd.addElementPromiseChainMethod('zoom', function() {
|
||||
return this.browser.zoom(this);
|
||||
});
|
||||
// ...
|
||||
return driver.zoom(el);
|
||||
// ...
|
||||
return el.zoom();
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -671,7 +738,8 @@ driver.pullFile("Library/AddressBook/AddressBook.sqlitedb");
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.pullFile("Library/AddressBook/AddressBook.sqlitedb")
|
||||
.then(function (base64File) { /*...*/ })
|
||||
```
|
||||
|
||||
```php
|
||||
@@ -705,7 +773,7 @@ driver.pushFile(path, data)
|
||||
```
|
||||
|
||||
```javascript
|
||||
todo: javascript
|
||||
driver.pushFile(path, data)
|
||||
```
|
||||
|
||||
```php
|
||||
|
||||
@@ -76,26 +76,22 @@ part of iOS 6** and was not available previously.
|
||||
|
||||
* We're working on filling out the methods available in web view contexts. [Join us in our quest!](http://appium.io/get-involved.html)
|
||||
|
||||
```js
|
||||
// assuming we have an initialized `driver` object working on the UICatalog app
|
||||
driver.elementByName('Web, Use of UIWebView', function(err, el) { // find button to nav to view
|
||||
el.click(function(err) { // nav to UIWebView
|
||||
driver.contexts(function(err, contexts) { // get list of available views
|
||||
driver.context(contexts[1], function(err) { // choose what is probably the webview context
|
||||
driver.elementsByCss('.some-class', function(err, els) { // get webpage elements by css
|
||||
els.length.should.be.above(0); // there should be some!
|
||||
els[0].text(function(elText) { // get text of the first element
|
||||
elText.should.eql("My very own text"); // it should be extremely personal and awesome
|
||||
driver.context('NATIVE_APP', function(err) { // leave webview context
|
||||
// do more native stuff here if we want
|
||||
driver.quit(); // stop webdrivage
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
```javascript
|
||||
// assuming we have an initialized `driver` object working on the UICatalog app
|
||||
return driver
|
||||
.elementByName('Web, Use of UIWebView') // find button to nav to view
|
||||
.click() // nav to UIWebView
|
||||
.contexts().then(function (contexts) { // get list of available views
|
||||
return driver.context(contexts[1]); // choose what is probably the webview context
|
||||
}).elementsByCss('.some-class').then(function (els) { // get webpage elements by css
|
||||
els.length.should.be.above(0); // there should be some!
|
||||
return els[0];
|
||||
}).text() // get text of the first element
|
||||
.should.become("My very own text") // it should be extremely personal and awesome
|
||||
.context('NATIVE_APP') // leave webview context
|
||||
// do more native stuff here if we want
|
||||
.quit() // stop webdrivage
|
||||
.done(); // end promise chain (may not be needed)
|
||||
```
|
||||
|
||||
```java
|
||||
@@ -230,20 +226,19 @@ switching contexts, etc...
|
||||
Make sure
|
||||
[setWebContentsDebuggingEnabled](http://developer.android.com/reference/android/webkit/WebView.html#setWebContentsDebuggingEnabled(boolean)) is set to true as described in the [remote debugging docs](https://developer.chrome.com/devtools/docs/remote-debugging#configure-webview).
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// assuming we have an initialized `driver` object working on a hybrid app
|
||||
driver.context("WEBVIEW", function(err) { // choose the only available view
|
||||
driver.elementsByCss('.some-class', function(err, els) { // get webpage elements by css
|
||||
return driver
|
||||
.context("WEBVIEW") // choose the only available view
|
||||
.elementsByCss('.some-class').then(function (els) { // get webpage elements by css
|
||||
els.length.should.be.above(0); // there should be some!
|
||||
els[0].text(function(elText) { // get text of the first element
|
||||
elText.should.eql("My very own text"); // it should be extremely personal and awesome
|
||||
driver.context("NATIVE_APP", function(err) { // leave webview context
|
||||
// do more native stuff here if we want
|
||||
driver.quit(); // stop webdrivage
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
return els[0];
|
||||
}).text() // get text of the first element
|
||||
.should.become("My very own text") // it should be extremely personal and awesome
|
||||
.context("NATIVE_APP") // leave webview context
|
||||
// do more native stuff here if we want
|
||||
.quit() // stop webdrivage
|
||||
.done(); // end promise chain (may not be needed)
|
||||
```
|
||||
|
||||
```java
|
||||
|
||||
@@ -87,12 +87,20 @@ driver.contexts
|
||||
current = driver.context
|
||||
```
|
||||
|
||||
```javascript
|
||||
driver.contexts().then(function (contexts) { /*...*/ })
|
||||
```
|
||||
|
||||
And to switch between them, you use
|
||||
|
||||
```python
|
||||
driver.switch_to.context("WEBVIEW")
|
||||
```
|
||||
|
||||
```javascript
|
||||
driver.currentContext().then(function (context) { /*...*/ })
|
||||
```
|
||||
|
||||
## No more `execute_script("mobile: xxx")`
|
||||
|
||||
All the `mobile: ` methods have been removed, and have been replaced by native methods in the Appium client libraries. This means that a method call like `driver.execute("mobile: lock", [5])` will now look something more like `driver.lock(5)` (where `lock` has been turned into a native client method). Of course, the details on calling these methods will differ by client.
|
||||
|
||||
@@ -15,7 +15,7 @@ attempting to use Appium.
|
||||
|
||||
Then, use desired capabilities like these to run your test in mobile Safari:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
{
|
||||
platformName: 'iOS'
|
||||
, platformVersion: '7.1'
|
||||
@@ -180,7 +180,7 @@ Pre-requisites:
|
||||
|
||||
Then, use desired capabilities like these to run your test in Chrome:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
{
|
||||
platformName: 'Android'
|
||||
, platformVersion: '4.4'
|
||||
|
||||
@@ -20,7 +20,7 @@ connection API for iOS.
|
||||
Choose the setting you would like to use, and then send the correct bitmask from
|
||||
the table above.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// set airplane mode
|
||||
driver.setNetworkConnection(1)
|
||||
|
||||
@@ -37,23 +37,24 @@ driver.setNetworkConnection(6)
|
||||
Retrieving the network connection settings returns the same bitmask, from which
|
||||
the status can be decoded.
|
||||
|
||||
```js
|
||||
var connectionType = driver.getNetworkConnection();
|
||||
switch (connectionType) {
|
||||
case 0:
|
||||
// no network connection
|
||||
break;
|
||||
case 1:
|
||||
// airplane mode
|
||||
break;
|
||||
case 2:
|
||||
// wifi
|
||||
break;
|
||||
case 4:
|
||||
// data
|
||||
break;
|
||||
case 6:
|
||||
// wifi and data
|
||||
break;
|
||||
}
|
||||
```javascript
|
||||
driver.getNetworkConnection().then(function (connectionType) {
|
||||
switch (connectionType) {
|
||||
case 0:
|
||||
// no network connection
|
||||
break;
|
||||
case 1:
|
||||
// airplane mode
|
||||
break;
|
||||
case 2:
|
||||
// wifi
|
||||
break;
|
||||
case 4:
|
||||
// data
|
||||
break;
|
||||
case 6:
|
||||
// wifi and data
|
||||
break;
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
@@ -31,7 +31,7 @@ Basically, first make sure Appium is running:
|
||||
|
||||
Then script your WebDriver test, sending in the following desired capabilities:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
{
|
||||
platformName: 'iOS',
|
||||
platformVersion: '7.1',
|
||||
@@ -106,7 +106,7 @@ Now, make sure Appium is running:
|
||||
|
||||
Then script your WebDriver test, sending in the following desired capabilities:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
{
|
||||
platformName: 'Android',
|
||||
platformVersion: '4.4',
|
||||
@@ -168,7 +168,7 @@ To use Selendroid, all that is required is to slightly change the set of
|
||||
desired capabilities mentioned above, by adding the `automationName` capability
|
||||
and specifying the Selendroid automation backend.
|
||||
|
||||
```js
|
||||
```javascript
|
||||
{
|
||||
automationName: 'Selendroid',
|
||||
platformName: 'Android',
|
||||
|
||||
@@ -49,28 +49,28 @@ automatic linting.
|
||||
* Use two spaces for indentation, *no tabs*
|
||||
* Use single spaces around operators
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var x = 1;
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
var x=1;
|
||||
```
|
||||
|
||||
* Spaces after commas and colons in lists, objects, function calls, etc...
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var x = myFunc("lol", {foo: bar, baz: boo});
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
var x = myFunc("lol",{foo:bar,baz:boo});
|
||||
```
|
||||
|
||||
* Always end statements with semicolons
|
||||
* Comma-first
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var x = {
|
||||
foo: 'bar'
|
||||
, baz: 'boo'
|
||||
@@ -80,7 +80,7 @@ automatic linting.
|
||||
|
||||
* Brackets for `function`, `if`, etc... go on same line, `else` gets sandwiched
|
||||
|
||||
```js
|
||||
```javascript
|
||||
if (foo === bar) {
|
||||
// do something
|
||||
} else {
|
||||
@@ -90,35 +90,35 @@ automatic linting.
|
||||
|
||||
* Space after `if`, `for`, and `function`:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
if (foo === bar) {
|
||||
```
|
||||
```js
|
||||
```javascript
|
||||
for (var i = 0; i < 10; i ++) {
|
||||
```
|
||||
```js
|
||||
```javascript
|
||||
var lol = function (foo) {
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
if(foo === bar) {
|
||||
```
|
||||
```js
|
||||
```javascript
|
||||
for(var i = 0; i < 10; i ++) {
|
||||
```
|
||||
```js
|
||||
```javascript
|
||||
var lol = function(foo) {
|
||||
```
|
||||
|
||||
* Avoid bracketless `if` for one-liners:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
if (foo === bar) {
|
||||
foo++;
|
||||
}
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
if (foo === bar)
|
||||
foo++;
|
||||
```
|
||||
@@ -127,21 +127,21 @@ automatic linting.
|
||||
* Line length shouldn't be longer than 79 characters
|
||||
* Break up long strings like this:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
myFunc("This is a really long string that's longer " +
|
||||
"than 79 characters so I broke it up, woo");
|
||||
```
|
||||
|
||||
* Comments should line up with code
|
||||
|
||||
```js
|
||||
```javascript
|
||||
if (foo === 5) {
|
||||
myFunc(foo);
|
||||
// foo++;
|
||||
}
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
if (foo === 5) {
|
||||
myFunc(foo);
|
||||
//foo++;
|
||||
@@ -150,7 +150,7 @@ automatic linting.
|
||||
|
||||
* Subclassing by extending prototypes
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var _ = require('underscore');
|
||||
|
||||
var SuperClass = function () {
|
||||
@@ -172,7 +172,7 @@ automatic linting.
|
||||
|
||||
* Callbacks are always last in function definitions
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var foo = function (arg1, arg2, cb) {
|
||||
...
|
||||
};
|
||||
@@ -180,31 +180,31 @@ automatic linting.
|
||||
|
||||
* Define functions as variables
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var myFunc = function (a, b, c) {};
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
function myFunc (a, b, c) {}
|
||||
```
|
||||
|
||||
* Variable names should be camelCased:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
var myVariable = 42;
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
var my_variable = 42;
|
||||
```
|
||||
|
||||
* Check for undefined
|
||||
|
||||
```js
|
||||
```javascript
|
||||
typeof myVariable === "undefined"
|
||||
```
|
||||
not
|
||||
```js
|
||||
```javascript
|
||||
myVariable === undefined
|
||||
```
|
||||
|
||||
@@ -214,7 +214,7 @@ Keep on the same line if it makes sense semantically and length is not an issue:
|
||||
|
||||
Examples:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
driver.elementByTagName('el1').should.become("123")
|
||||
.nodeify(done);
|
||||
|
||||
@@ -225,7 +225,7 @@ Examples:
|
||||
|
||||
Alternatively use extra indents to improve readability:
|
||||
|
||||
```js
|
||||
```javascript
|
||||
h.driver
|
||||
.elementById('comments')
|
||||
.clear()
|
||||
|
||||
@@ -105,11 +105,10 @@ See examples below:
|
||||
|
||||
* **WD.js:**
|
||||
|
||||
```js
|
||||
```javascript
|
||||
// scroll the view down
|
||||
driver.execute("mobile: scroll", [{direction: 'down'}], function(err) {
|
||||
driver.execute("mobile: scroll", [{direction: 'down'}])
|
||||
// continue testing
|
||||
});
|
||||
```
|
||||
|
||||
* **Java:**
|
||||
|
||||
Reference in New Issue
Block a user