* 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 коммит произвёл GitHub
Родитель aab1649996
Коммит 04f6543561
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
68 изменённых файлов: 2098 добавлений и 27 удалений

2
.github/ISSUE_TEMPLATE.md поставляемый
Просмотреть файл

@ -27,6 +27,6 @@ If you are reporting a bug, _always_ include Appium logs!
Please remember that with sample code it's easier to reproduce the bug and it's much faster to fix it.
Please git clone https://github.com/appium/sample-code and use one of your favourite languages and sample apps to reproduce the issue.
Please git clone https://github.com/appium/appium and from the `sample-code` directory, use one of your favourite languages and sample apps to reproduce the issue.
In case a similar scenario is missing in sample-code, please submit a PR with one of the sample apps provided.

7
.gitignore поставляемый
Просмотреть файл

@ -3,14 +3,15 @@
.DS_Store
node_modules
package-lock.json
sample-code
*.trace
xcuserdata
*.sublime-*
test/functional/_joined
*.iml
!sample-code/java/*.iml
*.autosave
.idea/
!sample-code/java/.idea/
*.log
*.t
artifacts
@ -34,3 +35,7 @@ old
.tern-project
coverage
docs/mkdocs.yml
sample-code/javascript-wd/node_modules
sample-code/php/vendor
sample-code/php/composer.lock
sample-code/java/out/

Просмотреть файл

@ -18,3 +18,6 @@ _vimrc_local.vim
*.trace
*.sublime-
*.prefs
./.npmignore
coverage
sample-code/

Просмотреть файл

@ -79,8 +79,8 @@ Node.js 6+.
Check out our [Getting Started](/docs/en/about-appium/getting-started.md) guide
to get going with Appium.
There is also a repository that contains [many examples of tests in a variety
of different languages](https://github.com/appium/sample-code)!
There is also sample code that contains [many examples of tests in a variety
of different languages](https://github.com/appium/appium/sample-code)!
### Documentation

Просмотреть файл

@ -45,11 +45,11 @@ the Android SDK configured on your system.
At some point, make sure you review the driver documentation for the platform
you want to automate, so your system is set up correctly:
* The [XCUITest Driver](/docs/en/drivers/ios-xcuitest.md) (for iOS apps)
* The [UiAutomator2 Driver](/docs/en/drivers/android-uiautomator2.md) (for Android apps)
* The [Windows Driver](/docs/en/drivers/windows.md) (for Windows Desktop apps)
* The [Mac Driver](/docs/en/drivers/mac.md) (for Mac Desktop apps)
* (BETA) The [Espresso Driver](/docs/en/drivers/android-espresso.md) (for Android apps)
- The [XCUITest Driver](/docs/en/drivers/ios-xcuitest.md) (for iOS apps)
- The [UiAutomator2 Driver](/docs/en/drivers/android-uiautomator2.md) (for Android apps)
- The [Windows Driver](/docs/en/drivers/windows.md) (for Windows Desktop apps)
- The [Mac Driver](/docs/en/drivers/mac.md) (for Mac Desktop apps)
- (BETA) The [Espresso Driver](/docs/en/drivers/android-espresso.md) (for Android apps)
### Verifying the Installation
@ -113,16 +113,16 @@ additional dependencies.
(Chances are, you'll eventually want to automate something other than Android
using something other than JavaScript. In that case, check out our
[sample-code](https://github.com/appium/sample-code) repository, which has code
[sample-code](https://github.com/appium/appium/sample-code), which has code
samples for many languages and platforms.)
#### Prerequisites
* We'll assume you have an Android 8.0 emulator configured and running (the
- We'll assume you have an Android 8.0 emulator configured and running (the
example will work on lower versions, just fix the version numbers
accordingly)
* We'll assume you have [this test
APK](https://github.com/appium/sample-code/blob/master/sample-code/apps/ApiDemos/bin/ApiDemos-debug.apk)
- We'll assume you have [this test
APK](https://github.com/appium/appium/raw/master/sample-code/apps/ApiDemos-debug.apk)
downloaded and available on your local filesystem
#### Setting up the Appium Client
@ -141,7 +141,7 @@ client object:
```js
// javascript
const wdio = require('webdriverio');
const wdio = require("webdriverio");
```
The next thing we need to do is to start an Appium session. We do this by
@ -151,12 +151,12 @@ values that get sent to the Appium server during session initialization, that
tell Appium what kind of thing we want to automate. The minimum set of required
capabilities for any Appium driver should include:
* `platformName`: the name of the platform to automate
* `platformVersion`: the version of the platform to automate
* `deviceName`: the kind of device to automate
* `app`: the path to the app you want to automate (but use the `browserName`
- `platformName`: the name of the platform to automate
- `platformVersion`: the version of the platform to automate
- `deviceName`: the kind of device to automate
- `app`: the path to the app you want to automate (but use the `browserName`
capability instead in the case of automating a web browser)
* `automationName`: the name of the driver you wish to use
- `automationName`: the name of the driver you wish to use
For more information on Desired Capabilities and for a list of all the
Capabilities you can use in Appium, see our [Capabilities
@ -191,7 +191,6 @@ session, perform some test commands, and end the session. In our case, we will
simply tap into a few menus and then back out the way we came before ending the
session:
```js
// javascript
client
@ -217,7 +216,7 @@ Putting it all together, the file should look like:
```js
// javascript
const wdio = require('webdriverio');
const wdio = require("webdriverio");
const opts = {
port: 4723,
@ -251,7 +250,8 @@ behaving as if an invisible user were tapping on it!
We've only scratched the surface of what you can do with Appium. Check out
these resources to help you on your journey:
* The Appium [command reference](http://appium.io/docs/en/commands/status/) - learn about what commands are available, how to use them with specific client libraries, etc...
* The [sample-code](https://github.com/appium/sample-code) repository, where lots more code samples are available
* [discuss.appium.io](https://discuss.appium.io) - this is the Appium community forum, which is a great first place to go for help getting started, or if you think you may have run into a bug
* The Appium [issue tracker](https://github.com/appium/appium/issues) - let the Appium maintainers know here if you think you've found a bug
- The Appium [command reference](https://appium.io/docs/en/commands/status/) - learn about what commands are available, how to use them with specific client libraries, etc...
- The [sample-code](https://github.com/appium/appium/sample-code) repository, where lots more code samples are available
- [discuss.appium.io](https://discuss.appium.io) - this is the Appium community forum, which is a great first place to go for help getting started, or if you think you may have run into a bug
- The Appium [issue tracker](https://github.com/appium/appium/issues) - let the Appium maintainers know here if you think you've found a bug

Просмотреть файл

@ -27,7 +27,7 @@ Nothing in particular needs to be done to run your test.
The best way to see what to do currently is to look at the example tests:
[Node.js](https://github.com/appium/sample-code/tree/master/sample-code/examples/node) | [Python](https://github.com/appium/sample-code/tree/master/sample-code/examples/python) | [PHP](https://github.com/appium/sample-code/tree/master/sample-code/examples/php) | [Ruby](https://github.com/appium/sample-code/tree/master/sample-code/examples/ruby) | [Java](https://github.com/appium/sample-code/tree/master/sample-code/examples/java)
[Node.js](https://github.com/appium/appium/tree/master/sample-code/javascript-webdriverio) | [Python](https://github.com/appium/appium/tree/master/sample-code/python) | [PHP](https://github.com/appium/appium/tree/master/sample-code/php) | [Ruby](https://github.com/appium/appium/tree/master/sample-code/ruby) | [Java](https://github.com/appium/appium/tree/master/sample-code/java)
Basically, first make sure Appium is running:

17
sample-code/README.md Normal file
Просмотреть файл

@ -0,0 +1,17 @@
# Sample Code
Sample Appium code written in multiple client languages
## Running sample code
* Follow the [Appium setup guide](https://github.com/appium/appium/blob/master/docs/en/about-appium/getting-started.md) to install Appium locally.
* Choose the client library that you wish to run and then follow the guide in `sample-code/<client-language>/README.md` (e.g.: `sample-code/java/README.md`)
## Environment variables
* `DEV`: If set to true, runs apps that are downloaded from GitHub, otherwise runs apps that are in local directory
* `IOS_DEVICE_NAME`: Sets the `deviceName` capability for iOS. Otherwise uses some default
* `IOS_PLATFORM_VERSION`: Sets the `platformVersion` capability for iOS. Otherwise uses some default
* `ANDROID_DEVICE_NAME`: Sets the `deviceName` capability for Android. Otherwise uses some default
* `ANDROID_PLATFORM_VERSION`: Sets the `platformVersion` capability for Android. Otherwise uses some default
* `SAUCE_LABS`: If set to true, runs tests on Sauce Labs. Requires being setup on SauceLabs to run these tests.

Двоичные данные
sample-code/apps/ApiDemos-debug.apk Normal file

Двоичный файл не отображается.

Двоичные данные
sample-code/apps/TestApp.app.zip Normal file

Двоичный файл не отображается.

Просмотреть файл

Просмотреть файл

@ -0,0 +1,9 @@
# Java Sample Code
## Setup
* Uses TestNG and was built and tested on IntelliJ
## Running Tests
* Can be run from IntelliJ the way tests normally are run

32
sample-code/java/java.iml Normal file
Просмотреть файл

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module-library" scope="TEST">
<library name="testng">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/testng.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/jcommander.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="module-library">
<library>
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/testng.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/plugins/testng/lib/jcommander.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
<orderEntry type="library" name="io.appium:java-client:5.0.4" level="project" />
</component>
</module>

Просмотреть файл

@ -0,0 +1,71 @@
import io.appium.java_client.android.Activity;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import java.io.File;
import java.io.IOException;
public class AndroidBasicInteractionsTest extends BaseTest {
private AndroidDriver<WebElement> driver;
private final String SEARCH_ACTIVITY = ".app.SearchInvoke";
private final String ALERT_DIALOG_ACTIVITY = ".app.AlertDialogSamples";
private final String PACKAGE = "io.appium.android.apis";
@BeforeClass
public void setUp() throws IOException {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("app", app.getAbsolutePath());
driver = new AndroidDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterClass
public void tearDown() {
driver.quit();
}
@Test()
public void testSendKeys() {
driver.startActivity(new Activity(PACKAGE, SEARCH_ACTIVITY));
AndroidElement searchBoxEl = (AndroidElement) driver.findElementById("txt_query_prefill");
searchBoxEl.sendKeys("Hello world!");
AndroidElement onSearchRequestedBtn = (AndroidElement) driver.findElementById("btn_start_search");
onSearchRequestedBtn.click();
AndroidElement searchText = (AndroidElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.visibilityOfElementLocated(By.id("android:id/search_src_text")));
String searchTextValue = searchText.getText();
Assert.assertEquals(searchTextValue, "Hello world!");
}
@Test
public void testOpensAlert() {
// Open the "Alert Dialog" activity of the android app
driver.startActivity(new Activity(PACKAGE, ALERT_DIALOG_ACTIVITY));
// Click button that opens a dialog
AndroidElement openDialogButton = (AndroidElement) driver.findElementById("io.appium.android.apis:id/two_buttons");
openDialogButton.click();
// Check that the dialog is there
AndroidElement alertElement = (AndroidElement) driver.findElementById("android:id/alertTitle");
String alertText = alertElement.getText();
Assert.assertEquals(alertText, "Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.");
AndroidElement closeDialogButton = (AndroidElement) driver.findElementById("android:id/button1");
// Close the dialog
closeDialogButton.click();
}
}

Просмотреть файл

@ -0,0 +1,37 @@
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.*;
import java.io.File;
public class AndroidCreateSessionTest extends BaseTest {
private AndroidDriver<WebElement> driver;
@BeforeClass
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterClass
public void tearDown() {
driver.quit();
}
@Test()
public void testCreateSession() {
String activity = driver.currentActivity();
String pkg = driver.getCurrentPackage();
Assert.assertEquals(activity, ".ApiDemos");
Assert.assertEquals(pkg, "io.appium.android.apis");
}
}

Просмотреть файл

@ -0,0 +1,32 @@
import io.appium.java_client.android.AndroidDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.*;
import java.net.URI;
import java.net.URISyntaxException;
public class AndroidCreateWebSessionTest extends BaseTest {
private AndroidDriver<WebElement> driver;
@BeforeClass
public void setUp() {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("browserName", "Chrome");
driver = new AndroidDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterClass
public void tearDown() {
driver.quit();
}
@Test()
public void testCreateWebSession() throws URISyntaxException {
driver.get(new URI("http://www.google.com").toString());
String title = driver.getTitle();
Assert.assertEquals(title, "Google");
}
}

Просмотреть файл

@ -0,0 +1,64 @@
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.File;
import java.util.List;
public class AndroidSelectorsTest extends BaseTest {
private AndroidDriver<WebElement> driver;
private static AppiumDriverLocalService service;
private final String PACKAGE = "io.appium.android.apis";
@BeforeSuite
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "ApiDemos-debug.apk");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Android Emulator");
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("appPackage", "io.appium.android.apis");
capabilities.setCapability("appActivity", ".ApiDemos");
driver = new AndroidDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterSuite
public void tearDown() {
driver.quit();
}
@Test
public void testFindElementsByAccessibilityId () {
// Look for element by accessibility. In Android this is the "content-desc"
List<WebElement> searchParametersElement = (List<WebElement>) driver.findElementsByAccessibilityId("Content");
Assert.assertEquals(searchParametersElement.size(), 1);
}
@Test
public void testFindElementsById () {
// Look for element by ID. In Android this is the "resource-id"
List<WebElement> actionBarContainerElements = (List<WebElement>) driver.findElementsById("android:id/action_bar_container");
Assert.assertEquals(actionBarContainerElements.size(), 1);
}
@Test
public void testFindElementsByClassName () {
// Look for elements by the class name. In Android this is the Java Class Name of the view.
List<WebElement> linearLayoutElements = (List<WebElement>) driver.findElementsByClassName("android.widget.FrameLayout");
Assert.assertTrue(linearLayoutElements.size() > 1);
};
@Test
public void testFindElementsByXPath () {
// Find elements by XPath
List<WebElement> linearLayoutElements = (List<WebElement>) driver.findElementsByXPath("//*[@class=\"android.widget.FrameLayout\"]");
Assert.assertTrue(linearLayoutElements.size() > 1);
};
}

Просмотреть файл

@ -0,0 +1,27 @@
import io.appium.java_client.service.local.AppiumDriverLocalService;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import java.io.IOException;
import java.net.URL;
public abstract class BaseTest {
private static AppiumDriverLocalService service;
@BeforeSuite
public void globalSetup () throws IOException {
service = AppiumDriverLocalService.buildDefaultService();
service.start();
}
@AfterSuite
public void globalTearDown () {
service.stop();
}
public URL getServiceUrl () {
return service.getUrl();
}
}

Просмотреть файл

@ -0,0 +1,79 @@
import io.appium.java_client.MobileBy;
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.*;
import java.io.File;
import java.io.IOException;
public class IOSBasicInteractionsTest extends BaseTest {
private IOSDriver<WebElement> driver;
@BeforeTest
public void setUp() throws IOException {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "TestApp.app.zip");
String deviceName = System.getenv("IOS_DEVICE_NAME");
String platformVersion = System.getenv("IOS_PLATFORM_VERSION");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", deviceName == null ? "iPhone 6s" : deviceName);
capabilities.setCapability("platformVerison", platformVersion == null ? "11.1" : platformVersion);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("automationName", "XCUITest");
driver = new IOSDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterTest
public void tearDown() {
driver.quit();
}
@Test
public void testSendKeysToInput () {
// Find TextField input element
String textInputId = "TextField1";
IOSElement textViewsEl = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId(textInputId)));
// Check that it doesn"t have a value
String value = textViewsEl.getAttribute("value");
Assert.assertEquals(value, null);
// Send keys to that input
textViewsEl.sendKeys("Hello World!");
// Check that the input has new value
value = textViewsEl.getAttribute("value");
Assert.assertEquals(value, "Hello World!");
}
@Test
public void testOpenAlert () {
// Find Button element and click on it
String buttonElementId = "show alert";
IOSElement buttonElement = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId(buttonElementId)));
buttonElement.click();
// Wait for the alert to show up
String alertTitleId = "Cool title";
IOSElement alertTitleElement = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId(alertTitleId)));
// Check the text
String alertTitle = alertTitleElement.getText();
Assert.assertEquals(alertTitle, "Cool title");
// Dismiss the alert
IOSElement okButtonElement = (IOSElement) new WebDriverWait(driver, 30)
.until(ExpectedConditions.visibilityOfElementLocated(MobileBy.AccessibilityId("OK")));
okButtonElement.click();
}
}

Просмотреть файл

@ -0,0 +1,43 @@
import io.appium.java_client.ios.IOSDriver;
import io.appium.java_client.ios.IOSElement;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.File;
public class IOSCreateSessionTest extends BaseTest {
private IOSDriver<WebElement> driver;
@BeforeSuite
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "TestApp.app.zip");
String deviceName = System.getenv("IOS_DEVICE_NAME");
String platformVersion = System.getenv("IOS_PLATFORM_VERSION");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", deviceName == null ? "iPhone 6s" : deviceName);
capabilities.setCapability("platformVerison", platformVersion == null ? "11.1" : platformVersion);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("automationName", "XCUITest");
driver = new IOSDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterSuite
public void tearDown() {
driver.quit();
}
@Test
public void testCreateSession () {
// Check that the XCUIElementTypeApplication was what we expect it to be
IOSElement applicationElement = (IOSElement) driver.findElementByClassName("XCUIElementTypeApplication");
String applicationName = applicationElement.getAttribute("name");
Assert.assertEquals(applicationName, "TestApp");
}
}

Просмотреть файл

@ -0,0 +1,41 @@
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.IOException;
public class IOSCreateWebSessionTest extends BaseTest {
private IOSDriver<WebElement> driver;
@BeforeSuite
public void setUp() throws IOException {
String deviceName = System.getenv("IOS_DEVICE_NAME");
String platformVersion = System.getenv("IOS_PLATFORM_VERSION");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", deviceName == null ? "iPhone 6s" : deviceName);
capabilities.setCapability("platformVerison", platformVersion == null ? "11.1" : platformVersion);
capabilities.setCapability("browserName", "Safari");
capabilities.setCapability("automationName", "XCUITest");
driver = new IOSDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterSuite
public void tearDown() {
driver.quit();
}
@Test()
public void testCreateSafariSession() {
// Navigate to google.com
driver.get("https://www.google.com");
// Test that it was successful by checking the document title
String pageTitle = driver.getTitle();
Assert.assertEquals(pageTitle, "Google");
}
}

Просмотреть файл

@ -0,0 +1,72 @@
import io.appium.java_client.ios.IOSDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.Assert;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;
import java.io.File;
import java.util.List;
public class IOSSelectorsTest extends BaseTest {
private IOSDriver<WebElement> driver;
@BeforeSuite
public void setUp() throws Exception {
File classpathRoot = new File(System.getProperty("user.dir"));
File appDir = new File(classpathRoot, "../apps");
File app = new File(appDir.getCanonicalPath(), "TestApp.app.zip");
String deviceName = System.getenv("IOS_DEVICE_NAME");
String platformVersion = System.getenv("IOS_PLATFORM_VERSION");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", deviceName == null ? "iPhone 6s" : deviceName);
capabilities.setCapability("platformVerison", platformVersion == null ? "11.1" : platformVersion);
capabilities.setCapability("app", app.getAbsolutePath());
capabilities.setCapability("automationName", "XCUITest");
driver = new IOSDriver<WebElement>(getServiceUrl(), capabilities);
}
@AfterSuite
public void tearDown() {
driver.quit();
}
@Test
public void testFindElementsByAccessibilityID () {
// This finds elements by "accessibility id", which in the case of IOS is the "name" attribute of the element
List<WebElement> computeSumButtons = driver.findElementsByAccessibilityId("ComputeSumButton");
Assert.assertEquals(computeSumButtons.size(), 1);
computeSumButtons.get(0).click();
}
@Test
public void testFindElementsByClassName () {
// Find element by name
List<WebElement> windowElements = driver.findElementsByClassName("XCUIElementTypeWindow");
Assert.assertTrue(windowElements.size() > 1);
};
@Test
public void testFindElementsByNSPredicateString () {
// This is an IOS-specific selector strategy. See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html for reference
List<WebElement> allVisibleElements = driver.findElementsByIosNsPredicate("visible = true");
Assert.assertTrue(allVisibleElements.size() > 1);
};
@Test
public void testFindElementsByClassChain () {
// This is also an IOS-specific selector strategy. Similar to XPath. This is recommended over XPath.
List<WebElement> windowElements = driver.findElementsByIosClassChain("XCUIElementTypeWindow[1]/*[2]");
Assert.assertEquals(windowElements.size(), 1);
};
@Test
public void testFindElementsByXPath () {
// Can find source xml by calling "driver.source()"
// Note that XPath is not recommended due to major performance issues
List<WebElement> buttons = driver.findElementsByXPath("//XCUIElementTypeWindow//XCUIElementTypeButton");
Assert.assertTrue(buttons.size() > 1);
};
}

Просмотреть файл

@ -0,0 +1,3 @@
{
"presets": ["es2015", "stage-0"]
}

Просмотреть файл

@ -0,0 +1,18 @@
# Javascript WD 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`)

Просмотреть файл

@ -0,0 +1,19 @@
{
"name": "javascript-wd",
"version": "1.0.0",
"description": "Appium sample code using 'wd'",
"scripts": {
"test": "mocha test/**/*.test.js"
},
"author": "Dan Graham",
"license": "Apache-2.0",
"devDependencies": {
"babel-core": "^6.26.0",
"babel-polyfill": "^6.26.0",
"babel-preset-es2015": "^6.24.1",
"babel-preset-stage-0": "^6.24.1",
"chai": "^4.1.2",
"mocha": "^4.1.0",
"wd": "^1.5.0"
}
}

Просмотреть файл

@ -0,0 +1,63 @@
import wd from 'wd';
import chai from 'chai';
import { androidCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
const PACKAGE = 'io.appium.android.apis';
const SEARCH_ACTIVITY = '.app.SearchInvoke';
const ALERT_DIALOG_ACTIVITY = '.app.AlertDialogSamples';
describe('Basic Android interactions', function () {
let driver;
before(async function () {
// Connect to Appium server
driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...androidCaps,
app: require('../helpers/apps').androidApiDemos,
appActivity: SEARCH_ACTIVITY, // Android-specific capability. Can open a specific activity.
});
});
after(async function () {
await driver.quit();
});
it('should send keys to search box and then check the value', async function () {
// Enter text in a search box
const searchBoxElement = await driver.elementById('txt_query_prefill');
await searchBoxElement.sendKeys('Hello world!');
// Press on 'onSearchRequestedButton'
const onSearchRequestedButton = await driver.elementById('btn_start_search');
await onSearchRequestedButton.click();
// Check that the text matches the search term
const searchText = await driver.waitForElementById('android:id/search_src_text');
const searchTextValue = await searchText.text();
assert.equal(searchTextValue, 'Hello world!');
});
it('should click a button that opens an alert and then dismisses it', async function () {
// Open the 'Alert Dialog' activity of the android app
await driver.startActivity({appPackage: PACKAGE, appActivity: ALERT_DIALOG_ACTIVITY});
// Click button that opens a dialog
const openDialogButton = await driver.elementById('io.appium.android.apis:id/two_buttons');
await openDialogButton.click();
// Check that the dialog is there
const alertElement = await driver.waitForElementById('android:id/alertTitle');
const alertText = await alertElement.text();
assert.equal(alertText, `Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.`);
const closeDialogButton = await driver.elementById('android:id/button1');
// Close the dialog
await closeDialogButton.click();
});
});

Просмотреть файл

@ -0,0 +1,26 @@
import wd from 'wd';
import chai from 'chai';
import { iosCaps, androidCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Create Android session', function () {
it('should create and destroy Android sessions', async function () {
// Connect to Appium server
const driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...androidCaps,
app: require('../helpers/apps').androidApiDemos
});
// Check that we're running the ApiDemos app by checking package and activity
const activity = await driver.getCurrentActivity();
const pkg = await driver.getCurrentPackage();
assert.equal(`${pkg}${activity}`, 'io.appium.android.apis.ApiDemos');
// Quit the session
await driver.quit();
});
});

Просмотреть файл

@ -0,0 +1,28 @@
import wd from 'wd';
import chai from 'chai';
import { androidCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Create Chrome web session', function () {
it('should create and destroy Android browser session', async function () {
// Connect to Appium server
const driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...androidCaps,
browserName: 'Chrome'
});
// Navigate to google.com
await driver.get('https://www.google.com');
// Test that it was successful by checking the document title
const pageTitle = await driver.title();
assert.equal(pageTitle, 'Google');
// Quit the session
await driver.quit();
});
});

Просмотреть файл

@ -0,0 +1,49 @@
import wd from 'wd';
import chai from 'chai';
import { androidCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Basic Android selectors', function () {
let driver;
before(async function () {
// Connect to Appium server
driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...androidCaps,
app: require('../helpers/apps').androidApiDemos
});
});
after(async function () {
await driver.quit();
});
it('should find elements by Accessibility ID', async function () {
// Look for element by accessibility. In Android this is the 'content-desc'
const searchParametersElement = await driver.elementsByAccessibilityId('Content');
assert.equal(searchParametersElement.length, 1);
});
it('should find elements by ID', async function () {
// Look for element by ID. In Android this is the 'resource-id'
const actionBarContainerElements = await driver.elementsById('android:id/action_bar_container');
assert.equal(actionBarContainerElements.length, 1);
});
it('should find elements by class name', async function () {
// Look for elements by the class name. In Android this is the Java Class Name of the view.
const linearLayoutElements = await driver.elementsByClassName('android.widget.FrameLayout');
assert.isAbove(linearLayoutElements.length, 1);
});
it('should find elements by XPath', async function () {
// Find elements by XPath
const linearLayoutElements = await driver.elementsByXPath(`//*[@class='android.widget.FrameLayout']`);
assert.isAbove(linearLayoutElements.length, 1);
});
});

Просмотреть файл

@ -0,0 +1,57 @@
import wd from 'wd';
import chai from 'chai';
import { iosCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Basic IOS interactions', function () {
let driver;
before(async function () {
// Connect to Appium server
driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...iosCaps,
app: require('../helpers/apps').iosTestApp
});
});
after(async function () {
await driver.quit();
});
it('should send keys to inputs', async function () {
// Find TextField input element
const textInputId = `TextField1`;
const textViewsEl = await driver.waitForElementByAccessibilityId(textInputId);
// Check that it doesn't have a value
let value = await textViewsEl.getValue();
assert.isNull(value, 'Input should have no value');
// Send keys to that input
await textViewsEl.sendKeys('Hello World!');
// Check that the input has new value
value = await textViewsEl.getValue();
assert.equal(value, 'Hello World!', 'Input should have newly input value');
});
it('should click a button that opens an alert', async function () {
// Find Button element and click on it
const buttonElementId = `show alert`;
const buttonElement = await driver.waitForElementByAccessibilityId(buttonElementId);
await buttonElement.click();
// Wait for the alert to show up
const alertTitleId = `Cool title`;
const alertTitleElement = await driver.waitForElementByAccessibilityId(alertTitleId);
// Check the text
const alertTitle = await alertTitleElement.text();
assert.equal(alertTitle, `Cool title`);
});
});

Просмотреть файл

@ -0,0 +1,26 @@
import wd from 'wd';
import chai from 'chai';
import { iosCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Create session', function () {
it('should create and destroy IOS sessions', async function () {
// Connect to Appium server
const driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...iosCaps,
app: require('../helpers/apps').iosTestApp
});
// Check that the XCUIElementTypeApplication was what we expect it to be
const applicationElement = await driver.elementByClassName('XCUIElementTypeApplication');
const applicationName = await applicationElement.getAttribute('name');
assert.equal(applicationName, 'TestApp');
// Quit the session
await driver.quit();
});
});

Просмотреть файл

@ -0,0 +1,28 @@
import wd from 'wd';
import chai from 'chai';
import { iosCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Create Safari session', function () {
it('should create and destroy IOS Safari session', async function () {
// Connect to Appium server
const driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...iosCaps,
browserName: 'Safari'
});
// Navigate to google.com
await driver.get('https://www.google.com');
// Test that it was successful by checking the document title
const pageTitle = await driver.title();
assert.equal(pageTitle, 'Google');
// Quit the session
await driver.quit();
});
});

Просмотреть файл

@ -0,0 +1,57 @@
import wd from 'wd';
import chai from 'chai';
import { iosCaps, serverConfig } from '../helpers/caps';
const {assert} = chai;
describe('Basic IOS selectors', function () {
let driver;
before(async function () {
// Connect to Appium server
driver = await wd.promiseChainRemote(serverConfig);
// Start the session
await driver.init({
...iosCaps,
app: require('../helpers/apps').iosTestApp
});
});
after(async function () {
await driver.quit();
});
it('should find elements by Accessibility ID', async function () {
// This finds elements by 'accessibility id', which in the case of IOS is the 'name' attribute of the element
const computeSumButtons = await driver.elementsByAccessibilityId('ComputeSumButton');
assert.equal(computeSumButtons.length, 1);
await computeSumButtons[0].click();
});
it('should find elements by class name', async function () {
// Find element by name
const windowElements = await driver.elementsByClassName('XCUIElementTypeWindow');
assert.isAbove(windowElements.length, 1);
});
it('should find elements by NSPredicateString', async function () {
// This is an IOS-specific selector strategy. See https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/Articles/pSyntax.html for reference
const allVisibleElements = await driver.elements('-ios predicate string', 'visible = 1');
assert.isAbove(allVisibleElements.length, 1);
});
it('should find elements by class chain', async function () {
// This is also an IOS-specific selector strategy. Similar to XPath. This is recommended over XPath.
const windowElement = await driver.elements('-ios class chain', 'XCUIElementTypeWindow[1]/*[2]');
assert.equal(windowElement.length, 1);
});
it('should find elements by XPath', async function () {
// Can find source xml by calling `driver.source()`
// Note that XPath is not recommended due to major performance issues
const buttons = await driver.elementsByXPath('//XCUIElementTypeWindow//XCUIElementTypeButton');
assert.isAbove(buttons.length, 1, 'Should have more than one button');
});
});

Просмотреть файл

@ -0,0 +1,10 @@
import path from 'path';
if (process.env.SAUCE_LABS) {
// TODO: Change thes URL's to updated locations
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");
}

Просмотреть файл

@ -0,0 +1,32 @@
import path from '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
};
// 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_LABS ? 'Android GoogleAPI Emulator' : 'My Android Device';
const DEFAULT_ANDROID_PLATFORM_VERSION = process.env.SAUCE_LABS ? '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 serverConfig = process.env.SAUCE_LABS ? {
host: 'ondemand.saucelabs.com',
port: 80
} : {
host: process.env.APPIUM_HOST || 'localhost',
port: process.env.APPIUM_PORT || 4723
};
export { iosCaps, androidCaps, serverConfig };

Просмотреть файл

@ -0,0 +1,3 @@
--compilers babel-core/register
--require babel-polyfill
--timeout 1800000

Просмотреть файл

@ -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`)

Просмотреть файл

@ -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");
}

Просмотреть файл

@ -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
};

Просмотреть файл

@ -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"
}
}

Просмотреть файл

@ -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);
});
});
});

Просмотреть файл

@ -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);
});
});
});

Просмотреть файл

@ -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");
});
});
});

Просмотреть файл

@ -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);
});
});
});

Просмотреть файл

@ -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();
});
});

Просмотреть файл

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

16
sample-code/php/README.md Normal file
Просмотреть файл

@ -0,0 +1,16 @@
# PHP Sample Code
## Setup
* Install [composer](https://getcomposer.org/)
* Run `composer install` from this directory
## Running Tests
* vendor/phpunit/phpunit/phpunit <path_to_tests> (e.g.: `vendor/phpunit/phpunit/phpunit test/basic/AndroidBasicInteractions.php`)
## 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

Просмотреть файл

@ -0,0 +1,12 @@
{
"name": "username/my-php-project",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/appium/php-client"
}
],
"require": {
"appium/php-client": "dev-master"
}
}

Просмотреть файл

@ -0,0 +1,49 @@
<?php
require_once("PHPUnit/Extensions/AppiumTestCase.php");
require_once("PHPUnit/Extensions/AppiumTestCase/Element.php");
require_once(__DIR__ . "/../helpers/Apps.php");
require_once(__DIR__ . "/../helpers/Caps.php");
require_once(__DIR__ . "/../helpers/Helpers.php");
define("APP", Apps::getApps()["androidApiDemos"]);
define("CAPS", Caps::getAndroidCaps(APP, ".app.SearchInvoke"));
class AndroidBasicInteractions extends PHPUnit_Extensions_AppiumTestCase {
public static $browsers = CAPS;
public function testShouldSendKeysToSearchBoxAndCheckValue()
{
// Enter text in a search box
$searchBoxElement = Helpers::elemBy($this, "id", "txt_query_prefill");
$searchBoxElement->value("Hello world!");
// Press on "onSearchRequestedButton"
$onSearchRequestedButton = Helpers::elemBy($this, "id", "btn_start_search");
$onSearchRequestedButton->click();
// Check that the text matches the search term
$searchText = Helpers::waitForElemBy($this, "id", "android:id/search_src_text");
$this->assertEquals($searchText->text(), "Hello world!");
}
public function testShouldClickButtonOpensAlert()
{
$this->startActivity(array(
"appActivity" => ".app.AlertDialogSamples",
"appPackage" => "io.appium.android.apis"
));
$openDialogButtons = Helpers::waitForElemBy($this, "id", "io.appium.android.apis:id/two_buttons");
$openDialogButtons->click();
// Check that the dialog is there
$alertElement = Helpers::waitForElemBy($this, "id", "android:id/alertTitle");
$alertText = $alertElement->text();
$this->assertEquals($alertText, "Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.");
$closeDialogButton = Helpers::waitForElemBy($this, "id", "android:id/button1");
// Close the dialog
$closeDialogButton->click();
}
}
?>

Просмотреть файл

@ -0,0 +1,25 @@
<?php
require_once("PHPUnit/Extensions/AppiumTestCase.php");
require_once("PHPUnit/Extensions/AppiumTestCase/Element.php");
require_once(__DIR__ . "/../helpers/Apps.php");
require_once(__DIR__ . "/../helpers/Caps.php");
require_once(__DIR__ . "/../helpers/Helpers.php");
define("APP", Apps::getApps()["androidApiDemos"]);
define("CAPS", Caps::getAndroidCaps(APP));
class AndroidCreateSession extends PHPUnit_Extensions_AppiumTestCase {
public static $browsers = CAPS;
public function testCreateSession()
{
// Check that we're running the ApiDemos app by checking package and activity
$activity = $this->currentActivity();
$pkg = $this->currentPackage();
$this->assertEquals($activity, '.ApiDemos');
$this->assertEquals($pkg, 'io.appium.android.apis');
}
}
?>

Просмотреть файл

@ -0,0 +1,25 @@
<?php
require_once("PHPUnit/Extensions/AppiumTestCase.php");
require_once("PHPUnit/Extensions/AppiumTestCase/Element.php");
require_once(__DIR__ . "/../helpers/Apps.php");
require_once(__DIR__ . "/../helpers/Caps.php");
require_once(__DIR__ . "/../helpers/Helpers.php");
define("CAPS", Caps::getAndroidCaps("", "", "Chrome"));
class AndroidCreateWebSession extends PHPUnit_Extensions_AppiumTestCase {
public static $browsers = CAPS;
public function testCreateWebSession()
{
// Navigate to google.com
$this->url('https://www.google.com');
// Test that it was successful by checking the document title
$pageTitle = $this->title();
$this->assertEquals($pageTitle, 'Google');
}
}
?>

Просмотреть файл

@ -0,0 +1,48 @@
<?php
require_once("PHPUnit/Extensions/AppiumTestCase.php");
require_once("PHPUnit/Extensions/AppiumTestCase/Element.php");
require_once(__DIR__ . "/../helpers/Apps.php");
require_once(__DIR__ . "/../helpers/Caps.php");
require_once(__DIR__ . "/../helpers/Helpers.php");
define("APP", Apps::getApps()["iosTestApp"]);
define("CAPS", Caps::getIosCaps(APP, ".app.SearchInvoke"));
class IosBasicInteractions extends PHPUnit_Extensions_AppiumTestCase {
public static $browsers = CAPS;
public function testShouldSendKeysToSearchBoxAndCheckValue()
{
// Find TextField input element
$textViewsEl = Helpers::elemBy($this, "accessibility id", "TextField1");
// Check that it doesn't have a value
$value = $textViewsEl->text();
$this->assertEquals($value, "");
// Send keys to that input
$textViewsEl->value('Hello World!');
// Check that the input has new value
$value = $textViewsEl->text();
$this->assertEquals(value, 'Hello World!');
}
public function testShouldClickButtonOpensAlert()
{
// Find Button element and click on it
$buttonElement = Helpers::elemBy($this, "accessibility id", "show alert");
$buttonElement->click();
// Wait for the alert to show up
$alertTitleId = `Cool title`;
$alertTitleElement = Helpers::elemBy($this, "accessibility id", "Cool title");
// Check the text
$alertTitle = $alertTitleElement->text();
$this->assertEquals($alertTitle, "Cool title");
}
}
?>

Просмотреть файл

@ -0,0 +1,25 @@
<?php
require_once("PHPUnit/Extensions/AppiumTestCase.php");
require_once("PHPUnit/Extensions/AppiumTestCase/Element.php");
require_once(__DIR__ . "/../helpers/Apps.php");
require_once(__DIR__ . "/../helpers/Caps.php");
require_once(__DIR__ . "/../helpers/Helpers.php");
define("APP", Apps::getApps()["iosTestApp"]);
define("CAPS", Caps::getIosCaps(APP, ".app.SearchInvoke"));
class IosCreateSession extends PHPUnit_Extensions_AppiumTestCase {
public static $browsers = CAPS;
public function testCreateSession()
{
// Check that the XCUIElementTypeApplication was what we expect it to be
$applicationElement = Helpers::elemBy($this, 'class name', 'XCUIElementTypeApplication');
$applicationName = $applicationElement->attribute('name');
$this->assertEquals($applicationName, 'TestApp');
}
}
?>

Просмотреть файл

@ -0,0 +1,27 @@
<?php
require_once("PHPUnit/Extensions/AppiumTestCase.php");
require_once("PHPUnit/Extensions/AppiumTestCase/Element.php");
require_once(__DIR__ . "/../helpers/Apps.php");
require_once(__DIR__ . "/../helpers/Caps.php");
require_once(__DIR__ . "/../helpers/Helpers.php");
define("APP", Apps::getApps()["iosTestApp"]);
define("CAPS", Caps::getIosCaps("", "Safari"));
class IosCreateWebSession extends PHPUnit_Extensions_AppiumTestCase {
public static $browsers = CAPS;
public function testShouldCreateAndDestroySafariSession()
{
// Navigate to google.com
$this->url('https://www.google.com');
// Test that it was successful by checking the document title
$pageTitle = $this->title();
$this->assertEquals($pageTitle, 'Google');
}
}
?>

Просмотреть файл

@ -0,0 +1,22 @@
<?php
define("IOS_TEST_APP", __DIR__.'/../../../apps/TestApp.app.zip');
define("ANDROID_API_DEMOS", __DIR__.'/../../../apps/ApiDemos-debug.apk');
class Apps {
public static function getApps () {
if (getenv("SAUCE_LABS", true)) {
return array(
"iosTestApp" => "http://appium.github.io/appium/assets/TestApp7.1.app.zip",
"androidApiDemos" => "http://appium.github.io/appium/assets/ApiDemos-debug.apk",
);
} else {
return array(
"iosTestApp" => IOS_TEST_APP,
"androidApiDemos" => ANDROID_API_DEMOS,
);
}
}
}
?>

Просмотреть файл

@ -0,0 +1,73 @@
<?php
$host = getenv("APPIUM_HOST", true) || "localhost";
if (getenv("SAUCE_LABS", true)) {
$host = "ondemand.saucelabs.com";
}
// Define the port
$port = 4723;
if (isset($_ENV["APPIUM_PORT"])) {
$port = getenv("APPIUM_PORT");
} else if (isset($_ENV["SAUCE_LABS"]) && getenv("SAUCE_LABS", true)) {
$port = 80;
}
// Define if is local
$isLocal = false;
if (isset($_ENV["SAUCE_LABS"])) {
$isLocal = getenv("SAUCE_LABS", true);
}
// Get default android platform version
$androidPlatformVersion = "";
$androidDeviceName = "My Android Device";
if (isset($_ENV["SAUCE_LABS"])) {
$androidPlatformVersion = getenv("ANDROID_PLATFORM_VERSION", true);
$androidDeviceName = "Android GoogleAPI Emulator";
}
define('PORT', $port);
define('IS_LOCAL', $isLocal);
define('ANDROID_PLATFORM_VERSION', $androidPlatformVersion);
define('ANDROID_DEVICE_NAME', $androidDeviceName);
class Caps {
public static function getIosCaps($app, $browserName="") {
return array(
array(
"local" => IS_LOCAL,
"port" => PORT,
"browserName" => $browserName,
"desiredCapabilities" => array(
"platformName" => "iOS",
"automationName" => "XCUITest",
"platformVersion" => getenv("IOS_PLATFORM_VERSION", true) ? getenv("IOS_PLATFORM_VERSION") : "11.1",
"deviceName" => getenv("IOS_DEVICE_NAME", true) ? getenv("IOS_DEVICE_NAME") : "iPhone 6s",
"app" => $app
)
)
);
}
public static function getAndroidCaps($app, $appActivity="", $browserName="") {
return array(
array(
"local" => IS_LOCAL,
"port" => PORT,
"browserName" => $browserName,
"desiredCapabilities" => array(
"platformName" => "Android",
"automationName" => "UIAutomator2",
"platformVersion" => ANDROID_PLATFORM_VERSION,
"deviceName" => ANDROID_DEVICE_NAME,
"app" => $app,
"appActivity" => $appActivity,
)
)
);
}
}
?>

Просмотреть файл

@ -0,0 +1,44 @@
<?php
class Helpers {
public static function elemsBy($driver, $using, $tag)
{
return $driver->elements($driver->using($using)->value($tag));
}
public static function waitForElemsBy($driver, $using, $tag)
{
$element;
$i = 0;
while ($i < 20) {
$element = $driver->elements($driver->using("id")->value($tag));
if ($element) {
break;
}
sleep(1);
}
return $element;
}
public static function elemBy($driver, $using, $tag)
{
$elems = Helpers::elemsBy($driver, $using, $tag);
if ($elems)
{
return $elems[0];
}
}
public static function waitForElemBy($driver, $using, $tag)
{
$elems = Helpers::waitForElemsBy($driver, $using, $tag);
if ($elems)
{
return $elems[0];
}
}
}
?>

Просмотреть файл

@ -0,0 +1,5 @@
# Python Sample Code
## Setup
* <Setup instructions>

10
sample-code/ruby/Gemfile Normal file
Просмотреть файл

@ -0,0 +1,10 @@
source 'https://www.rubygems.org'
gem 'appium_lib', '~> 9.10'
gem 'rest-client', '~> 2.0.2'
gem 'rspec', '~> 3.6.0'
gem 'cucumber', '~> 2.4.0'
gem 'rspec-expectations', '~> 3.6.0'
gem 'spec', '~> 5.3.4'
gem 'sauce_whisk', '~> 0.0.13'
gem 'test-unit', '~> 2.5.5'

Просмотреть файл

@ -0,0 +1,91 @@
GEM
remote: https://www.rubygems.org/
specs:
appium_lib (9.7.5)
awesome_print (~> 1.8)
json (>= 1.8)
nokogiri (~> 1.6, >= 1.6.6)
selenium-webdriver (~> 3.4, >= 3.4.1)
tomlrb (~> 1.1)
awesome_print (1.8.0)
builder (3.2.3)
childprocess (0.8.0)
ffi (~> 1.0, >= 1.0.11)
chronic_duration (0.10.6)
numerizer (~> 0.1.1)
cucumber (2.4.0)
builder (>= 2.1.2)
cucumber-core (~> 1.5.0)
cucumber-wire (~> 0.0.1)
diff-lcs (>= 1.1.3)
gherkin (~> 4.0)
multi_json (>= 1.7.5, < 2.0)
multi_test (>= 0.1.2)
cucumber-core (1.5.0)
gherkin (~> 4.0)
cucumber-wire (0.0.1)
diff-lcs (1.3)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
ffi (1.9.23)
gherkin (4.1.3)
http-cookie (1.0.3)
domain_name (~> 0.5)
json (2.1.0)
mime-types (3.1)
mime-types-data (~> 3.2015)
mime-types-data (3.2016.0521)
mini_portile2 (2.3.0)
multi_json (1.13.1)
multi_test (0.1.2)
netrc (0.11.0)
nokogiri (1.8.2)
mini_portile2 (~> 2.3.0)
numerizer (0.1.1)
rest-client (2.0.2)
http-cookie (>= 1.0.2, < 2.0)
mime-types (>= 1.16, < 4.0)
netrc (~> 0.8)
rspec (3.6.0)
rspec-core (~> 3.6.0)
rspec-expectations (~> 3.6.0)
rspec-mocks (~> 3.6.0)
rspec-core (3.6.0)
rspec-support (~> 3.6.0)
rspec-expectations (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-mocks (3.6.0)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.6.0)
rspec-support (3.6.0)
rubyzip (1.2.1)
sauce_whisk (0.0.22)
json (>= 1.8)
rest-client (>= 1.8)
selenium-webdriver (3.10.0)
childprocess (~> 0.5)
rubyzip (~> 1.2)
spec (5.3.4)
chronic_duration (~> 0.10.2)
test-unit (2.5.5)
tomlrb (1.2.6)
unf (0.1.4)
unf_ext
unf_ext (0.0.7.5)
PLATFORMS
ruby
DEPENDENCIES
appium_lib (~> 9.7.4)
cucumber (~> 2.4.0)
rest-client (~> 2.0.2)
rspec (~> 3.6.0)
rspec-expectations (~> 3.6.0)
sauce_whisk (~> 0.0.13)
spec (~> 5.3.4)
test-unit (~> 2.5.5)
BUNDLED WITH
1.15.3

Просмотреть файл

@ -0,0 +1,10 @@
# Ruby Sample Code
## Setup
* Install `ruby` and `rspec`
* Run `bundle install` from this directory
## Running Tests
* `rspec spec/<name_of_test>_spec.rb`

Просмотреть файл

@ -0,0 +1,63 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
PACKAGE = 'io.appium.android.apis'
SEARCH_ACTIVITY = '.app.SearchInvoke'
ALERT_DIALOG_ACTIVITY = '.app.AlertDialogSamples'
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/ApiDemos-debug.apk' : '../apps/ApiDemos-debug.apk'
desired_caps = {
caps: {
platformName: 'Android',
platformVersion: ENV['SAUCE_LABS'] ? (ENV["ANDROID_PLATFORM_VERSION"] || '7.1') : ENV["ANDROID_PLATFORM_VERSION"],
deviceName: ENV["ANDROID_DEVICE_VERSION"] || 'Android',
app: APP_PATH,
automationName: 'UIAutomator2',
appActivity: SEARCH_ACTIVITY
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Basic Android interactions' do
before(:all) do
@driver = Appium::Driver.new(desired_caps, true).start_driver
end
after(:all) do
@driver.quit
end
it 'should send keys to search box and then check the value' do
@search_box_element = @driver.find_element(:id, 'txt_query_prefill')
@search_box_element.send_keys('Hello world!')
@on_search_requested_button = @driver.find_element(:id, 'btn_start_search')
@on_search_requested_button.click()
@search_text = @driver.find_element(:id, 'android:id/search_src_text')
@search_text_value = @search_text.text()
expect(@search_text_value).to eql('Hello world!')
end
it 'should click a button that opens an alert and then dismisses it' do
@driver.start_activity app_package: PACKAGE, app_activity: ALERT_DIALOG_ACTIVITY
@open_dialog_button = @driver.find_element(:id, 'io.appium.android.apis:id/two_buttons')
@open_dialog_button.click()
@alert_element = @driver.find_element(:id, 'android:id/alertTitle')
@alert_text = @alert_element.text()
expect(@alert_text).to eql("Lorem ipsum dolor sit aie consectetur adipiscing\nPlloaso mako nuto siwuf cakso dodtos anr koop.")
@close_dialog_button = @driver.find_element(:id, 'android:id/button1')
@close_dialog_button.click()
end
end

Просмотреть файл

@ -0,0 +1,33 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/ApiDemos-debug.apk' : '../apps/ApiDemos-debug.apk'
desired_caps = {
caps: {
platformName: 'Android',
platformVersion: ENV['SAUCE_LABS'] ? (ENV["ANDROID_PLATFORM_VERSION"] || '7.1') : ENV["ANDROID_PLATFORM_VERSION"],
deviceName: ENV["ANDROID_DEVICE_VERSION"] || 'Android',
app: APP_PATH,
automationName: 'UIAutomator2',
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Create Android session' do
it 'should create and destroy Android sessions' do
@driver = Appium::Driver.new(desired_caps, true).start_driver
@activity = @driver.current_activity
@pkg = @driver.current_package
expect("#{@pkg}#{@activity}").to eql('io.appium.android.apis.ApiDemos')
@driver.quit()
end
end

Просмотреть файл

@ -0,0 +1,33 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
desired_caps = {
caps: {
platformName: 'Android',
platformVersion: ENV['SAUCE_LABS'] ? (ENV["ANDROID_PLATFORM_VERSION"] || '7.1') : ENV["ANDROID_PLATFORM_VERSION"],
deviceName: ENV["ANDROID_DEVICE_VERSION"] || 'Android',
automationName: 'UIAutomator2',
browserName: 'Chrome'
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Create Chrome web session' do
it 'should create and destroy Android browser session' do
@driver = Appium::Driver.new(desired_caps, true).start_driver
@driver.get('https://www.google.com')
@page_title = @driver.title()
expect(@page_title).to eql('Google')
@driver.quit()
end
end

Просмотреть файл

@ -0,0 +1,56 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
PACKAGE = 'io.appium.android.apis'
SEARCH_ACTIVITY = '.app.SearchInvoke'
ALERT_DIALOG_ACTIVITY = '.app.AlertDialogSamples'
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/ApiDemos-debug.apk' : '../apps/ApiDemos-debug.apk'
desired_caps = {
caps: {
platformName: 'Android',
platformVersion: ENV['SAUCE_LABS'] ? (ENV["ANDROID_PLATFORM_VERSION"] || '7.1') : ENV["ANDROID_PLATFORM_VERSION"],
deviceName: ENV["ANDROID_DEVICE_VERSION"] || 'Android',
app: APP_PATH,
automationName: 'UIAutomator2'
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Basic Android selectors' do
before(:all) do
@driver = Appium::Driver.new(desired_caps, true).start_driver
end
after(:all) do
@driver.quit
end
it 'should find elements by Accessibility ID' do
@search_parameters_element = @driver.find_elements(:accessibility_id, 'Content')
expect(@search_parameters_element.length).to eql 1
end
it 'should find elements by ID' do
@action_bar_container_elements = @driver.find_elements(:id, 'android:id/action_bar_container')
expect(@action_bar_container_elements.length).to eql 1
end
it 'should find elements by class name' do
@linear_layout_elements = @driver.find_elements(:class_name, 'android.widget.FrameLayout')
expect(@linear_layout_elements.length).to be > 1
end
it 'should find elements by XPath' do
@linear_layout_elements = @driver.find_elements(:xpath, "//*[@class='android.widget.FrameLayout']")
expect(@linear_layout_elements.length).to be > 1
end
end

Просмотреть файл

@ -0,0 +1,49 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/TestApp7.1.app.zip' : '../apps/TestApp.app.zip'
desired_caps = {
caps: {
platformName: 'iOS',
platformVersion: ENV["IOS_PLATFORM_VERSION"] || '11.1',
deviceName: ENV["IOS_DEVICE_NAME"] || 'iPhone 6s',
app: APP_PATH,
automationName: 'XCUITest',
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
# Start the driver
describe "IOS Basic Interactions" do
before(:all) do
@driver = Appium::Driver.new(desired_caps, true).start_driver
end
after(:all) do
@driver.quit
end
it "should send keys to inputs" do
@textFieldEl = @driver.find_element(:id, "TextField1")
expect(@textFieldEl.attribute(:value)).to be_nil
@textFieldEl.send_keys("Hello World!")
expect(@textFieldEl.attribute(:value)).to eq("Hello World!")
end
it "should click a button that opens an alert" do
@buttonElementId = "show alert"
@buttonElement = @driver.find_element(:accessibility_id, @buttonElementId)
@buttonElement.click()
@alertTitleId = "Cool title"
@alertTitleElement = @driver.find_element(:accessibility_id, @alertTitleId)
@alertTitle = @alertTitleElement.attribute(:value)
expect(@alertTitle.attribute(:value)).to eq("Cool title")
end
end

Просмотреть файл

@ -0,0 +1,33 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/TestApp7.1.app.zip' : '../apps/TestApp.app.zip'
desired_caps = {
caps: {
platformName: 'iOS',
platformVersion: ENV["IOS_PLATFORM_VERSION"] || '11.1',
deviceName: ENV["IOS_DEVICE_NAME"] || 'iPhone 6s',
app: APP_PATH,
automationName: 'XCUITest',
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Create session' do
it 'should create and destroy IOS sessions' do
@driver = Appium::Driver.new(desired_caps, true).start_driver
@application_element = @driver.find_element(:class_name, 'XCUIElementTypeApplication')
@application_name = @application_element.attribute(:name)
expect(@application_name).to eq('TestApp')
@driver.quit
end
end

Просмотреть файл

@ -0,0 +1,32 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/TestApp7.1.app.zip' : '../apps/TestApp.app.zip'
desired_caps = {
caps: {
platformName: 'iOS',
platformVersion: ENV["IOS_PLATFORM_VERSION"] || '11.1',
deviceName: ENV["IOS_DEVICE_NAME"] || 'iPhone 6s',
automationName: 'XCUITest',
browserName: 'Safari',
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Create Safari session' do
it 'should create and destroy IOS Safari session' do
@driver = Appium::Driver.new(desired_caps, true).start_driver
@driver.get('https://www.google.com')
expect(@driver.title).to eql('Google')
@driver.quit
end
end

Просмотреть файл

@ -0,0 +1,57 @@
require 'rubygems'
require 'appium_lib'
require 'test/unit'
extend Test::Unit::Assertions
APP_PATH = ENV['SAUCE_LABS'] ? 'http://appium.github.io/appium/assets/TestApp7.1.app.zip' : '../apps/TestApp.app.zip'
desired_caps = {
caps: {
platformName: 'iOS',
platformVersion: ENV["IOS_PLATFORM_VERSION"] || '11.1',
deviceName: ENV["IOS_DEVICE_NAME"] || 'iPhone 6s',
app: APP_PATH,
automationName: 'XCUITest',
},
appium_lib: {
sauce_username: ENV['SAUCE_LABS'] ? ENV['SAUCE_USERNAME'] : nil,
sauce_access_key: ENV['SAUCE_LABS'] ? ENV['SAUCE_ACCESS_KEY'] : nil,
wait: 60
}
}
describe 'Basic IOS selectors' do
before(:all) do
@driver = Appium::Driver.new(desired_caps, true).start_driver
end
after(:all) do
@driver.quit
end
it 'should find elements by Accessibility ID' do
@compute_sum_buttons = @driver.find_elements(:accessibility_id, 'ComputeSumButton')
expect(@compute_sum_buttons.length).to eql(1)
@compute_sum_buttons[0].click()
end
it 'should find elements by class name' do
@window_elements = @driver.find_elements(:class_name, 'XCUIElementTypeWindow')
expect(@window_elements.length).to be > 1
end
it 'should find elements by NSPredicateString' do
@all_visible_elements = @driver.find_elements(:predicate, 'visible = 1')
expect(@all_visible_elements.length).to be > 1
end
it 'should find elements by class chain' do
@window_element = @driver.find_elements(:class_chain, 'XCUIElementTypeWindow[1]/*[2]')
expect(@window_element.length).to be(1)
end
it 'should find elements by XPath' do
@buttons = @driver.find_elements(:xpath, '//XCUIElementTypeWindow//XCUIElementTypeButton')
expect(@buttons.length).to be > 1
end
end