Skip to content

Commit

Permalink
Bring Sample Code into master (appium#10880)
Browse files Browse the repository at this point in the history
* Sample code stub (appium#9887)

* WD tests

* WD sample code (appium#9918)

* WebdriverIO sample code (appium#10166)

* Ruby sample code (appium#10331)

* PHP Sample Code (appium#10209)

* Basic Android java test

* Java sample code (appium#10427)

* Sample code (appium#10834)

* Sample code stub (appium#9887)

* WD tests

* WD sample code (appium#9918)

* WebdriverIO sample code (appium#10166)

* Ruby sample code (appium#10331)

* PHP Sample Code (appium#10209)

* Basic Android java test

* Java sample code (appium#10427)

* fixed WDIO test

* Update .npmignore
  • Loading branch information
imurchie authored Jun 15, 2018
1 parent aab1649 commit 04f6543
Show file tree
Hide file tree
Showing 68 changed files with 2,098 additions and 27 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 6 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ _vimrc_local.vim
*.trace
*.sublime-
*.prefs
./.npmignore
coverage
sample-code/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
44 changes: 22 additions & 22 deletions docs/en/about-appium/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,16 @@ 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

To verify that all of Appium's dependencies are met you can use
`appium-doctor`. Install it with `npm install -g appium-doctor`, then run the
`appium-doctor`. Install it with `npm install -g appium-doctor`, then run the
`appium-doctor` command, supplying the `--ios` or `--android` flags to verify
that all of the dependencies are set up correctly.

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion docs/en/writing-running-appium/running-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
17 changes: 17 additions & 0 deletions sample-code/README.md
Original file line number Diff line number Diff line change
@@ -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.
Binary file added sample-code/apps/ApiDemos-debug.apk
Binary file not shown.
Binary file added sample-code/apps/TestApp.app.zip
Binary file not shown.
Empty file added sample-code/csharp/README.md
Empty file.
9 changes: 9 additions & 0 deletions sample-code/java/README.md
Original file line number Diff line number Diff line change
@@ -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 changes: 32 additions & 0 deletions sample-code/java/java.iml
Original file line number Diff line number Diff line change
@@ -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>
71 changes: 71 additions & 0 deletions sample-code/java/src/AndroidBasicInteractionsTest.java
Original file line number Diff line number Diff line change
@@ -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();
}
}
37 changes: 37 additions & 0 deletions sample-code/java/src/AndroidCreateSessionTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
32 changes: 32 additions & 0 deletions sample-code/java/src/AndroidCreateWebSessionTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
Loading

0 comments on commit 04f6543

Please sign in to comment.