mirror of
https://github.com/appium/appium.git
synced 2026-02-16 06:50:20 -06:00
Bring Sample Code into master (#10880)
* Sample code stub (#9887) * WD tests * WD sample code (#9918) * WebdriverIO sample code (#10166) * Ruby sample code (#10331) * PHP Sample Code (#10209) * Basic Android java test * Java sample code (#10427) * Sample code (#10834) * Sample code stub (#9887) * WD tests * WD sample code (#9918) * WebdriverIO sample code (#10166) * Ruby sample code (#10331) * PHP Sample Code (#10209) * Basic Android java test * Java sample code (#10427) * fixed WDIO test * Update .npmignore
This commit is contained in:
16
sample-code/php/README.md
Normal file
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
|
||||
12
sample-code/php/composer.json
Normal file
12
sample-code/php/composer.json
Normal file
@@ -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"
|
||||
}
|
||||
}
|
||||
49
sample-code/php/test/basic/AndroidBasicInteractions.php
Normal file
49
sample-code/php/test/basic/AndroidBasicInteractions.php
Normal file
@@ -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();
|
||||
}
|
||||
}
|
||||
?>
|
||||
25
sample-code/php/test/basic/AndroidCreateSession.php
Normal file
25
sample-code/php/test/basic/AndroidCreateSession.php
Normal file
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
25
sample-code/php/test/basic/AndroidCreateWebSession.php
Normal file
25
sample-code/php/test/basic/AndroidCreateWebSession.php
Normal file
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
48
sample-code/php/test/basic/IosBasicInteractions.php
Normal file
48
sample-code/php/test/basic/IosBasicInteractions.php
Normal file
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
25
sample-code/php/test/basic/IosCreateSession.php
Normal file
25
sample-code/php/test/basic/IosCreateSession.php
Normal file
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
27
sample-code/php/test/basic/IosCreateWebSession.php
Normal file
27
sample-code/php/test/basic/IosCreateWebSession.php
Normal file
@@ -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');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
22
sample-code/php/test/helpers/Apps.php
Normal file
22
sample-code/php/test/helpers/Apps.php
Normal file
@@ -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,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
73
sample-code/php/test/helpers/Caps.php
Normal file
73
sample-code/php/test/helpers/Caps.php
Normal file
@@ -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,
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
44
sample-code/php/test/helpers/Helpers.php
Normal file
44
sample-code/php/test/helpers/Helpers.php
Normal file
@@ -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];
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user