Code Monkey home page Code Monkey logo

appium-driver-codeception's Introduction

Appium Driver for Codeception

Appium driver for codeception for writing mobile tests.


Build Status downloads MIT License Donate

All Contributors PRs Welcome Code of Conduct Watch on GitHub Star on GitHub Tweet

Requirement

  1. PHP >= 7.0
  2. Appium
  3. Inspect App with Appium Desktop
  4. Devices:
    • Android
    • iOS
      • Install Xcode from the following link or run the following command inside your terminal:
        xcode-select --install
      • Install the Carthage dependency manager:
        brew install carthage

Table of Contents

Install

Just add me-io/appium-driver-codeception to your project's composer.json file:

{
    "require": {
        "me-io/appium-driver-codeception": "~1"
    }
}

and then run composer install. This will install codeception appium driver and all it's dependencies. Or run the following command

composer require me-io/appium-driver-codeception

Tests

Now lets run the following command at the root directory of your project:

codecept bootstrap

This command will creates a configuration file for codeception and tests directory and default test suites.

Writing tests for Android

Now, lets create a new configuration file android.suite.yml inside tests directory and put the following contents inside of it.

class_name: AndroidGuy
modules:
  enabled:
    # Enable appium driver
    - \Appium\AppiumDriver 
    -  Asserts
  config:
    # Configuration for appium driver
    \Appium\AppiumDriver:
      host: 0.0.0.0
      port: 4723
      dummyRemote: false
      resetAfterSuite: true
      resetAfterCest: false
      resetAfterTest: false
      resetAfterStep: false
      capabilities:
        platformName: 'Android'
        deviceName: 'Android device'
        automationName: 'Appium'
        appPackage: io.selendroid.testapp
        fullReset: false
        noReset: false
        newCommandTimeout: 7200
        nativeInstrumentsLib: true
        connection_timeout: 500
        request_timeout: 500
        autoAcceptAlerts: true
        appActivity: io.selendroid.testapp.HomeScreenActivity
        skipUnlock: true

Note: deviceName should be set as Android device only for real device. For Android Emulator use the name of the virtual device.

Writing tests for iOS

Now, lets create a new configuration file ios.suite.yml inside tests directory and put the following contents inside of it.

class_name: IosGuy
modules:
  enabled:
    # Enable appium driver
    - \Appium\AppiumDriver
    -  Asserts
  config:
    # Configuration for appium driver
    \Appium\AppiumDriver:
      host: 0.0.0.0
      port: 4723
      dummyRemote: false
      resetAfterSuite: true
      resetAfterCest: false
      resetAfterTest: false
      resetAfterStep: false
      capabilities:
        # PATH OF YOUR APP (something like  /Users/username/Documents/ios.app)
        app: ''
        # xcideOrgId is Apple developer team identifier string.
        xcodeOrgId: ''
        # xcodeSigningId is a string representing a signing certificate. iPhone Developer by default.
        xcodeSigningId: 'iPhone Developer'
        platformName: 'iOS'
        platformVersion: '11.2'
        deviceName: 'iPhone8'
        # Your device udid
        udid: ''
        useNewWDA: false
        newCommandTimeout: 7200
        automationName: 'XCUITest'
        autoAcceptAlerts: true
        fullReset: false
        noReset: true
        nativeInstrumentsLib: true
        connection_timeout: 500
        request_timeout: 500
        skipUnlock: true
        clearSystemFiles: true
        showIOSLog: true

Generating Actor classes

Now we need to generate actor class for the AndroidGuy/IosGuy that we defined in android.suite.yml/ios.suite.yml. To generate the actor class for AndroidGuy/IosGuy run the following command inside your terminal:

codecept build

Your First Android Test

To create your first android test create a new directory android inside tests folder. After creating the android folder create a new file FirstAndroidCest.php and put the following contents inside of it:

class FirstAndroidCest
{
    public function changeLanguage(AndroidGuy $I)
    {
        $I->implicitWait([
            'ms' => 3500,
        ]);
        $text = $I->byId('id_of_button')->getText();
        $I->assertEquals('Hello, World!', $text);
    }
}

Your First iOS Test

To create your first iOS test create a new directory ios inside tests folder. After creating the ios directory create a new file FirstIosCest.php and put the following contents inside of it:

class FirstIosCest
{
    public function lockPhone(Ios $I)
    {
        $I->implicitWait([
            'ms' => 10000,
        ]);
        $I->assertEquals('Hello, World!', 'Hello, World!');
        $I->amGoingTo("lock phone");
        $I->lock([null]);
    }
}

Running tests

Run the appium server by running the following command:

appium

NOTE: If you want to change IP/Port run the appium command like this:

appium -a <IP Address> -p <Port>

After running the appium server now you need to start android emulator and install the application that you want to test. If you don't know how to start the emulator you can follow the following guide Setup Genymotion Android Emulators on Mac OS

Now run the following command inside your terminal to run the tests:

# For Android
codecept run android FirstAndroidCest.php --steps

# For iOS
codecept run ios FirstIosCest.php --steps

Note: While following the steps that are mentioned here if you get codecept command not found error try to run codecept command like this ./vendor/bin/codecept.

Contributors

A huge thanks to all of our contributors:


Mohamed Meabed

๐Ÿ’ป ๐Ÿ“ข

Zeeshan Ahmad

๐Ÿ’ป ๐Ÿ› โš ๏ธ ๐Ÿ“–

License

The code is available under the MIT license.

appium-driver-codeception's People

Contributors

adbrvn avatar aheermohsinse avatar anooptajawal avatar dependabot[bot] avatar meabed avatar raleerg avatar walterwhites avatar ziishaned avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

appium-driver-codeception's Issues

Filling form or any input element is not clear how to use it

I am trying to fill form in website using browser on android device, and they problem is there is no clear way to locate the element

  • PHP Version: 7.2
  • Appium Version: latest
  • Codeception Version: 2.4.2

Description:

1-I am trying to open chrome on android device and register form
So far I was able to : 1-Open chrome 2-click on button

$data = array('url'=>"myUrl");
       $I->setUrl($data);
       $I->getUrl();
       $I->implicitWait([ 'ms' => 3500, ]);
       $I->byCssSelector('#container-calculator > form > 
       div.calculator__button.calculator__button--promocode.form-group > a')
         ->click();

But when it came to sendkeys (filling input element),
There is no clear way how to do that, can please provide me with clear example!

Steps To Reproduce:

When I check the your code:

  /**
     * @param Element $element that accepts a string
     * @param string $keys send to $element
     * @return \PHPUnit_Extensions_Selenium2TestCase_Response
     */
    public function sendKeys($element, $keys)
    {
        return $element->setValueImmediate($keys);
    }

The problem is here you can't get the elementby ID like this:

`$I->getElement('#f_Last_Name');`
or other ways I tried 

Please add clear example how to open browser and fill form in android and Ios 

"You must include a platformName capability" not recognizing from .yml file

I've been trying to connect to the android emulator, even the iOS and the add on won't let me do it. This is mine .yml file:
- \Appium\AppiumDriver: host: '0.0.0.0' port: '4723' dummyRemote: false capabilities: platformName: 'Android' app: '.../app.apk' deviceName: 'Nugget'

Am I missing something?

Stack trace in Appium:

[debug] [BaseDriver] Event 'newSessionRequested' logged at 1500918493543 (12:48:13 GMT-0500 (CDT))
[MJSONWP] Encountered internal error running command: Error: You must include a platformName capability
    at AppiumDriver.getDriverForCaps (../../lib/appium.js:44:13)
    at AppiumDriver.createSession$ (../../lib/appium.js:157:28)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
    at Promise (<anonymous>)
    at F (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
    at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
    at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
    at AppiumDriver.createSession (../../lib/appium.js:183:31)
    at ../../../lib/basedriver/driver.js:207:24
    at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/promise.js:510:31)
    at Promise._settlePromiseAt (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/promise.js:584:18)
    at Promise._settlePromiseAtPostResolution (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/promise.js:248:10)
    at Async._drainQueue (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/async.js:15:14)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5)
[HTTP] <-- POST /wd/hub/session 500 63 ms - 179
[HTTP] --> POST /wd/hub/session {"desiredCapabilities":[]}
[debug] [MJSONWP] Calling AppiumDriver.createSession() with args: [[],null,null]
[debug] [BaseDriver] Event 'newSessionRequested' logged at 1500918595485 (12:49:55 GMT-0500 (CDT))
[MJSONWP] Encountered internal error running command: Error: You must include a platformName capability
    at AppiumDriver.getDriverForCaps (../../lib/appium.js:44:13)
    at AppiumDriver.createSession$ (../../lib/appium.js:157:28)
    at tryCatch (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:67:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:315:22)
    at GeneratorFunctionPrototype.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at invoke (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:136:37)
    at enqueueResult (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:185:17)
    at Promise (<anonymous>)
    at F (/usr/local/lib/node_modules/appium/node_modules/core-js/library/modules/$.export.js:30:36)
    at AsyncIterator.enqueue (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:184:12)
    at AsyncIterator.prototype.(anonymous function) [as next] (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:100:21)
    at Object.runtime.async (/usr/local/lib/node_modules/appium/node_modules/babel-runtime/regenerator/runtime.js:209:12)
    at AppiumDriver.createSession (../../lib/appium.js:183:31)
    at ../../../lib/basedriver/driver.js:207:24
    at tryCatcher (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/util.js:26:23)
    at Promise._settlePromiseFromHandler (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/promise.js:510:31)
    at Promise._settlePromiseAt (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/promise.js:584:18)
    at Promise._settlePromiseAtPostResolution (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/promise.js:248:10)
    at Async._drainQueue (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/async.js:128:12)
    at Async._drainQueues (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/async.js:133:10)
    at Immediate.Async.drainQueues [as _onImmediate] (/usr/local/lib/node_modules/appium/node_modules/bluebird/js/main/async.js:15:14)
    at runCallback (timers.js:781:20)
    at tryOnImmediate (timers.js:743:5)
    at processImmediate [as _immediateCallback] (timers.js:714:5) ```

removeApp() or isAppInstalled() fail: Parameters were incorrect

  • PHP Version: 7.2.7
  • Appium Version: 1.8.1
  • Codeception Version: 2.4.4

Description:

Steps To Reproduce:

Have installed an Android app and try to remove it using:
$I->removeApp('com.myapp.android.beta');

Expected result:

  • no issue

Actual result:

  • codeception log:
    [BadMethodCallException] Something unexpected happened: 'Parameters were incorrect. We wanted {"required":[["appId"],["bundleId"]],"optional":["options","sessionId","id"]} and you sent []'

  • appium.log:

2018-07-26 18:35:27:378 - info: [HTTP] --> POST /wd/hub/session/c5dfc606-2c2c-4d02-9ba9-31ba49c34fb4/appium/device/remove_app
2018-07-26 18:35:27:379 - info: [HTTP] {}
2018-07-26 18:35:27:383 - info: [debug] [MJSONWP] Bad parameters: BadParametersError: Parameters were incorrect. We wanted {"required":[["appId"],["bundleId"]],"optional":["options","sessionId","id"]} and you sent []
2018-07-26 18:35:27:389 - info: [HTTP] <-- POST /wd/hub/session/c5dfc606-2c2c-4d02-9ba9-31ba49c34fb4/appium/device/remove_app 400 9 ms - 130

I tested it also in CodeceptJS and it's working there:

I.removeApp('com.myapp.android.beta');

  • appium log:
2018-07-26 18:46:32:281 - info: [HTTP] --> POST /wd/hub/session/78919c5b-4b7f-416a-921d-45ff933622c4/appium/device/remove_app
2018-07-26 18:46:32:281 - info: [HTTP] {"bundleId":"com.myapp.android.beta"}
2018-07-26 18:46:32:282 - info: [debug] [MJSONWP] Calling AppiumDriver.removeApp() with args: ["com.myapp.android.beta",null,null,null,"78919c5b-4b7f-416a-921d-45ff933622c4"]

Declaration of Appium\AppiumDriver::_closeSession($AppiumSession)

PHP Fatal error: Declaration of Appium\AppiumDriver::_closeSession($AppiumSession) must be compatible with Codeception\Lib\Interfaces\MultiSession::_closeSession($session = NULL) in D:\GitHub\NairaShop\vendor\tajawal\codeception-appium\src\AppiumDriver.php on line 32

Please, change this to
public function _closeSession($AppiumSession = NULL) at Appium\AppiumDriver::_closeSession($AppiumSession) line 295 to make it work

Supports codeception 4.1

Description:

Hello. Do you have the option to update the extension so that it supports codeception 4.1? Right now it only supports version 2

Composer is not able to find this library

The requested package tajawal/codeception-appium could not be found in any version, there may be a typo in the package name.

Is there another way to get this package?

New functions added to driver

I've been using the AppiumDriver and have added some new functions to it, how can I contribute to the repository?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.