Get started with mobile automation: Appium & Python

Problem: There is a perception among testers that getting started with mobile automation is hard.

Why this post?

I strongly believe that a tester must have a wide range of skills. You do not need to be an expert in all of them, but it is extremely important to have contemplated a spectrum of concepts and explored a variety of tools. The context under which you test will inform you of the specific choice of testing methodology and test tools to choose. The more options you are aware of, the better your context specific choice is going to be. In this regard, I began noticing that mobile testing has become somewhat of a niche among testers. Testers are reluctant to get started with mobile testing – probably because they think getting started involves a lot of time and effort. At Qxf2 Services, we have decided to tackle the problem head on. This post is the second in a series of quick, easily consumable tutorials geared towards hands-on testers looking to start exploring the mobile testing landscape.

NOTE: In this post we are concentrating only on the “getting started” phase. The tools your test team uses to solve the specific and unique problems can greatly vary. There is no one silver bullet.


A little bit of history

On the eve of Christmas 2013, Selenium officially retired their own AndroidDriver and iPhoneDriver in favour of Selendroid, iosdriver and Appium. In an earlier post we explored using Selendroid and Python. In this post, we will help you get started with Appium.

Appium is an open-source tool you can use to automate mobile native, mobile web, and mobile hybrid applications on iOS and Android platforms. Appium is “cross-platform”: it allows you to write tests against multiple platforms (iOS, Android), using the same API. This enables a large or total amount of code reuse between iOS and Android testsuites.


Appium setup

Here are the steps to setup Appium on Windows 7 and use it with Android emulator.
1. Download the latest Appium
I have used AppiumForWindows-1.0.0.zip. Verify that Node.exe is available after you unzip Appium, else you can download the same from http://nodejs.org/download/
2. Install the Android SDK
You will need to run the ‘android’ tool (included in the SDK) and make sure you have an API Level 17 or greater API installed. Set ANDROID_HOME to be your Android SDK path and add the tools and platform-tools folders to your PATH variable.
set_android_home
3. Install the Java JDK
Set JAVA_HOME to your JDK folder
4. Install the Python client library
There are client libraries (in Java, Ruby, Python, PHP, JavaScript, and C#) which support Appium’s extensions to the WebDriver protocol. When using Appium, you want to use these client libraries instead of your regular WebDriver client.I have used the Appium Python client available here. Assuming you have pip installed on your machine, you can use the following command to install it

pip install Appium-Python-Client

Woot! You are now setup. Next stop: launch the emulator and start the appium server.

5. Start the Android Virtual Device (AVD) Manager
Start the Android Virtual Device (AVD) Manager from the command line by calling the android tool with the avd options, from the /tools/ directory.
android_start_avd
Create an emulator with the preferences you need and launch it using the start button
android_emulator
6. Start the Appium server console
Start the Appium server console by double clicking on the Appium file.
start_appium
7. Launch the Appium node server
Click on the ‘rocket’ icon to launch the Appium node server
appium_server_settings
appium_node_server_console


Your first test using Appium

For this test we will use one of my favorite Android apps – the highly recommended Chess Free application created by the UK based AI Factory. For this blog post, we will pretend that our test is to launch the application and navigate to ‘Single Player’ mode.

1. Obtain the .apk for the application under test
We obtained the .apk for Chess Free over here. Copy the chess application to a directory of your choice. I used ($Directory_Of_My_Choice\apps\Chess Free.apk )
2. Peek into the AndroidManifest.xml
To write the test, you need two pieces of information specific to your application:
a) Java package of the Android app you want to run
b) Activity name for the Android activity you want to launch from your package

You can get this information by running the following command

ANDROID_HOME\sdk\build-tools\android-4.4.2>aapt dump badging path_to_apk_file

aapt_pkg_activity

Another approach is using the AndroidManifest.xml which is present in the root directory of all Android applications that has the information we need. I followed the how-to here, extracted the AndroidManifest.xml and located

package="uk.co.aifactory.chessfree" and 
android:name=".ChessFreeActivity"

3. Write the test
Create a test script (android_chess.py) in $Directory_Of_My_Choice based on the snippet below. Pay particular attention to the setup() method.

"""
Qxf2: Example script to run one test against the Chess Free app using Appium
The test will:
- launch the app
- click the 'PLAY!' button
- choose single player mode 
"""
 
import os
import unittest
from appium import webdriver
from time import sleep
 
class ChessAndroidTests(unittest.TestCase):
    "Class to run tests against the Chess Free app"
    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.2'
        desired_caps['deviceName'] = 'Android Emulator'
        # Returns abs path relative to this file and not cwd
        desired_caps['app'] = os.path.abspath(os.path.join(os.path.dirname(__file__),'apps/Chess Free.apk'))
        desired_caps['appPackage'] = 'uk.co.aifactory.chessfree'
        desired_caps['appActivity'] = '.ChessFreeActivity'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
 
    def tearDown(self):
        "Tear down the test"
        self.driver.quit()
 
    def test_single_player_mode(self):
        "Test the Single Player mode launches correctly"
        element = self.driver.find_element_by_name("PLAY!")
        element.click()
        self.driver.find_element_by_name("Single Player").click()
        textfields = self.driver.find_elements_by_class_name("android.widget.TextView")
        self.assertEqual('MATCH SETTINGS', textfields[0].text)
 
#---START OF SCRIPT
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

4. Run the test
Run the script android_chess.py. The chess application is launched in the test emulator
chess_emulator
5. Check the result
appium_test_run

Celebrate a little – you just upgraded your skills by a little bit in a very short span of time!

There you have it! You have just run your first mobile automated test with Appium and Python. Happy exploring from Qxf2 Services!

P.S.: As a chess fanatic, I think it is a crime to test chess applications in an automated fashion. I sincerely believe infinite manual testing is the only correct way to test chess applications 😉

P.P.S: We were pleasantly surprised by positive reaction we got to our last tutorial on mobile application testing with Selendroid. Please chime in on the direction you want our future blog posts to go. We will try our best to keep churning out useful posts for testers.

Vrushali Toshniwal
My journey as a tester started at Sun Microsystems (now Oracle). I was part of the testing and sustaining team for the Portal Server and Identity Management products. My first assignment was to test the Rewriter module. I enjoyed understanding the big picture, writing test cases, finding bugs and sometimes suggesting the fix too! I was hooked onto testing. Testing felt natural and intuitive to me. I am technically inclined and can write automation in Java, C++, Perl and Python. I am well versed with SilkTest, Selenium, Appium and Selendroid. I am a Computer Science graduate from BITS-Pilani. I love travelling and listening to music.

© 2013-2017, Vrushali Toshniwal. All rights reserved.

88 Comments

  1. The idea behind UI automation is to test the app as a user would. But i think, reusing test code is going to be a challenge when comparing web automation to native app automation. To test with more than one Android device locally, you need to have one Appium server per device. Good article.

    July 8, 2014
    Reply
    • Avinash Shetty Qxf2 said:

      Thanks for the comments! This post was just on getting started with mobile automation using appium. You can also run your test directly on cloud using Saucelabs. You can refer to our blog on Mobile Automation using appium and sauce-labs.

      July 9, 2014
      Reply
  2. Aravind said:

    If any steps to setup Appium on Ubuntu and use it with Android emulator can be provided, then it would be of great help.

    July 25, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Aravind, I have not tried getting Appium on Ubuntu. I’m adding it to my to do list. I will try to install Appium on Ubuntu in the next 3 weeks. I’m giving you a high level answer here just in case you are in a hurry.

      Since I am not in a position to try this right away, I did some extra high level research. Appium is written in JavaScript and powered by Node.js. There is a dependency on grunt too – which is like (not exactly but like) a build tool for JavaScript. Grunt lets JavaScript developers automate repetitive tasks like minifying scripts, running tests, etc. Node has its own eco system and uses NPM (Node Package Manager) to make installations easy. Its like APT for Ubuntu. Hopefully this gives you better context as you execute steps listed online.

      I did Google around for common pitfalls and found these:
      a) few people have trouble because they were running older versions of node. Apparently you need node 0.1 and above
      b) few people warn that appium may not work if you installed node with sudo user

      All in all, this answer on stackoverflow seems to be safest approach to installing Appium on Ubuntu. If you solve this problem before me, please post your answer here.

      July 26, 2014
      Reply
  3. Raj said:

    Thanks a lot.
    Very useful article.

    September 10, 2014
    Reply
  4. madhubabu said:

    I want to learn “appium” ,i am a java programmer and i have knowledge on Webdriver ,can anybody help me to learn Appium.
    Thanks in advance…….

    September 18, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Madhubabu, our experience with Java and Appium is extremely limited. However, one thing that helped us get started with Appium and Python was the concept behind Appium. Think of Appium as three parts:

      1. Appium implements a some subset of webdriver methods (technically the REST API of webdriver aka webdriver JSON wire protocol).

      2. Appium lets you interface with mobile devices by extending this webdriver implementation.

      3. Appium also has added some functionality unique to mobile devices – swipe, flick, etc.

      If you are already familiar with webdriver, I would suggest that you start with a simple app. Then figure out how to set the “desired capabilities”. Finally figure out the different webdriver calls implemented by Appium. Hope this helps!

      September 18, 2014
      Reply
  5. varun said:

    Thanks,Article was really Helpful,though i was new to selenium i was able to run the Appium.

    September 18, 2014
    Reply
  6. priya said:

    Hi ,

    I am doing ioS Mobile automation testing for Native application.

    I am getting an system generated location alert “… would like to use your Current Location”while opening the application in simulator . I am not able to handle this with Selenium as i am not able to capture this alert box using Inspector .

    Is there any way to handle this with the help of capabilities (while setting the capabilities ) .I am using the below code :
    capabilities.setCapability(CapabilityType.VERSION, “7.0”);
    capabilities.setCapability(CapabilityType.PLATFORM, “Mac”);
    capabilities.setCapability(“Device”, “iPhone Simulator”);
    capabilities.setCapability(“app”,”/Users/test/EclipseMediaSourceTree/EclipseMedia/build/Release-iphonesimulator/EclipseMedia.app”);*/
    //capabilities.setCapability(“app”,”sauce:storage:EclipseMedia.app.zip”);

    try{
    driver = new RemoteWebDriver(
    new URL(remoteDriverURL), capabilities);
    }

    I am using Java + Appium + Web Driver +Sikuli.

    Please help on this .

    September 26, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Priya, can you check if adding capabilities.setCapability(“autoAcceptAlerts”, true); works with your version of Appium?

      September 26, 2014
      Reply
  7. B said:

    Hi there, I am new to Appium. I followed all the steps and when I was running it I keep getting some URLError. Do you know what I missed? Thx very much!

    This is what I got from the console:
    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly … ERROR

    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “C:\Users\bonnie.donnels\workspace\Emn8_automation\BKLoyalty\Test_Appium\testappium.py”, line 42, in setUp
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
    File “C:\Python27\Lib\site-packages\appium\webdriver\webdriver.py”, line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “C:\Python27\Lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\Lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 121, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\Lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 171, in execute
    response = self.command_executor.execute(driver_command, params)
    File “C:\Python27\Lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 349, in execute
    return self._request(command_info[0], url, body=data)
    File “C:\Python27\Lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 417, in _request
    resp = opener.open(request)
    File “C:\Python27\Lib\urllib2.py”, line 404, in open
    response = self._open(req, data)
    File “C:\Python27\Lib\urllib2.py”, line 422, in _open
    ‘_open’, req)
    File “C:\Python27\Lib\urllib2.py”, line 382, in _call_chain
    result = func(*args)
    File “C:\Python27\Lib\urllib2.py”, line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
    File “C:\Python27\Lib\urllib2.py”, line 1184, in do_open
    raise URLError(err)
    URLError:

    ———————————————————————-
    Ran 1 test in 1.009s

    FAILED (errors=1)

    October 9, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      My hunches based on your error is that:
      1. Appium server is not up and running (steps 6 & 7 in the Appium Setup section)
      2. Appium server is running on a port other than 4723 (use netstat or TCPView on Windows to confirm)
      3. localhost may not be getting resolved to 127.0.0.1 (try changing your URL from http://localhost:4723/wd/hub to http://127.0.0.1:4723/wd/hub and try)

      Let me know if none of the hunches are right and we can go looking for more possibilities.

      October 10, 2014
      Reply
      • B said:

        Thank so much!! I made sure that the Appium server is running correctly and also I checked port 4723 which is working fine. Now, I have another issue.

        I keep getting the following error:
        error: Unhandled error: Error: ENOENT, no such file or directory ‘C:\android_sdk_adt_bundle\android_sdk;\build-tools’

        First, I don’t find ‘ENOENT’ in the directory; Second, I do not know why there is ‘;’ after … android_sdk directory.

        So now I am facing a new problem.

        Thanks very much!

        October 11, 2014
        Reply
        • Arunkumar Muralidharan Qxf2 said:

          ENOENT error is NodeJS complaining. Can you check these two things:
          1. (highly likely) Does your ANDROID_HOME has an extra semi-colon at the end? If it does, remove the semi-colon, restart the appium server, open up a new command prompt and then try running the test again.
          2. (unlikely but possible) Does your PATH variable have android related paths that have a spurious semi-colon i.e., a semi-colon that is NOT being used as a separator between two paths.

          October 11, 2014
          Reply
          • B said:

            Thanks again!! Now it works. I had a ‘;’ in the end of the path (C:\android_sdk_adt_bundle\android_sdk;’ of ANDROID_HOME. I took out the ‘;’.

            The problem is now resolved, although I didn’t have an extra ‘;’ to begin with and having one ‘;’ in the end of the path should not be a problem?

            Thanks very much again, I appreciate it.

            October 11, 2014
            Reply
  8. selva said:

    Hi ,
    I am new to this i am getting the error below: can you help me out. i did try the above solution but still not working.

    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “C:\BSG\Android\adt-bundle-windows-x86_64-20130522\android_chess.py”, line 26, in setUp
    self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
    File “C:\Python27\lib\site-packages\appium\webdriver\webdriver.py”, line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 121, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 173, in execute
    self.error_handler.check_response(response)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py”, line 164, in check_response
    raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: u”A new session could not be created. (Original error: Bad app: C:\\BSG\\Android\\adt-bundle-windows-x86_64-20130522\\Chess Free.apk. App paths
    tall dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\\BSG\\Android\\adt-bundle-windows-x86_64-20130522\\Ches

    ———————————————————————-
    Ran 1 test in 0.105s

    October 21, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Selva, can you post the entire error message starting from raise exception_class(message, screen, stacktrace). It looks like your last few lines were not copy pasted fully. Also, please post the version of Appium you installed.

      My best guesses without seeing the exact message is that:
      1. (likely) Your script is pointing to the wrong app path. The app path in our script is set as:
      desired_caps[‘app’] = os.path.abspath(os.path.join(os.path.dirname(__file__),’apps/Chess Free.apk’)) where
      __file__ is the Python script you are executing and present in lets say $Directory_Of_My_Choice
      The .apk is expected to be in $Directory_Of_My_Choice\apps\Chess Free.apk.
      So either make sure that your directory structure matches what is set in desired_caps[‘app’] or change desired_caps[‘app’] to match where your app is present.

      2. (unlikely) If the problem is intermittent, it may just be that you need to add a appWaitActivity to your desired capabilities.

      October 21, 2014
      Reply
  9. selva said:

    Thanks for getting back to me. I did check the path and version. Here is the full details.

    I am using appium version 1.0.0 as you suggested above
    my scripts file is in the the below path
    c:\

    my app is in the below directory
    C:\BSG\apps\ChesssFree.apk

    my scripts:
    =========================================

    “””
    Qxf2: Example script to run one test against the Chess Free app using Appium
    The test will:
    – launch the app
    – click the ‘PLAY!’ button
    – choose single player mode
    “””

    import os
    import unittest
    from appium import webdriver
    from time import sleep

    class ChessAndroidTests(unittest.TestCase):
    “Class to run tests against the Chess Free app”
    def setUp(self):
    “Setup for the test”
    desired_caps = {}
    desired_caps[‘platformName’] = ‘Android’
    desired_caps[‘platformVersion’] = ‘4.4.2’
    desired_caps[‘deviceName’] = ’emulator-5554′
    # Returns abs path relative to this file and not cwd
    desired_caps[‘app’] = os.path.abspath(os.path.join(os.path.dirname(__file__),’BSG/Chess Free.apk’))
    desired_caps[‘appPackage’] = ‘uk.co.aifactory.chessfree’
    desired_caps[‘appActivity’] = ‘.ChessFreeActivity’
    self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)

    def tearDown(self):
    “Tear down the test”
    self.driver.quit()

    def test_single_player_mode(self):
    “Test the Single Player mode launches correctly”
    element = self.driver.find_element_by_name(“PLAY!”)
    element.click()
    self.driver.find_element_by_name(“Single Player”).click()
    textfields = self.driver.find_elements_by_class_name(“android.widget.TextView”)
    self.assertEqual(‘MATCH SETTINGS’, textfields[0].text)

    #—START OF SCRIPT
    if __name__ == ‘__main__’:
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

    =============================================

    here is the error:

    C:\>android_chess.py
    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly … ERROR

    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “C:\android_chess.py”, line 26, in setUp
    self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
    File “build\bdist.win32\egg\appium\webdriver\webdriver.py”, line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 121, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 173, in execute
    self.error_handler.check_response(response)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\errorhandler.py”, line 164, in check_response
    raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: u”A new session could not be created. (Original error: Bad app: C:\\apps\\Chess Free.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file,
    special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\\apps\\Chess Free.apk’)”

    ———————————————————————-
    Ran 1 test in 0.194s

    FAILED (errors=1)

    C:\>

    This is the appium windows error:

    > Starting Node Server
    > info: Welcome to Appium v1.0.0 (REV f0a00fab2335fa88cb355ab4dc43a9cd3f3236c0)
    > info: Appium REST http interface listener started on 127.0.0.1:4723
    > info: socket.io started
    > info: Non-default server args: {“address”:”127.0.0.1″,”logNoColors”:true,”avd”:”appium”}
    > ERROR: debug: Appium request initiated at /wd/hub/session
    > info: Using local app from desired caps: C:\apps\Chess Free.apk
    > ERROR: debug: Request received with params: {“desiredCapabilities”:{“deviceName”:”emulator-5554″,”app”:”C:\\apps\\Chess Free.apk”,”platformVersion”:”4.4.2″,”appPackage”:”uk.co.aifactory.chessfree”,”platformName”:”Android”,”appActivity”:”.ChessFreeActivity”}}
    > info: Got configuration error, not starting session
    > ERROR: error: Failed to start an Appium session, err was: Error: Bad app: C:\apps\Chess Free.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\apps\Chess Free.apk’
    > info: Cleaning up appium session
    > info: Error: Bad app: C:\apps\Chess Free.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\apps\Chess Free.apk’
    > at null. (C:\BSG\Appium\AppiumForWindows-1.0.0\AppiumForWindows\node_modules\appium\lib\devices\android\android-common.js:53:13)
    > at C:\BSG\Appium\AppiumForWindows-1.0.0\AppiumForWindows\node_modules\appium\lib\devices\device.js:70:16
    > at Object.oncomplete (fs.js:107:15)
    > info: Responding to client with error: {“status”:33,”value”:{“message”:”A new session could not be created. (Original error: Bad app: C:\\apps\\Chess Free.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\\apps\\Chess Free.apk’)”,”origValue”:”Bad app: C:\\apps\\Chess Free.apk. App paths need to be absolute, or relative to the appium server install dir, or a URL to compressed file, or a special app name. cause: Error: Error locating the app: ENOENT, stat ‘C:\\apps\\Chess Free.apk'”},”sessionId”:null}
    > POST /wd/hub/session 500 42ms – 632b

    I hope this will help.

    Thanks

    October 22, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Please try changing desired caps to this:
      desired_caps[‘app’] = os.path.abspath(os.path.join(os.path.dirname(__file__),’BSG/apps/Chess Free.apk’))

      I think what is going on right now is that Appium is looking for the apk in C:/BSG/. You can make Appium look for the app in C:/BSG/apps by making the above change.

      October 22, 2014
      Reply
  10. selva said:

    Hi ,
    Thanks again. I did change this but still the error. My appium folder is in the below directory
    C:\BSG\Appium\AppiumForWindows-1.0.0\AppiumForWindows

    My scripts now look like
    ———————————

    import os
    import unittest
    from appium import webdriver
    from time import sleep

    class ChessAndroidTests(unittest.TestCase):
    “Class to run tests against the Chess Free app”
    def setUp(self):
    “Setup for the test”
    desired_caps = {}
    desired_caps[‘platformName’] = ‘Android’
    desired_caps[‘platformVersion’] = ‘4.4.2’
    desired_caps[‘deviceName’] = ’emulator-5554′
    # Returns abs path relative to this file and not cwd
    desired_caps[‘app’] = os.path.abspath(os.path.join(os.path.dirname(__file__),’BSG/apps/Chess Free.apk’))
    desired_caps[‘appPackage’] = ‘uk.co.aifactory.chessfree’
    desired_caps[‘appActivity’] = ‘.ChessFreeActivity’
    self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)

    def tearDown(self):
    “Tear down the test”
    self.driver.quit()

    def test_single_player_mode(self):
    “Test the Single Player mode launches correctly”
    element = self.driver.find_element_by_name(“PLAY!”)
    element.click()
    self.driver.find_element_by_name(“Single Player”).click()
    textfields = self.driver.find_elements_by_class_name(“android.widget.TextView”)
    self.assertEqual(‘MATCH SETTINGS’, textfields[0].text)

    #—START OF SCRIPT
    if __name__ == ‘__main__’:
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

    ————————————-

    error
    c:\>android_chess.py
    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly … ERROR

    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “C:\android_chess.py”, line 26, in setUp
    self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
    File “build\bdist.win32\egg\appium\webdriver\webdriver.py”, line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 121, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 171, in execute
    response = self.command_executor.execute(driver_command, params)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py”, line 347, in execute
    return self._request(command_info[0], url, body=data)
    File “C:\Python27\lib\site-packages\selenium-2.42.1-py2.7.egg\selenium\webdriver\remote\remote_connection.py”, line 415, in _request
    resp = opener.open(request)
    File “C:\Python27\lib\urllib2.py”, line 404, in open
    response = self._open(req, data)
    File “C:\Python27\lib\urllib2.py”, line 422, in _open
    ‘_open’, req)
    File “C:\Python27\lib\urllib2.py”, line 382, in _call_chain
    result = func(*args)
    File “C:\Python27\lib\urllib2.py”, line 1214, in http_open
    return self.do_open(httplib.HTTPConnection, req)
    File “C:\Python27\lib\urllib2.py”, line 1184, in do_open
    raise URLError(err)
    URLError:

    ———————————————————————-
    Ran 1 test in 1.059s

    FAILED (errors=1)

    c:\>

    once again thanks.

    October 22, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Great! You are past the previous error. This error is different. It seems similar to the error that ‘B’ commented on a little earlier. The likely solutions are:
      1. Appium server is not up and running (steps 6 & 7 in the Appium Setup section)
      2. Appium server is running on a port other than 4723 (use netstat or TCPView on Windows to confirm)
      Can you check if your Appium server is up and running?

      October 22, 2014
      Reply
  11. selva said:

    thanks again.
    here i can see that appium using the port
    > Starting Node Server
    > info: Welcome to Appium v1.0.0 (REV f0a00fab2335fa88cb355ab4dc43a9cd3f3236c0)
    > info: Appium REST http interface listener started on 127.0.0.1:4723
    > info: socket.io started
    > info: Non-default server args: {“address”:”127.0.0.1″,”logNoColors”:true,”avd”:”appium”}

    what when i look on the TCPView i can only see the node.exe on port 4723 and listening.
    do you have an instruction for ubuntu hwo to run this. i can try on ubuntu

    October 22, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Weird. Your previous URLError exception indicates that your script was not able to connect to the Appium Server. Try stopping the server, restarting it and then use a new command prompt to run the script again.

      To setup Appium on Ubuntu,
      1. Install NodeJs: sudo apt-get install nodejs
      2. Install npm: sudo apt-get install npm
      3. Install appium: npm install -g appium
      4. Install the appium client: npm install wd
      5. Start the appium server: appium

      You will need to set up your environment variables in a similar fashion. The rest of the tutorial will be nearly identical between Windows and Ubunutu.

      October 23, 2014
      Reply
  12. Evelyn said:

    Thanks for this post. It was very useful.
    I’m encountering the following “Access Denied”error.

    E:\ToolEvaluations\Appium_Projects\SampleProj>python android_chess.py
    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly … ERROR
    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “android_chess.py”, line 19, in setUp
    self.driver = webdriver.Remote(‘http://127.0.0.1:4723/wd/hub’, desired_caps)
    File “build\bdist.win32\egg\appium\webdriver\webdriver.py”, line 35, in __init
    __
    super(WebDriver, self).__init__(command_executor, desired_capabilities, brow
    ser_profile, proxy, keep_alive)
    File “C:\Python27\lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriv
    er\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriv
    er\remote\webdriver.py”, line 121, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriv
    er\remote\webdriver.py”, line 173, in execute
    self.error_handler.check_response(response)
    File “C:\Python27\lib\site-packages\selenium-2.43.0-py2.7.egg\selenium\webdriv
    er\remote\errorhandler.py”, line 136, in check_response
    raise exception_class(value)
    WebDriverException: Message: ‘\r\nAccess Denied\r\n\r\n\r\n\r\n\r
    \n\r\n

    \r\n\r\n\r\n\r\nAccess Denied (authentication_failed)\r\n\r\n\r\n\r\n\r\n\r\n\r\nYour credentials could not be authenticated: “Credentials are missing.”. Y
    ou will not be permitted access until your credentials can be verified.\r\n\r\n\r\n\r\n\r\nThis is typically cau
    sed by an incorrect username and/or password, but could also be caused by networ
    k problems.\r\n\r\n\r\n\r\n\r\n\r\nFor assistance, contact your network support team.\r\n\r\n\r\n\r\n

    \r\n\r\n\r\n’
    ———————————————————————-
    Ran 1 test in 0.022s
    FAILED (errors=1)

    November 11, 2014
    Reply
    • Arunkumar Muralidharan Qxf2 said:

      Evelyn, I’m making a wild guess based on past experience with webdriver. Do you have a proxy setup on your machine? If so, try again after removing the proxy settings.

      November 13, 2014
      Reply
      • Anonymous said:

        bingo!! thankU

        October 5, 2016
        Reply
  13. Anonymous said:

    Hi,

    I am trying to run the example in python and the script does not do any thing.
    Any suggestions.

    Thanks

    DeviceName”:”Android”,”app”:”c:\\users\\user\\documents\\visual studio 2012\\Projects\\PythonApplication3\\PythonApplication3\\apps\\ChessFree.apk”,”platformVersion”:”4.2″,”ap]
    > info: Starting android appium
    > info: [debug] Using fast reset? true
    > info: [debug] Preparing device for session
    > info: [debug] Checking whether app is actually present
    > info: [debug] Checking whether adb is present

    Python:
    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly …

    November 29, 2014
    Reply
  14. Eldad said:

    Hi,

    I am trying to run the example in python and the script does not do any thing.
    Any suggestions.

    Thanks

    DeviceName”:”Android”,”app”:”c:\\users\\user\\documents\\visual studio 2012\\Projects\\PythonApplication3\\PythonApplication3\\apps\\ChessFree.apk”,”platformVersion”:”4.2″,”ap]
    > info: Starting android appium
    > info: [debug] Using fast reset? true
    > info: [debug] Preparing device for session
    > info: [debug] Checking whether app is actually present
    > info: [debug] Checking whether adb is present

    Python:
    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly …

    November 29, 2014
    Reply
    • Eldad, does the Python script just hang? It will be helpful if you post the entire content of what the Python script writes out.

      November 30, 2014
      Reply
      • Eldad said:

        Thanks on your response. The python just hang with:

        test_single_player_mode (__main__.ChessAndroidTests)
        Test the Single Player mode launches correctly …

        Appium:
        > info: Starting android appium
        > info: [debug] Using fast reset? true
        > info: [debug] Preparing device for session
        > info: [debug] Checking whether app is actually present
        > info: [debug] Checking whether adb is present

        Thanks

        November 30, 2014
        Reply
        • Vrushali Toshniwal Vrushali Mahalley said:

          Eldad,
          Have you done the Android SDK setup as mentioned in step 2?
          Are you able to run ‘adb’ command from the command prompt?

          Following is the snippet for my test run-
          > info: [debug] Checking whether adb is present
          > info: [debug] Using adb from D:\adt-bundle-windows-x86_64-20140321\adt-bundle-windows-x86_64-20140321\sdk\platform-tools\adb.exe
          > info: Retrieving device

          December 1, 2014
          Reply
  15. rakesh said:

    Very Usefull …….Thank you Can i run both android and iOS scripts in mac using appium +python

    December 2, 2014
    Reply
  16. praveen said:

    can we test a website functionality using appium and selenium scripts??
    i want to create selenium scripts to test a website functionality.

    January 19, 2015
    Reply
    • praveen said:

      actually i wanna perform mobile testing on a website using appium and selenium…

      January 19, 2015
      Reply
  17. selva said:

    hi,
    how do i implement swipe screen. Any advice please?

    January 19, 2015
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Selva,
      I replied to your comments on other blog regarding swipe functionality.
      “http://qxf2.com/blog/appium-tutorial-python-physical-device/”

      January 20, 2015
      Reply
  18. Avinash Shetty Avinash Shetty said:

    Hi Praveen,
    You can perform test on Mobile web apps using appium.

    For this you need to set the browserName in your desired capability to one that you intend to use
    eg: desired_caps[‘browserName’] = ‘Chrome’
    Then you then launch any website using self.driver.get() function.

    January 20, 2015
    Reply
  19. Arun said:

    error: Unhandled error: Error: ENOENT, no such file or directory ‘D:\adt-bundle-windows-x86-20131030\sdk;D:\adt-bundle-windows-x86-20131030\sdk\platform-tools\build-tools’

    I am getting the above error message, Request to help me to sort it out

    March 4, 2015
    Reply
    • Arun, your ANDROID_HOME needs to be D:\adt-bundle-windows-x86-20131030\sdk

      I suspect that your ANDROID_HOME currently has an extra D:\adt-bundle-windows-x86-20131030\sdk\platform-tools.

      March 4, 2015
      Reply
  20. Anonymous said:

    What this ERROR Means in iOS:

    error: Appium will not work if used or installed with sudo. Please rerun/install as a non-root user. If you had to install Appium using `sudo npm install -g appium`, the solution is to reinstall Node using a method (Homebrew, for example) that doesn’t require sudo to install global npm packages.

    Please Help.
    Thanks,
    AJIT JADHAV.

    May 14, 2015
    Reply
    • Avinash Shetty Avinash Shetty said:

      Appium may not work if node is installed as sudo user. If you have already installed remove it using

      sudo apt-get remove nodejs
      sudo apt-get remove npm

      These are two options to install appium
      1: Easiest way is to download and run the latest appium stable build for Mac OS from here: https://bitbucket.org/appium/appium.app/downloads/
      2: Compile and run appium from the source

      > brew install node # get node.js
      > npm install -g appium # get appium
      > npm install wd # get appium client
      > appium & # start appium
      > node your-appium-test.js

      May 20, 2015
      Reply
  21. Rajendra said:

    Hi Qxf2,

    How to perform actions on already opened App.
    When i run my test it launches the app. I dont want that, i will launch the app and will run the test.
    I saw that “autoLaunch” have to be set for it, i tried as below but it didnt work.
    how to set autoLaunch property in Python.?
    i tried as below, but it didnt work.
    def setUp(self):
    “Setup for the test”
    desired_caps = {}
    desired_caps[‘platformName’] = ‘Android’
    desired_caps[‘platformVersion’] = ‘4.4.4’
    desired_caps[‘deviceName’] = ‘XT1022’
    # Get the Package and Activity name to launch the Camera app
    desired_caps[‘appPackage’] = ‘com.xxx.xxx.dial’
    desired_caps[‘appActivity’] = ‘com.xxx.xxx.dial.MainActivity’
    desired_caps[‘autoLaunch’] = False
    #You may need to change the line below depending on your setup
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)

    Please let me know how to do it.

    Thanks in advance.
    Rajendra

    August 1, 2015
    Reply
  22. AmarEswar said:

    Hi ,
    I am new to appium . I am automating IOS hybrid app on real device. In my app when click on the button in webpage it will open the native settings page(MDM profile install ).

    That page giving model dialog box with install and cancel button.In Appium inspector also not loading. Unable to add the screenshots here. Please refer the the below link for more details.
    https://github.com/appium/appium/issues/5474

    Please help me on this ..

    August 11, 2015
    Reply
  23. Kate said:

    Thanks! This was very helpful! I have not done much automation let alone on mobile..and this just kick started me!:>
    Well written and explained! Kudos!
    Cheers,
    Kate

    November 9, 2015
    Reply
  24. As a manual QA tester looking to break in to automation (specifically Android automation), this has helped me a lot. Thanks!

    November 13, 2015
    Reply
  25. jai said:

    Hi,

    I tried running the same program on real device and getting following error. Any suggestions.

    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly … ERROR

    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “chess_and_j.py”, line 18, in setUp
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)

    File “C:\Python27\lib\site-packages\appium\webdriver\webdriver.py”, line 36, i
    n __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, brow
    ser_profile, proxy, keep_alive)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, l
    ine 87, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, l
    ine 141, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, l
    ine 201, in execute
    self.error_handler.check_response(response)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py”
    , line 102, in check_response
    value = json.loads(value_json)
    File “C:\Python27\lib\json\__init__.py”, line 338, in loads
    return _default_decoder.decode(s)
    File “C:\Python27\lib\json\decoder.py”, line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
    File “C:\Python27\lib\json\decoder.py”, line 384, in raw_decode
    raise ValueError(“No JSON object could be decoded”)
    ValueError: No JSON object could be decoded

    ———————————————————————-
    Ran 1 test in 0.141s

    FAILED (errors=1)

    January 5, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Jai,
      My guesses based on your error message are
      1. Appium server is running on a port other than 4723 (use netstat or TCPView on Windows to confirm)
      2. localhost may not be getting resolved to 127.0.0.1 (try changing your URL from http://localhost:4723/wd/hub to http://127.0.0.1:4723/wd/hub and try)

      Let me know if this resolves your issue or else we can investigate more

      January 7, 2016
      Reply
  26. Rijo said:

    Hi
    I am new to appium and I am running a selenium script with device connected and while running in terminal i am getting this error “Error: ENOENT: no such file or directory, scandir ‘/Documents/android-sdk-linux/build-tools’
    at Error (native)” . I am running in Linux. Can you please help me out ?

    April 4, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Rijo,
      I am not sure of the path ‘/Documents/android-sdk-linux/build-tools’ which you used. You can always try “which build tools” or “which adb” to get the path

      April 7, 2016
      Reply
  27. neelima said:

    on entering password in device using appium, some times it open keypad while sometimes not , i use the code “driver.hidekeypad” its hiding the same when display, but not when it doesnt display the keypad and further code get stopped , so how to write code to search whether keypad is open or close if open then enter and go to next text else type directly and then go to next text field .

    April 5, 2016
    Reply
    • Shivahari P Shivahari P said:

      Hi Neelima,
      We use try-except to hide the key board after entering text in a text field.
      *Code to enter text in the text field
      try:
      driver.hide_keyboard()
      except Exception,e:
      pass
      Hope this helps

      April 7, 2016
      Reply
  28. Joyz Ng said:

    It helps me to kickstart on writing appium scripts! Really simple and helpful, thanks a lot!

    April 22, 2016
    Reply
  29. Sonu Arora said:

    Hi,

    This is very helpful. I was able to do automation just because of this link. Now i want to start automation on Mac for iPhone apps. I know python and Appium. Can u please suggest me how to setup same for Mac?

    May 9, 2016
    Reply
  30. Anonymous said:

    Why starting/stopping simulator is a manual step instead of part of your test?

    Cheers,
    Harry

    June 24, 2016
    Reply
    • We did not automate starting/stopping the emulator because we use the emulator only when developing the tests on our local machines. It saves us time when developing and debugging tests to leave the emulator running and just start/stop the Appium server itself.

      Once a test is developed, we end up running the test on a cloud service provider with real devices (e.g.: BrowserStack). Here are two examples of running your mobile automation on a cloud service provider:

      1. With Sauce labs: https://qxf2.com/blog/mobile-automation-appium-sauce-labs/
      2. With BrowserStack: https://qxf2.com/blog/browserstack-part1/

      June 28, 2016
      Reply
  31. nagarjuna said:

    how to print all the contacts of the contact list , using appium code

    June 30, 2016
    Reply
  32. Mohit Anand said:

    Hi,

    Have you ever tried reading an OTP message from the message app and then entering that into the textfield of the app which you are automating using Appium?

    If yes, kindly let me know how can we approach this problem?

    July 13, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Mohit,
      I haven’t tried this but i guess the approach mentioned in this link should help you when testing it on a Android device.

      July 15, 2016
      Reply
  33. Javed said:

    /usr/bin/python /Users/jchowdry/Documents/AutomationTest/appium/test.py
    Traceback (most recent call last):
    File “/Users/jchowdry/Documents/AutomationTest/appium/test.py”, line 24, in
    driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
    File “/Library/Python/2.7/site-packages/appium/webdriver/webdriver.py”, line 36, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 90, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 177, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
    File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py”, line 236, in execute
    self.error_handler.check_response(response)
    File “/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py”, line 192, in check_response
    raise exception_class(message, screen, stacktrace)
    selenium.common.exceptions.WebDriverException: Message: An unknown server-side error occurred while processing the command. Original error: Could not find a device to launch. You requested ‘iPhone 6s (9.2) [‘, but the available devices were: [“Apple TV 1080p (9.2) [4E02F4C7-B5CC-4D30-B34F-80EE99C136B9] (Simulator)”,”iPad 2 (9.3) [79B1A87D-0895-40B4-8226-4D207CEF8412] (Simulator)”,”iPad Air (9.3) [C55DB910-E996-42B1-AC94-B259EB69DA47] (Simulator)”,”iPad Air 2 (9.3) [6EB90D1F-1980-4DE8-AC88-D800F26DEAA6] (Simulator)”,”iPad Pro (9.3) [4E4F169A-12D4-4D9F-B540-85EEDEBBCC5A] (Simulator)”,”iPad Retina (9.3) [61140A0E-6240-4942-A0AF-655CFEF58AD5] (Simulator)”,”iPhone 4s (9.3) [BD16DCE4-8567-4FE5-86B6-634757F42BA4] (Simulator)”,”iPhone 5 (9.3) [36BC2385-66E8-46A1-9605-7C1952573FFA] (Simulator)”,”iPhone 5s (9.3) [499D9EBC-CE97-441E-9DBC-3414ACFFE5E0] (Simulator)”,”iPhone 6 (9.3) [AE746B61-91C8-457F-904D-3DA6E729F091] (Simulator)”,”iPhone 6 Plus (9.3) [F7238529-0147-4A46-BD66-DB4E9135F065] (Simulator)”,”iPhone 6s (9.3) [3FBE595A-00E1-4884-A93C-6EC1129AC2F9] (Simulator)”,”iPhone 6s (9.3) + Apple Watch – 38mm (2.2) [277E8BDF-B301-44AF-986B-E878E4447618] (Simulator)”,”iPhone 6s Plus (9.3) [DCDFCEEE-2AEF-4DA5-9560-5738F72D553A] (Simulator)”,”iPhone 6s Plus (9.3) + Apple Watch – 42mm (2.2) [87968785-B129-4947-B832-CD6B822101F3] (Simulator)”]

    I am getting above error. Can you please help me out

    August 1, 2016
    Reply
    • Shivahari P Shivahari P said:

      Hi Javed,
      My guess from this – Could not find a device to launch. You requested ‘iPhone 6s (9.2) is that may have to add this device to ur simulator or you can try running your against iPhone 6s Plus (9.3).

      August 3, 2016
      Reply
  34. Satish said:

    Hi, I’m using windows Appium 1.4.16, appium-python-client2.47. And trying to use set_value() to send the text values however I get following error (Not yet implemented).

    File “omnirent_android_tests.py”, line 203, in test_signUp_full_name
    self.driver.find_element_by_id(“com.test.org.example:id/sName”).set_value(‘username’)
    File “C:\Python27\lib\site-packages\appium\webdriver\webelement.py”, line 123, in set_value
    self._execute(Command.SET_IMMEDIATE_VALUE, data)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py”, line 461, in _execute
    return self._parent.execute(command, params)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 236, in execute
    self.error_handler.check_response(response)
    File “C:\Python27\lib\site-packages\appium\webdriver\errorhandler.py”, line 29, in check_response
    raise wde
    WebDriverException: Message: Not yet implemented. Please help us: http://appium.io/get-involved.html

    Could you please guide me, what method should we use to send texts or some values to emulator?

    August 8, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Satish,

      The function set_value(self, element, value) takes the element and the value you want to pass to that element. You may need to update your code self.driver.find_element_by_id(“com.test.org.example:id/sName”).set_value(‘username’) so that you pass both the element and the value to the set_value function. Let me know if this works

      August 9, 2016
      Reply
  35. Satish said:

    Hi Avinash,

    My code is same as you had mentioned self.driver.find_element_by_id(“com.test.org.example:id/sName”).set_value(‘username’)
    and facing the issue i had mentioned. Is this code works only on particular versions of Appium and Appium-python-clinet?

    August 9, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Satish,

      You need to pass the element and the value inside set_value function
      element = self.driver.find_element_by_id(“com.test.org.example:id/sName”)
      set_value(element,’username’)

      August 9, 2016
      Reply
  36. Satish said:

    Hi Avinash,
    Thanks for replay. I tried as you suggested however now i see new issue.
    set_value(el,’username’)
    NameError: global name ‘set_value’ is not defined

    I had imported following on my script
    import os
    import unittest
    from appium import webdriver
    from time import sleep

    Am i missing something?

    August 9, 2016
    Reply
    • Shivahari P Shivahari P said:

      Hi Satish,
      Did you try self.driver.set_value(element,username)?
      Alternatively, you can use element.send_keys.
      element = self.driver.find_element_by_id(“com.test.org.example:id/sName”)
      element.send_keys(username)

      August 9, 2016
      Reply
  37. Satish said:

    Hi Shivahari
    Thanks for your suggestion send_keys() works.
    Following are my observations for “set_value()” :
    – I tried all the possibilities with “set_value() and” nothing worked on windows with .Appium 1.4.16 and 1.3. XX
    – The interesting point is set_value() works perfectly on Ubuntu machine with Appium 1.5 and appium-python-client2.47.(installed appium through npm install).
    – Looks like Appium 1.4.XX does not support set_value(), that’s why we get exception error “WebDriverException: Message: Not yet implemented”

    August 11, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Satish,
      Thanks for sharing your Observation…

      August 12, 2016
      Reply
  38. Jish said:

    HI

    This was way beyond helpful. However im running into an issue while using appium behind a proxy wall. The error seems to start from line

    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)

    Im getting connection refused error. I used the same environment at home and worked perfectly. How can i take care of this ?

    December 26, 2016
    Reply
  39. JLyon said:

    Hi,

    I tried to execute below program:

    “””
    Qxf2: Example script to run one test against the Chess Free app using Appium
    The test will:
    – launch the app
    – click the ‘PLAY!’ button
    – choose single player mode
    “””

    import os
    import unittest
    from appium import webdriver
    from time import sleep

    class ChessAndroidTests(unittest.TestCase):
    “Class to run tests against the Chess Free app”
    def setUp(self):
    “Setup for the test”
    desired_caps = {}
    desired_caps[‘platformName’] = ‘Android’
    desired_caps[‘platformVersion’] = ‘4.2’
    desired_caps[‘deviceName’] = ‘Android Emulator’
    # Returns abs path relative to this file and not cwd
    desired_caps[‘app’] = os.path.abspath(os.path.join(os.path.dirname(__file__),’D:\Programs\myapp\Chess Free.apk’))
    desired_caps[‘appPackage’] = ‘uk.co.aifactory.chessfree’
    desired_caps[‘appActivity’] = ‘.ChessFreeActivity’
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)

    def tearDown(self):
    “Tear down the test”
    self.driver.quit()

    def test_single_player_mode(self):
    “Test the Single Player mode launches correctly”
    element = self.driver.find_element_by_name(“PLAY!”)
    element.click()
    self.driver.find_element_by_name(“Single Player”).click()
    textfields = self.driver.find_elements_by_class_name(“android.widget.TextView”)
    self.assertEqual(‘MATCH SETTINGS’, textfields[0].text)

    #—START OF SCRIPT
    if __name__ == ‘__main__’:
    suite = unittest.TestLoader().loadTestsFromTestCase(ChessAndroidTests)
    unittest.TextTestRunner(verbosity=2).run(suite)

    Getting below error:

    test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly … ERROR

    ======================================================================
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “D:/Programs/myapp/android_chess.py”, line 26, in setUp
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
    File “D:\Programs\Python275\lib\site-packages\appium\webdriver\webdriver.py”, line 36, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 236, in execute
    self.error_handler.check_response(response)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 192, in check_response
    raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c “java -jar D:\Programs\Appium\node_modules\appium\node_modules\appium-adb\jars\sign.jar “D:\Programs\myapp\Chess Free.apk” –override”
    java.util.zip.ZipException: error in opening zip file

    at java.util.zip.ZipFile.open(Native Method)

    at java.util.zip.ZipFile.(Unknown Source)

    at java.util.zip.ZipFile.(Unknown Source)

    at java.util.jar.JarFile.(Unknown Source)

    at java.util.jar.JarFile.(Unknown Source)

    at s.Sign.sign(Sign.java:441)

    at s.Sign.main(Sign.java:532)

    Would you please help me to solve this error?
    Thank you.

    February 25, 2017
    Reply
  40. JLyon said:

    Hi,

    Thanks for the nice post, its very useful.

    I am getting below error while running the same program mentioned in your post:
    ERROR: test_single_player_mode (__main__.ChessAndroidTests)
    Test the Single Player mode launches correctly
    ———————————————————————-
    Traceback (most recent call last):
    File “D:/Programs/myapp/android_chess.py”, line 26, in setUp
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
    File “D:\Programs\Python275\lib\site-packages\appium\webdriver\webdriver.py”, line 36, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 92, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 179, in start_session
    response = self.execute(Command.NEW_SESSION, capabilities)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 236, in execute
    self.error_handler.check_response(response)
    File “D:\Programs\Python275\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 192, in check_response
    raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: A new session could not be created. (Original error: Command failed: C:\WINDOWS\system32\cmd.exe /s /c “java -jar D:\Programs\Appium\node_modules\appium\node_modules\appium-adb\jars\sign.jar “D:\Programs\myapp\Chess Free.apk” –override”
    java.util.zip.ZipException: error in opening zip file

    at java.util.zip.ZipFile.open(Native Method)

    at java.util.zip.ZipFile.(Unknown Source)

    at java.util.zip.ZipFile.(Unknown Source)

    at java.util.jar.JarFile.(Unknown Source)

    at java.util.jar.JarFile.(Unknown Source)

    at s.Sign.sign(Sign.java:441)

    at s.Sign.main(Sign.java:532)

    Would you please help me to solve this issue?
    Thank you.

    February 25, 2017
    Reply
  41. Chandra Sekar said:

    Hi, thanks a lot for the detailed explanation. Is there some reason you prefer Python over other languages? Because the Github repos of Appium Ruby & Java are updated frequently, whereas Appium python repo is not

    March 9, 2017
    Reply
    • Chandra Sekar, We find the code in the Appium Python repo sufficient for our testing needs. So the regularity of the updates does not matter too much to us.

      Python, Ruby, Java are all good for what we are trying to do. There is no reason to get into a language flame war. Here is why we started with Python and continue to use it:

      1. We like Python. We are good with Python. We were used to Python.
      2. We found Python more than sufficient for our needs. A lot of the top companies (Google, Facebook, etc.) use Python extensively for their scripting needs.
      3. Python is easy to pick up. Most of our employees pick up Python after they join Qxf2.
      4. Python is portable and less susceptible to version changes.
      5. Python has a lot of potential. Python is becoming the industry’s top choice for scientific and mathematical programming. And those are areas we are interested in exploring.

      March 13, 2017
      Reply
  42. Anonymous said:

    Hi,

    I am new to this appium how to start with basics automation testing in android and ios and I am new to a programming language also

    April 11, 2017
    Reply
    • Shivahari P Shivahari P said:

      Hi,
      The tutorials/examples in all our blogs are designed for anyone with beginner level of expertise in Python. Please follow the instructions in this blog,it will help you get the mobile automation environment setup and get you going with a basic mobile automation test.

      April 12, 2017
      Reply

Leave a Reply to selva Cancel reply

Your email address will not be published.