An extension library to add Selenium 3 features to Appium.

Overview

Appium PHP Client

An extension library to add Selenium 3 features to Appium.

The library is installable using the Composer dependency manager. Just add "appium/appium-php": "dev-master" (or any other branch/tag you might like) to your composer.json file's requires, and the repository on GitHub to the repositories:

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

Have an instance of Appium running in the background at port 4723. Then install the dependencies and run your tests:

composer install
vendor/phpunit/phpunit/phpunit <mytest.php>

For more details about your tests add the --verbose flag to phpunit

Usage and changes

There are a number of methods added to Selenium 3/Appium 1. The central change is in the test case that serves as the base of your tests, and the elements with which you interact. Both are subclasses of the PHPUnit Selenium classes. Your tests should be subclasses of PHPUnit_Extensions_AppiumTestCase, and all elements that get returned will be of the class PHPUnit_Extensions_AppiumTestCase_Element.

require_once('PHPUnit/Extensions/AppiumTestCase.php');
require_once('PHPUnit/Extensions/AppiumTestCase/Element.php');

class MySuperTests extends PHPUnit_Extensions_AppiumTestCase
{
    public static $browsers = array(
        array(
            'local' => true,
            'port' => 4723,
            'browserName' => '',
            'desiredCapabilities' => array(
                'app' => APP_PATH
            )
        )
    );

    public function testStuff()
    {
        $element = $this->byAccessibilityId('Element on screen');

        $this->assertInstanceOf('PHPUnit_Extensions_AppiumTestCase_Element', $element);
    }
}

Methods added

Methods in PHPUnit_Extensions_AppiumTestCase

  • byIOSUIAutomation
  • byAndroidUIAutomator
  • byAccessibilityId
  • keyEvent
  • pullFile
  • pushFile
  • backgroundApp
  • isAppInstalled
  • installApp
  • removeApp
  • launchApp
  • closeApp
  • endTestCoverage
  • lock
  • shake
  • getDeviceTime
  • hideKeyboard
  • initiateTouchAction
  • initiateMultiAction
  • scroll
  • dragAndDrop
  • swipe
  • tap
  • pinch
  • zoom
  • startActivity
  • getSettings
  • setSettings

Methods in PHPUnit_Extensions_AppiumTestCase_Element

  • byIOSUIAutomation
  • byAndroidUIAutomator
  • byAccessibilityId
  • setImmediateValue

Methods for Touch Actions and Multi Gesture Touch Actions

Appium 1.0 allows for much more complex ways of interacting with your app through Touch Actions and Multi Gesture Touch Actions. The PHPUnit_Extensions_AppiumTestCase_TouchAction class allows for the following events:

  • tap
  • press
  • longPress
  • moveTo
  • wait
  • release

All of these except tap and release can be chained together to create arbitrarily complex actions. Instances of the PHPUnit_Extensions_AppiumTestCase_TouchAction class are obtained through the Test Class's initiateTouchAction method, and dispatched through the perform method.

The Multi Gesture Touch Action API allows for adding an arbitrary number of Touch Actions to be run in parallel on the device. Individual actions created as above are added to the multi action object (an instance of PHPUnit_Extensions_AppiumTestCase_MultiAction obtained from the Test Class's initiateMultiAction method) through the add method, and the whole thing is dispatched using perform.

Comments
  • third argument is no needed

    third argument is no needed

    hi I tried to make auto test. But i got a error.

    1) IosCreateWebSession::testShouldCreateAndDestroySafariSession
    Undefined index: secure
    
    /Users/xxxxx/ios_unittest_appium/vendor/appium/php-client/PHPUnit/Extensions/AppiumTestCase/SessionStrategy/Isolated.php:25
    /Users/xxxxx/ios_unittest_appium/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:319
    /Users/xxxxx/ios_unittest_appium/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:360
    /Users/xxxxx/ios_unittest_appium/vendor/phpunit/phpunit-selenium/PHPUnit/Extensions/Selenium2TestCase.php:337
    

    then i checked 'Isolated.php:25'

    $seleniumServerUrl = PHPUnit_Extensions_Selenium2TestCase_URL::fromHostAndPort($parameters['host'], $parameters['port'], $parameters['secure'])
    

    and i checked this also

    /**
         * @param string $host
         * @param int port
         * @return PHPUnit_Extensions_Selenium2TestCase_URL
         */
        public static function fromHostAndPort($host, $port)
        {
            return new self("http://{$host}:{$port}");
        }
    

    so that i think third argument is no needed.

    Could you accept my pull request?

    opened by shiratsu 11
  • Fixed getting one or more children of an element

    Fixed getting one or more children of an element

    The "elements" function used to call prepareSession(), which isn't defined for the element. Instead it should use $this just like the "element" method right above it.

    As described in #26.

    opened by quintstoffers 6
  • appium/app/strings command must be updated

    appium/app/strings command must be updated

    The Appium command 'session/:sessionId?/appium/app/strings' has changed: https://github.com/appium/appium/commit/af89c299473617b7980770102f07a1205c25627b

    Now it's a POST command and allows an optional parameter language to get strings for a specific language.

    • appium/app/strings without parameters returns the default strings
    • appium/app/strings with the language parameter returns the strings for that language if they exist in the app or the default app strings if not
    opened by rgonalo 4
  • Added secure server flag to fromHostAndPort call for https servers.

    Added secure server flag to fromHostAndPort call for https servers.

    The selenium server is resolve by concatenation in PHPUnit_Extensions_Selenium2TestCase_URL:: fromHostAndPort in URL.php. To add support for https server this PR has been made. To reflect these changes in the Appium client the call to the method fromHostAndPort needs to be made using with the secure flag in its parameters.

    opened by pankaj-a 2
  • BadParametersError: Parameters were incorrect. We wanted {

    BadParametersError: Parameters were incorrect. We wanted {"required":["value"]} and you sent ["value",":id"]

    I see the latest version doesn't work with API sendKeys, I tried with several requests as Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, accessibility id. Please see more info below:

    Versions: PHPUnit 5.7.17 Appium version: 1.6.3 iOS device: 10.2 (real device)

    Client script:

    <?php
    class iOSWebTest extends PHPUnit_Framework_TestCase {
      protected $driver;
      public function test_should_search_Google() {
        $desired_caps = array(
          'browserName'         => 'Safari',
          'platformName'        => 'iOS',
          'deviceName'          => 'iPhone 5s',
          'deviceOrientation'   => 'portrait'
        );
        $SERVER_URL = "http://127.0.0.1:4723/wd/hub";
        $this->driver = RemoteWebDriver::create($SERVER_URL, $desired_caps,
        $connection_timeout_in_ms = 300000,
        $request_timeout_in_ms = 300000);
        $this->driver->get("https://www.google.com");
        $this->driver->findElement(WebDriverBy::name("q"))->sendKeys("Google");
        $this->driver->findElement(WebDriverBy::name("btnG"))->click();
        sleep(3);
        $this->assertContains("Google", $this->driver->getTitle());
        $this->driver->quit();
      }
    }
    

    Error:

    Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":["value"]} and you sent ["value",":id"]
    
    opened by khanhdodang 2
  • Add touchId command

    Add touchId command

    Added test for it (no assertions just test that it doesn't throw an exception). Updated test platformVersion to 10.1 and renamed the fields from UIA to XCUIElementType

    opened by dpgraham 2
  • ->elements(...) on a PHPUnit_Extensions_AppiumTestCase_Element is broken

    ->elements(...) on a PHPUnit_Extensions_AppiumTestCase_Element is broken

    The method attempts to run

    $session = $this->prepareSession();
    

    However. $this doesn't have a method prepareSession at all. It looks like this method shouldn't be trying to prepare its own session, but instead should mimic the element function.

    A working method would look like:

    $values = $this->postCommand('elements', $criteria);
    $elements = array();
    foreach ($values as $value) {
        $elements[] =
                PHPUnit_Extensions_AppiumTestCase_Element::fromResponseValue(
                $value, $this->getSessionUrl()->descend('element'), $this->driver);
        }
    return $elements;
    
    opened by quintstoffers 2
  • New session could not be created with appium 1.2.0

    New session could not be created with appium 1.2.0

    Hello,

    I download the php project, then I launch appium (in console mode) on win 7 SP1.

    Test is launched, but I've got the following error : """ php phpunit context_tests.php PHPUnit 4.1.3 by Sebastian Bergmann.

    EEEEEE

    Time: 10.32 seconds, Memory: 4.75Mb

    There were 6 errors:

    1. ContextTests::testCurrentContext PHPUnit_Extensions_Selenium2TestCase_WebDriverException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName)

    [...]\PHPUnit\Extensions\AppiumTestCase\Driver.php:39 [...]\PHPUnit\Extensions\AppiumTestCase\SessionStrategy\Isolated.php:30

    1. ContextTests::testMoveToCorrectContext PHPUnit_Extensions_Selenium2TestCase_WebDriverException: A new session could not be created. (Original error: The following desired capabilities are required, but were not provided: platformName, deviceName)

    etc. """

    opened by makiavelik 2
  • $driver

    $driver

    Not so much an issue but a question. I have seen examples like

    $driver->hideKeyboard(); $driver->hideKeyboard(array( 'keyName' => 'Done' ));

    and was just wondering how to intialise $driver correctly, or can I just use $this->hideKeyboard(); instead?

    opened by C14427818 1
  • Appium PHP error on cmd

    Appium PHP error on cmd

    Hi everyone,

    Can you help me fix this issue, i'm getting this error when I execute in CMD:

    phpunit bot.php

    PHP Fatal error: Class 'PHPUnit_Extensions_Selenium2TestCase_Command' not found in D:\xampp\htdocs\shopeephp\PHPUnit\Extensions\AppiumTestCase\SessionCommand\Context.php on line 18

    opened by lemueloodle 1
  • Add getDeviceTime method

    Add getDeviceTime method

    Resolves https://github.com/appium/php-client/issues/28

    Reference https://github.com/appium/node-mobile-json-wire-protocol/issues/40

    Please review @imurchie

    opened by scottdixon-zz 1
  • what this?

    what this?

    Warning: require_once(PHPUnit/Extensions/AppiumTestCase.php): failed to open stream: No such file or directory in E:\home\appium\php\php-client\vendor\phpunit\phpunit\test.php on line 3

    Fatal error: require_once(): Failed opening required 'PHPUnit/Extensions/AppiumTestCase.php' (include_path='.;C:\php\pear') in E:\home\appium\php\php-client\vendor\phpunit\phpunit\test.php on line 3

    说实话,你写的代码很垃圾~

    opened by bpshou 0
  • Setting desired capabilities

    Setting desired capabilities

    Is there a way to set the capabilities in a different .inc or .PHP file and pass then to the appium script?? All the examples have the capabilities in the same file. Any help is greatly appreciated.

    opened by C14427818 0
  • Undefined index: secure

    Undefined index: secure

    Hello,

    I am using your code sample:

    require_once('PHPUnit/Extensions/AppiumTestCase.php');
    require_once('PHPUnit/Extensions/AppiumTestCase/Element.php');
    
    class MySuperTests extends PHPUnit_Extensions_AppiumTestCase
    {
        public static $browsers = array(
            array(
                'local' => true,
                'port' => 4723,
                'browserName' => '',
                'desiredCapabilities' => array(
                    'app' => APP_PATH
                )
            )
        );
    
        public function testStuff()
        {
            $element = $this->byAccessibilityId('Element on screen');
    
            $this->assertInstanceOf('PHPUnit_Extensions_AppiumTestCase_Element', $element);
        }
    }
    

    The following error occurred: Undefined index secure. I think it was at fault appium/php-client/PHPUnit/Extensions/AppiumTestCase/SessionStrategy/Isolated.php@session line 24. 'secure' does not exist in variable parameters when start session.

    Can you help me ?

    opened by thuyhyvg 1
  • bump up phpunit/phpunit-selenium since current master only support secure parameter

    bump up phpunit/phpunit-selenium since current master only support secure parameter

    do not merge this yet.

    Currently, https://github.com/giorgiosironi/phpunit-selenium/releases/tag/4.1.0 is the latest phpunit/phpunit-selenium released version.

    After the release, a secure parameter has been added. After https://github.com/appium/php-client/pull/46 , this client also can work with the secure parameter. But the change breaks under 4.1.0.

    This PR is just remark for making sure current master need the latest phpunit/phpunit-selenium

    opened by KazuCocoa 1
  • Appium Php Error: You must include a platformName capability

    Appium Php Error: You must include a platformName capability

    Hi,

    I'm new to appium. I write my first script and executed its throwing below error. Below same Capabilities working Appium desktop Session.

    My Code:

    require_once "vendor/autoload.php";

    class MySuperTests extends PHPUnit_Extensions_AppiumTestCase { public static $browsers = array( array( 'host' => true, 'port' => 4444, 'browserName' => '', 'desiredCapabilities' => array( 'app' => 'D:\xamp\htdocs\appium\sample-code\examples\test\myapp.apk', 'platformName' => 'Android', 'platformVersion' => '7.0', 'deviceName' => 'emulator-5551' ) ) );

    // this fails for some reason
    public function testInstallApp()
    {
        $this->installApp('D:\xamp\htdocs\appium\sample-code\examples\test\myapp.apk');
    }
    

    }

    $obj = new MySuperTests(); $obj->testInstallApp();

    Got Below Error:

    [info] [Appium] Welcome to Appium v1.7.2 [info] [Appium] Non-default server args: [info] [Appium] address: localhost [info] [Appium] port: 4444 [info] [Appium] Appium REST http interface listener started on localhost:4444[info] [HTTP] --> POST /wd/hub/session {"desiredCapabilities":{"browserName":""}} [debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [{"browserName":""},null,null] [debug] [BaseDriver] Event 'newSessionRequested' logged at 1524208895020 (12:51:35 GMT+0530 (India Standard Time)) [error] [MJSONWP] Encountered internal error running command: Error: You must include a platformName capability at AppiumDriver.getDriverForCaps (C:\Users\testuser\AppData\Local\appium-desktop\app-1.5.0\resources\app\node_modules\appium\lib\appium.js:66:13)

    Please suggest me what i did wrong. I was executed php using command line D:\xamp\htdocs\appium\sample-code\examples\test>php mytest.php

    Thanks, Jay

    opened by jeyakumarsbe 0
  • Missing mobile gestures for iOS (XCUITest)

    Missing mobile gestures for iOS (XCUITest)

    There are several methods in Appium (Java) which are useful in doing mobile gestures on iOS as listed here..

    https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/ios-xctest-mobile-gestures.md

    https://github.com/appium/appium/blob/93271330365a17408f94ae502d98b70c1cd34636/docs/en/writing-running-appium/ios/ios-xctest-mobile-gestures.md

    Can we please add the same on appium-php client ?

    opened by ghost 0
Releases(v0.2.0)
Owner
Appium Boneyard
Defunct Appium-related Code
Appium Boneyard
Create and manage advanced polls with this Telegram Bot which has many features available!

MasterPollBot Create and manage advanced polls with this Telegram Bot which has many features available! Requirements Local Telegram Bot API or a webh

NeleB54Gold 7 Oct 21, 2022
BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

BeckhoffPLCSoapClient - SoapClient to communicate with BeckHoff PLC. Library made in PHP based on TcAdsWebService JavaScript Library.

null 3 May 18, 2022
A framework agnostic PHP library to build chat bots

BotMan If you want to learn how to create reusable PHP packages yourself, take a look at my upcoming PHP Package Development video course. About BotMa

BotMan 5.8k Jan 3, 2023
PHP library for the Stripe API.

Stripe PHP bindings The Stripe PHP library provides convenient access to the Stripe API from applications written in the PHP language. It includes a p

Stripe 3.3k Jan 5, 2023
A PHP library for communicating with the Twilio REST API and generating TwiML.

twilio-php The default branch name for this repository has been changed to main as of 07/27/2020. Documentation The documentation for the Twilio API c

Twilio 1.4k Jan 2, 2023
A PHP library for the Campaign Monitor API

createsend A PHP library which implements the complete functionality of the Campaign Monitor API. Installation Composer If you use Composer, you can r

Campaign Monitor 287 Jan 6, 2023
PHP 5.3+ library which helps you to interact with the DigitalOcean API

DigitalOcean The version 2 of the API will be available soon ! Please visit DigitalOceanV2 and contribute :) This PHP 5.3+ library helps you to intera

Antoine Kirk 156 Jul 30, 2022
A versatile PHP Library for Google PageSpeed Insights

PhpInsights An easy-to-use API Wrapper for Googles PageSpeed Insights. The JSON response is mapped to objects for an headache-free usage. Installation

Daniel Sentker 110 Dec 28, 2022
PHP library for the GitHub API v3

GitHub API v3 - PHP Library Currently under construction. Overview Provides access to GitHub API v3 via an Object Oriented PHP library. The goal of th

Darren Rees 62 Jul 28, 2022
PHP library to use IOTA REST API to help node management and tangle queries

iota.php About PHP library to use IOTA REST API to help node management and tangle queries. Please be aware that this library is in an early developme

IOTA Community 45 Dec 13, 2022
oursms.app client library that allows you to send SMS

Oursms laravel client https://oursms.app client library that allows you to send SMS Installation Install oursms client with composer composer requir

Khalid Mohammad 11 Aug 27, 2022
A Class Library enabling Asterisk ARI functionality for PHP

phpari A Class Library enabling Asterisk ARI functionality for PHP Dependencies These are the minimum requirements to have phpari installed on your se

Nir Simionovich 87 Jan 5, 2023
NovaGram - An elegant, Object-Oriented, reliable PHP Telegram Bot Library

An elegant, Object-Oriented, reliable PHP Telegram Bot Library Full Documentation • Public support group Examples • Features • Installation ?

Gaetano 165 Jan 6, 2023
PHP library for the ArvanCloud API

PHP ArvanCloud API PHP library for the ArvanCloud API. This package supports PHP 7.3+. For Laravel integration you can use mohammadv184/arvancloud-lar

Mohammad Abbasi 5 Apr 29, 2022
A library written in PHP to interact with Coinbase Pro via API.

A library written in PHP to interact with Coinbase Pro via API.

Blake Hamilton 4 Mar 31, 2022
Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API

Upload Vimeo video with CodeIgniter, Official PHP library for the Vimeo API. Vimeo Video upload with API using Official PHP library for the Vimeo API.

WordPress theme and Plugins developers 2 Oct 10, 2021
Lightweight PHP library for WhatsApp API to send the whatsapp messages in PHP provided by ultramsg.com

Ultramsg.com WhatsApp API PHP SDK Lightweight PHP library for WhatsApp API to send the whatsappp messages in PHP provided by Ultramsg.com Installation

Ultramsg 117 Dec 26, 2022
The Universal Device Detection library will parse any User Agent and detect the browser, operating system, device used (desktop, tablet, mobile, tv, cars, console, etc.), brand and model.

DeviceDetector Code Status Description The Universal Device Detection library that parses User Agents and detects devices (desktop, tablet, mobile, tv

Matomo Analytics 2.4k Jan 9, 2023
Google-api-php-client - A PHP client library for accessing Google APIs

Google APIs Client Library for PHP Reference Docs https://googleapis.github.io/google-api-php-client/main/ License Apache 2.0 The Google API Client Li

Google APIs 8.4k Dec 30, 2022