Appium tutorial: Execute Python tests on mobile devices

This Appium tutorial will show you how to run automated tests on a real physical device. We estimate skimming through this post will take you 10 minutes. We estimate working through this post, step by step, will take you about 90 minutes. In this post we will cover getting setup with Appium, interfacing with real devices, writing and running Appium tests. We also briefly introduce you to multiple ways to locate UI elements .

NOTE: If you have an Android phone handy, you can follow along easily. If not, you may be interested in a previous post showing you how to get started with Appium on an emulator.


Why this post?

There are two compelling reasons for this post.
1. Mobile devices are taking over the world
In recent times there is a lot of interest on mobile testing. And rightly so. The mobile space is growing. The apps are the new cool thing. The mobile space is ideal for software testers looking to learn new things and keep current.
2. Lack of high quality tutorials on mobile automation
One big challenge in the mobile automation space is the the limited amount of information about the technologies. Quality sources of information on mobile automation is very limited.

So here is a high quality and informative tutorial for the hands on tester who wants to get started with Appium and mobile automation on a physical mobile device.


Why Appium?

There are quite a few number of tools out there in the mobile automation market like MonkeyTalk, Calabash, Robotium, etc. Each has its own advantages and limitations. Some of these tools require an agent to be installed, the application has to be recompiled so that the tool can interact with the mobile app, etc. However Appium is built on the idea that testing native apps shouldn’t require including an SDK or recompiling the app. Appium is also a open source project – so if you are not happy with it, you can contribute and enhance it. Appium tests run against both on iOS and Android. For me, Appium (while still being extremely immature), looks to be the stand out technology that will own the mobile UI automation space. Appium reminds me of the early Selenium versions I used. Based on history, I think Appium will be the front runner in the mobile UI automation space.


Step by step Appium tutorial

We have already shown you how to run an Appium test using an emulator in one of our previous posts. In this post I will show you how to test an app using a real device. Being a tennis fan, I decided to test a tennis app. On my Android phone I downloaded the ATP/WTA app and decided to automate some of the functionality of this app. I will also show you how to navigate through different pages in the app using different locator strategies, get data from a table using Appium and Python and how to use the uiautomator to find UI components of the page.

Overview
1. Appium setup
2. Connect to an Android device
3. Select an app to test, get its package and activity name
4. Use uiautomatorviewer to find UI components of the application
5. Write the test
6. Start and launch Appium server console
7. Run the test
8. View the test result

STEP 1: Appium setup
Download and install Android SDK and Appium along with Appium’s client libraries for Python. Installations are fairly straight forward. However if you need help, please refer to the setup section in our previous blog for a more detailed process on how to set up Appium on your machine.

STEP 2: Connect to an Android device
You have to enable USB debugging in your phone to be able to run your test scripts. For this, first you need to enable “Developer options” by navigating to Settings/About Phone and tapping build number seven times. You will get a notification saying that you’re now a developer. Ignore it – you are still a tester ;). Once you are a developer you need to navigate to “Developer options” and enable the USB debugging option. You can refer to this link for more details

Build Number in Android Settings

Enable USB Debugging

Developer Option in Android settings

Note: On some devices you may have to download some device drivers to connect your phone to the PC

STEP 3: Select an app to test, get its package and activity name
You can go to Google Play Store and download the ATP/WTA app. We will automate some of the functionality like navigating to the ATP Singles Rankings view to assert that Novak Djokovic is the first player listed and also get his personal details from the table in players view.

In order to start the app we would need the app Package and Activity name. We can get these details from the apk file of the app. Instead of downloading the apk file and looking into app manifest file for this detail, we can also download some really cool apps which can get you these details. Application Reader is one such app which you can download from Play Store and get the app Package and Activity details. Just download the app and click on Application Reader Icon which will list all the apps on your device. Click on your app to get the details required as shown below

Application Reader for getting the Package and Activity name

Details of ATP WTA app

STEP 4: Use uiautomatorviewer to find UI components of the application uiautomatorviewer is a GUI tool to scan and analyze the UI components of an Android application. To click or to navigate to any components in your app you need to identify the UI components of your application. Using uiautomatorviewer you can take the snapshot of the UI screen on any Android device that is connected to your machine. You can then inspect the layout hierarchy and view the properties of the individual UI components that are displayed on the device.

Connect your Android device to your machine and open the app you are testing. In your machine open a terminal window and navigate to the path $android-sdk /tools and run the command to open Uiautomatorviewer

$ uiautomatorviewer

To capture a screen, click the “Device Screenshot button” in the uiautomatorviewer tool. The screenshot of the page in your device is captured. You can move over the snapshot in the left-hand panel to see the UI components identified by the uiautomatorviewer. You can view the component’s properties listed in the lower right-hand panel, and the layout hierarchy in the upper right-hand panel.
UI  Automator Viewer

STEP 5: Write the test
We will launch the ATP WTA app using the package and activity name we found out and then navigate through various pages using different locator strategies. While we do not recommend using multiple locator strategies, we are doing so in this tutorial only to make you aware of your options. Then we will confirm that Novak Djokovic is the top player listed in ATP Singles Rankings list view and get his personal details from a table in Players view.

"""
Qxf2: Example script to run one test against ATP_WTA app using Appium
The test will navigate to ATP Singles Rankings list and confirm that Novak
Djokovic is the top player listed and get his personal details from a table.
 
"""
 
import unittest, time, os
from appium import webdriver
from time import sleep
 
class Android_ATP_WTA(unittest.TestCase):
    "Class to run tests against the ATP WTA app"
    def setUp(self):
        "Setup for the test"
        desired_caps = {}
        desired_caps['platformName'] = 'Android'
        desired_caps['platformVersion'] = '4.4'
        desired_caps['deviceName'] = '$ Your device name'
        # Since the app is already installed launching it using package and activity name
        desired_caps['appPackage'] = 'atpwta.live'
        desired_caps['appActivity'] = '.activity.Main'
        # Adding appWait Activity since the activity name changes as the focus shifts to the ATP WTA app's first page
        desired_caps['appWaitActivity'] = '.activity.root.TournamentList'
        self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
 
    def tearDown(self):
        "Tear down the test"
        self.driver.quit()
 
    def test_atp_wta(self):
        "Testing the ATP WTA app "
        self.driver.implicitly_wait(30)
        time.sleep(5)
 
        # click on Navigation Bar MainMenu by finding element by xpath
        menubar = self.driver.find_element_by_xpath("//android.widget.Spinner[@resource-id='atpwta.live:id/NavBarMainMenuSpinner']")
        menubar.click()
 
        # From list of options available click on Rankings by finding element using uiautomator
        rankings = self.driver.find_element_by_android_uiautomator('new UiSelector().text("Rankings")')
        rankings.click()
 
        # click on ATP Singles by finding element using id
        singles = self.driver.find_element_by_id('atpwta.live:id/RankingsListItem')
        singles.click()
 
        # Assert that Novak Djokovic is the top listed player
        elmnt = self.driver.find_element_by_id('atpwta.live:id/Player1TV')
        self.assertEqual('Novak Djokovic', elmnt.get_attribute('text'))
        print elmnt.get_attribute('text')
 
        elmnt = self.driver.find_element_by_xpath("//android.widget.LinearLayout[@index=0]")
        elmnt.click()
 
        # Print the contents of Table listed for the top ranked player
        table = self.driver.find_element_by_android_uiautomator("new UiSelector().className(android.widget.TableLayout)")
        rows = table.find_elements_by_class_name('android.widget.TableRow')
        for i in range(0, len(rows)):
            cols = rows[i].find_elements_by_class_name('android.widget.TextView')
            for j in range(0, len(cols)):
                print(cols[j].get_attribute('text')+" -- "),
            print("")
 
 
#---START OF SCRIPT
if __name__ == '__main__':
    suite = unittest.TestLoader().loadTestsFromTestCase(Android_ATP_WTA)
    unittest.TextTestRunner(verbosity=2).run(suite)

STEP 6: Start and launch Appium server
Start Appium server console by double clicking on the Appium file. Click on the ‘rocket’ icon to launch the Appium node server.
Please refer to the 6th and 7th step of our previous blog if you need more details on starting appium server.
Start Appium

STEP 7: Run the test
You can run the test any way you like. We will run it using command prompt. The app gets launched in your device and navigates to different screen.

ATP WTA Live PagePlayers PageATP Rankings List Page

STEP 8: View the test result
BrowserStack Test Result


Game. Set. Match. You learnt how to do mobile automation using Appium on a real device!


A weekly newsletter for testers


View a sample



Avinash Shetty
I am a software tester with over 10 years of experience in software testing. Currently I am working at Qxf2 Services Bangalore. As a student of the context-driven approach to software testing I feel there is a lot to learn out there which keeps me very excited. My work has helped me gain good experience in different areas of testing like CRM, Web, Mobile and Database testing. I have good knowledge of building test scripts using Automation tools like Selenium and Appium using Java and Python. Beside testing I am a “Sports Fanatic” and love watching and playing sports.

© 2013-2017, Avinash Shetty. All rights reserved.

69 Comments

  1. selva said:

    Hi,
    This is excellent. I can run this successfully. Thanks for this. I was waiting for this. Great job. Keep it up.
    How to capture the screen for each steps?
    Thanks
    Selva

    November 13, 2014
    Reply
    • Thanks, Selva! We are always happy to help out fellow testers.

      When you say “capture the screen” do you mean taking a screenshot as part of the script itself? Or did you mean how we captured the screenshots pasted in this tutorial?

      November 14, 2014
      Reply
  2. selva said:

    Hi ,
    Thanks for getting back to me. I mean talking screenshot as part of the script itself.

    Once again thanks.

    November 14, 2014
    Reply
    • Selva, I have not tried this and won’t be able to try this for the next few days. But I think self.driver.get_screenshot_as_file(filename) should do it. I know Appium’s webdriver inherits from Selenium’s webdriver.Remote. Selenium’s webdriver.Remote has the method get_screenshot_as_file(filename) where filename is the full path of the desired image. E.g.:self.driver.get_screenshot_as_file(r’C:\tmp\my_image.png’)

      Side note: A useful Python feature is to use the help(object) command in the Python interpreter. You can create the driver object and then do help(driver) to see what are the methods that can be used with that object.

      November 14, 2014
      Reply
      • Selva, I can confirm that self.driver.get_screenshot_as_file(r’C:\tmp\my_image.png’) works for me.

        November 17, 2014
        Reply
        • selva said:

          Hi,
          Thanks for your help.

          November 19, 2014
          Reply
  3. Leonardo said:

    Hi
    I followed your tutorial as follows:
    1. Appium setup – Yes
    2. Connect to an Android device – Yes (Nexus 4 running Android 4.4.2, with Dev mode enabled)
    3. Select an app to test, get its package and activity name – Downloaded ATP/WTA Live app and installed on Nexus 4.
    4. Use uiautomatorviewer to find UI components of the application – Skipped
    5. Write the test – Copied the test from this page and saved as atp_wta.py, and modified platformVersion and deviceName.
    6. Start and launch Appium server console – Yes
    7. Run the test – Yes

    But I’m getting the following error:

    C:\Dev\appium_python_tests>python atp_wta.py
    test_atp_wta (__main__.Android_ATP_WTA)
    Testing the ATP WTA app … ERROR

    ======================================================================
    ERROR: test_atp_wta (__main__.Android_ATP_WTA)
    Testing the ATP WTA app
    ———————————————————————-
    Traceback (most recent call last):
    File “atp_wta.py”, line 18, in setUp
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
    File “C:\Dev\Python27\lib\site-packages\appium_python_client-0.11-py2.7.egg\appium\webdriver\webdriver.py”, line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 121, in start_sess
    ion
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 173, in execute
    self.error_handler.check_response(response)
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py”, line 166, in check_r
    esponse
    raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: A new session could not be created. (Original error: Could not find a connected Android device.)
    ———————————————————————-
    Ran 1 test in 28.133s

    FAILED (errors=1)

    What am I doing wrong? Any help would be greatly appreciated.
    Thanks

    Leo

    November 22, 2014
    Reply
    • Leonardo, the error indicates that your Android device may not have been recognized. I’ll need more details to debug. What do you see when you run adb devices -l on your command prompt? You may need to change the directory to you_android_path\sdk\platform-tools for the adb command to work.

      Please let us know the version of Android you have on your phone too.

      November 23, 2014
      Reply
  4. Leonardo said:

    Hi, yes, my laptop didn’t recognise my device but I have sorted it out since, by following the steps outlined here: http://bit.ly/1y93bXt, and now I get this message when I do adb devices:
    List of devices attached
    025f18afd8d66506 device
    So, now when I run the python script, I get this new error:

    test_atp_wta (__main__.Android_ATP_WTA)
    Testing the ATP WTA app … ERROR
    ======================================================================
    ERROR: test_atp_wta (__main__.Android_ATP_WTA)
    Testing the ATP WTA app
    ———————————————————————-
    Traceback (most recent call last):
    File “atp_wta.py”, line 18, in setUp
    self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
    File “C:\Dev\Python27\lib\site-packages\appium_python_client-0.11-py2.7.egg\appium\webdriver\webdriver.py”, line 35, in __init__
    super(WebDriver, self).__init__(command_executor, desired_capabilities, browser_profile, proxy, keep_alive)
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 73, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 121, in start_sess
    ion
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py”, line 173, in execute
    self.error_handler.check_response(response)
    File “C:\Dev\Python27\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py”, line 166, in check_r
    esponse
    raise exception_class(message, screen, stacktrace)
    WebDriverException: Message: A new session could not be created. (Original error: Requested a new session but one was in progress)
    ———————————————————————-
    Ran 1 test in 0.303s
    FAILED (errors=1)

    November 24, 2014
    Reply
    • Leonardo, can you try restarting your Appium server? I have seen this happen when driver.quit() is not called at the end of one script and you try to run a new one. E.g.: You ran a script and somewhere the script failed with an exception before driver.quit() was called. Now you correct the error in the script and run it again and sometimes this error happens. Annoying. Only quick fix I can think of is to restart the Appium server.

      November 27, 2014
      Reply
  5. Leonardo said:

    Thank you. That did the trick! It would also help others if you add a small section of FAQ at the end of this article if case others have come across these types of errors with Appium.

    Now I can follow the rest of your tutorials and even try writing my own tests! Thanks again.

    November 27, 2014
    Reply
    • Great, test away! I like your idea about an FAQ section, Leonardo. Thanks! Based on the comments here, I will add the FAQ to this post. I should get to doing it in the next couple of weeks.

      November 30, 2014
      Reply
  6. Eldad said:

    Hi,

    Great article .
    Can you please elaborate in general the concept of how can I do image recognition to identify and control GUI components.

    Thanks In Advanced,

    December 17, 2014
    Reply
    • Eldad, I have used image comparison in the non-mobile space. In various projects, I have used EggPlant, AutoIT and Screenster. I have also written my own Python scripts using a combination of ImageMagick and Python Image Library. How you end up doing image recognition depends on your specific use case. Sometimes its just a matter of scaling the image to a known size, comparing it with a reference and then working out the co-ordinates that you want to click. Other times, it may be a matter of super-imposing two images and taking a pixel by pixel difference (with an error margin) to determine an exact match.

      Having said all that, I would strongly discourage you from using image comparisons unless that is literally your last unexplored alternative. To date, I have not found a single tool that is based on image recognition that is even moderately robust enough for professional use.

      December 21, 2014
      Reply
  7. Eldad said:

    Thanks on a detailed & professional answer.

    Are there any tools that wraps Appium for more less-code tool for QA engineers that are not writing code?

    Thanks

    December 22, 2014
    Reply
    • Eldad, I am not familiar with the record & play space. I know a tool called “Appium GUI” exists and is supposed to work ok with iOS. But I have not used it with either Android or iOS.

      December 23, 2014
      Reply
  8. selva said:

    Hi,
    Can you please how to do i do for Pich and swipe on screen on android using appium api.
    thanks
    Selva

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

      Hi Selva,
      We would be writing a blogpost on Pinch and swipe gestures on android using appium, within next week

      January 16, 2015
      Reply
      • selva said:

        Thanks. let me know when you done that.

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

          Hi Selva,
          The blog may take bit time, so here is some sample code for swipe, pinch and zoom which may be helpful for you.

          For swipe use:
          driver.swipe(startx, starty, endx, endy, duration)
          eg: self.driver.swipe(475, 500, 75, 500, 400)

          For pinch and zoom:
          self.driver.pinch(element = el)
          self.driver.zoom(element = el)

          I tested this with camera app and below is the code snippet
          el = self.driver.find_element_by_class_name(‘android.view.View’)
          self.driver.pinch(element = el)
          time.sleep(5)
          self.driver.zoom(element = el)
          time.sleep(5)
          action.long_press(el).perform()
          Note: pinch and zoom doesn’t work for android 4.2 or lower versions

          January 20, 2015
          Reply
          • selva said:

            Hi,
            Thanks for your continues help. You are doing very excellent jobs. Well done and keep it up.
            Regards
            Selva

            January 23, 2015
            Reply
          • selva said:

            Hi,
            Thanks for your help. You are doing excellent jobs. Well done keep it up.I have learned so much from you. it is good idea to consider doing on line tutorial or you tube video as you have very good talent.
            Regards
            Selva

            January 23, 2015
            Reply
  9. selva said:

    Hi,
    Thanks for your help. You are doing excellent work. I advice you to do some online tutorial or You tube series of Video.
    Thanks
    Selva

    January 23, 2015
    Reply
  10. Mohit said:

    Hi Avinash,

    Have you written a similar blog for automating an iOS app using a real device?
    If yes, please provide its link.

    If no, could you please advise me a tool which can be used to find the UI component of an iOS application?

    Any help would be highly appreciated.

    January 26, 2015
    Reply
  11. selva said:

    Hi Avinash,,
    Is there any issue in appium when we use the While loop.
    I am trying to use while loop to install a data from a data sets. the while loop seems to not break after it completed data sets install. Is there anything i am doing wrong here.
    basically the text “AVAILABLE DATASETS” will be disappear once all data set got install.
    here is my part of the code.
    while self.driver.find_element_by_android_uiautomator(‘new UiSelector().text(“AVAILABLE DATASETS”)’):
    Single_Datasets=self.driver.find_element_by_xpath(“//android.widget.ImageButton[@resource-id=’com.bsgwireless.fac:id/download_button’]”)
    Single_Datasets.click()

    any suggestion how i can use the while loop with appium for android. any other example also fine. i can get idea.
    Thanks
    selva

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

      Hi Selva,

      You can probably use an if condition inside the loop and break. But i am not completely sure of this and may need to see what exactly the app does.

      Thanks
      Avinash Shetty

      January 30, 2015
      Reply
      • selva said:

        Hi Ainash,
        Thanks for your information. you are correct i did use that but it fails. I mean it did not break.
        Appium close the app.

        Thanks
        Selva

        January 30, 2015
        Reply
  12. Mohit said:

    Hi Avinash,

    Do you know any python or Xcode command via which I can change the language of my iPhone and iPad to Chinese or some other language after which , I will run my script on that particular device?

    Also, on working with iOS devices, if I want to automate the app in many languages, then I can’t find the element by name because that is different in every locale. So, do we only have the option of xpath to do this or is there any other option?

    February 4, 2015
    Reply
  13. selva said:

    Hi
    I would like to compare screenshot taken by appium with manaul screenshot. Could you let me know how i can do this in python.

    Thanks
    selva

    March 24, 2015
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Selva,
      Arun had earlier replied for a similar comment. Please find his comments below

      “I have used image comparison in the non-mobile space. In various projects I used EggPlant, AutoIT and Screenster. I have also written my own Python scripts using a combination of ImageMagick and Python Image Library. How you end up doing image recognition depends on your specific use case. Sometimes its just a matter of scaling the image to a known size, comparing it with a reference and then working out the co-ordinates that you want to click. Other times, it may be a matter of super-imposing two images and taking a pixel by pixel difference (with an error margin) to determine an exact match.

      Having said all that, I would strongly discourage you from using image comparisons unless that is literally your last unexplored alternative. To date, I have not found a single tool that is based on image recognition that is even moderately robust enough for professional use.”

      You can also probably try automated-screenshot-diff.

      April 15, 2015
      Reply
      • selva said:

        Hi,
        Thanks for this information. I will look at this. sorry to get back to you so late.

        Regards
        selva

        June 13, 2015
        Reply
  14. Vaishali said:

    Hi Avinash,

    I am trying to automate an android app using appium- keyword driven framework which includes methods (keywords) as actions . So if i use UNITTEST for these kind of frameworks will it be feasible? or any suggestion on this?

    April 8, 2015
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Vaishali,

      May be UnitTest would work. Can you let me know what language you are using here?

      April 14, 2015
      Reply
  15. Deepa said:

    Hi,
    I am very new to automation …. Moving from manual to automation now.
    Trying to install Appium but there is no proper documentation to install Appium on Ubuntu.
    Looking forward for the same.

    Thankyou in Advance.

    good articles……………..

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

      Hi Deepa,
      I found this stack overflow answer useful while trying to install appium in Ubuntu

      http://stackoverflow.com/questions/22374416/how-to-setup-appium-in-ubuntu-for-android/23263166#23263166

      The steps which i tried are following

      Download latest nodejs linux binaries from http://nodejs.org/download/

      Extract into a folder that doesn’t need sudo rights to access, for example your home folder.

      tar -xvf
      Add the following line to your ~/.bashrc file.

      export PATH=$PATH:/bin
      Open a now terminal and do

      npm install -g appium

      Ran into permission issue while running appium
      So i set the path of appium bin in .bashrc file as

      export PATH=:$PATH

      After this I could run appium successfully.

      Regards
      Avinash Shetty

      May 8, 2015
      Reply
  16. giri said:

    Hi Avinash,

    This atricle is very good.i am very new to appium.i am trying to automate one android app.for that i need to login by using my company credentials.before doing complete login i am trying to validate the login functionality.that means if i didnt enter the username, i am getting ptompt like field shouldnt be empty message.i am not able to capture that prompt in uiautomator and not able to print that message.unable to attache the image here to give you the clear explanation.

    please give some suggestions.its very useful for me.

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

      Hi Giri,
      Thanks for your comments. Probably you can check with the Development team. They should have details on the prompt so that you can capture it.

      Regards
      Avinash Shetty

      May 19, 2015
      Reply
  17. Mohit said:

    Hi Avinash,

    I am using the same method self.driver.get_screenshot_as_file(filename) for taking a screenshot and it was working fine for me till now.
    But now, I have to take a screenshot of a tooltip which appears after you click an element. That tooltip appears on the screen for one second.
    Since there is inherent delay of 1 sec in executing every command on a real device., I miss taking that particular screenshot.
    Any ideas which you can think of taking this screenshot?

    Thanks in advance.

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

      Hi Mohit,
      I am not aware of any 1 sec delay. As per appium documentation (http://appium.io/slate/en/master/?javascript#server-flags) IOS has a weird built-in unavoidable delay. We patch this in appium. If you do not want it patched, pass in this flag.
      I am not sure how you can capture the tooltip if it goes off immediately before you capture the screenshot.
      Regards
      Avinash

      May 19, 2015
      Reply
  18. vinod said:

    Hi friends am using python language to automate mobile apps with appium,
    Can any one suggest me how to do datadriven/keyword driven testing in appium using python script.
    your help will be well appriciated.

    Thx
    vinod

    June 24, 2015
    Reply
  19. Jennifer said:

    hello,
    Can you provide me the exact link to download the python library for this project, also we dont require to import selenium jar files in the projet as we do in case of TestNG frameworks?

    October 5, 2015
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Jennifer,
      You can download python 2.7.10 from link here. After this install selenium using pip (pip install -U selenium). This installs selenium in python site packages. Once you have this you don’t need to add selenium jar’s to the project separately as you do in Java.

      October 6, 2015
      Reply
  20. Anonymous said:

    I am writing automation script using automation tool appium using java.
    1)I would like to know how to write script using only below data
    type: android.widget.CheckedTextView
    text: hgad@gmail.com
    index: 4
    enabled: true
    location: {87, 1135}
    size: {906, 144}
    checkable: true
    checked: false
    focusable: false
    clickable: true
    long-clickable: false
    package: com.google.android.gms
    password: false

    2) This method doesn’t auto populate when I type driver. please help me how can I get it…..driver.elementsByAndroidUIAutomator

    driver.elementsByAndroidUIAutomator(“new UiSelector().className(android.widget.ListView).childSelector(new UiSelector().className(android.widget.LinearLayout).clickable(true))”);

    October 8, 2015
    Reply
  21. Tomas said:

    Hello,

    Thanks you for a nice presentation on using Appium on real device. I am new to this and it was very useful introduction. I have a little comment to the code though:
    “elmnt = self.driver.find_element_by_xpath(“//android.widget.LinearLayout[@index=0]”)
    elmnt.click()”
    Actually returns Wawrinka for me. Probably because it gets confused with what to choose as Rank has the same class and also refers to index 0. It helped me to do a small change: “elmnt = self.driver.find_element_by_xpath(“//android.widget.LinearLayout[@resource-id=’atpwta.live:id/RankingItemViewRoot’and android.widget.LinearLayout[@index=0]]”)”

    Once again thank you for a nice introduction!
    Cheers

    November 30, 2015
    Reply
  22. Deepa said:

    i m launching a site in chrome
    i m not getting the path of urls of that site
    could you please provide me with the documentation for the same or any further help

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

      Hi Deepa,
      Can you please let me know what exact issue are you facing? Error message and when are you getting the error would help

      January 27, 2016
      Reply
  23. Karthik said:

    Hi Avinash,
    I am working on Ubuntu 14.04. I have installed Appium 1.4.13. I have test cases written in Python. Everything works fine . Now, I need to create a report of the outputs.
    How can I do that ??

    March 7, 2016
    Reply
    • Avinash Shetty Avinash Shetty said:

      Hi Karthik,
      As of now I don’t have a good reporting capability. If I have something will update you on it

      March 18, 2016
      Reply
  24. Apurva said:

    Hi,

    I have used the same code as urs and have just changed the required things according to my app.
    I am getting this error
    selenium.common.exceptions.WebDriverException: Message:

    ———————————————————————-
    Ran 1 test in 0.032s

    FAILED (errors=1)

    The message column is blank and nothing is happening in mobile device. I have checked with avd devices, my device is recognized so device recognition is not a problem.

    Plus can you elaborate what is the funtion of xpath()

    March 31, 2016
    Reply
    • Apurva said:

      this is the complete error
      Traceback (most recent call last):
      File “D:\automation\appium_samples\getting_Started.py”, line 21, in setUp
      self.driver = webdriver.Remote(‘http://localhost:4723/wd/hub’, desired_caps)
      File “C:\Python34\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 “C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 91, in __init__
      self.start_session(desired_capabilities, browser_profile)
      File “C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 173, in start_session
      ‘desiredCapabilities’: desired_capabilities,
      File “C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 233, in execute
      self.error_handler.check_response(response)
      File “C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py”, line 165, in check_response
      raise exception_class(value)
      selenium.common.exceptions.WebDriverException: Message:

      March 31, 2016
      Reply
      • Avinash Shetty Avinash Shetty said:

        Hi Apurva,
        I couldn’t figure out much looking at that error message except there is something wrong with the desiredCapabilities which you have set in line 173.

        April 7, 2016
        Reply
  25. Rashmi said:

    Hi Avinash,
    You blog is very good and helpfull .Have you written any blog on how to write framework on Appium python for mobile application . Could you please provide any on this ?
    Thanks in advance.

    October 27, 2016
    Reply
    • Shivahari P Shivahari P said:

      Hi Rashmi,
      Thanks for taking time to write to us. We don’t have any blog on Mobile framework yet. We may decide to write about it in the coming days, please leave a note if you wish to be notified when we do.
      Regards

      November 2, 2016
      Reply
  26. Siddhesh said:

    Hi,

    It’s really good article to go with, I wold like to know more about parallel execution. Is it possible to achieve this? Yes, Can you please give an example?

    November 29, 2016
    Reply
    • Siddhesh, sorry about the late reply. We totally missed your comment.

      To run Appium tests in parallel, you would start multiple Appium servers, designate one as the main Appium port and the rest as bootstrap ports. You’ll need to associate each server with a device id too.

      Use this as a reference: http://appium.readthedocs.io/en/stable/en/appium-setup/parallel_tests/

      And when you are able to do this, how about writing a blog post of your own that the rest of us can refer to ;)?

      December 25, 2016
      Reply
  27. Anonymous said:

    Hi There,
    I would like to know if appium test results can be integrated with testrail test management tool. If so could you please let me know the steps to do that.
    Thanks
    Mohan

    December 11, 2016
    Reply
  28. Mohan said:

    Hi There,
    I really liked your wlog about the testrail integration with selenium. now im interested to know whether appium can be integrated with testrail i.e. appium test results can be updated and reflected via testrail

    December 11, 2016
    Reply
  29. Raj said:

    Hi Avinash Sir,

    Could you please help me to test Web Application by using chrome browser by using a real devices ?
    Kindly give me few of the example to navigate to any web application and perform some actions by using xpath ad all on real android device

    Regards
    Raj

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

      Hi Raj,
      The example shown in this blog is testing an app on a real device. Unfortunately i don’t have an example to share with you for working on a web app on chrome browser.
      As per the link suggested “http://appium.io/slate/en/v1.3.4/?python#mobile-chrome-on-emulator-or-real-device” the things which you need to take care of is
      1) Make sure Chrome (an app with the package com.android.chrome) is installed on your device
      2) Add desired capabilities like these to run your test
      {
      ‘platformName’: ‘Android’,
      ‘platformVersion’: ‘4.4’,
      ‘deviceName’: ‘YOUR DEVICE NAME,
      ‘browserName’: ‘Chrome’
      }

      January 6, 2017
      Reply
  30. Roshni said:

    Hi,

    I have followed the exact steps given here, however I am getting the below error. I have restarted appium server several times. Still I am getting the same error.

    Error
    Traceback (most recent call last):
    File “C:\Python27\lib\unittest\case.py”, line 320, in run
    self.setUp()
    File “D:\python_program\calci\atp.py”, line 20, 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, 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 87, in __init__
    self.start_session(desired_capabilities, browser_profile)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 141, in start_session
    ‘desiredCapabilities’: desired_capabilities,
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py”, line 199, in execute
    response = self.command_executor.execute(driver_command, params)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 395, in execute
    return self._request(command_info[0], url, body=data)
    File “C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py”, line 463, in _request
    resp = opener.open(request, timeout=self._timeout)
    File “C:\Python27\lib\urllib2.py”, line 429, in open
    response = self._open(req, data)
    File “C:\Python27\lib\urllib2.py”, line 447, in _open
    ‘_open’, req)
    File “C:\Python27\lib\urllib2.py”, line 407, in _call_chain
    result = func(*args)
    File “C:\Python27\lib\urllib2.py”, line 1228, in http_open
    return self.do_open(httplib.HTTPConnection, req)
    File “C:\Python27\lib\urllib2.py”, line 1198, in do_open
    raise URLError(err)
    URLError:

    Also at appium side I am getting below error,

    Launching Appium server with command: C:\Program Files (x86)\Appium\node.exe lib\server\main.js –address 127.0.0.1 –port 4723 –pre-launch –platform-name Android –platform-version 23 –automation-name Appium –device-name “38fcda2f” –log-no-color
    > info: [debug] Starting Appium in pre-launch mode
    > info: Pre-launching app
    > info: [debug] No appActivity desired capability or server param. Parsing from apk.
    > info: [debug] No appPackage desired capability or server param. Parsing from apk.
    > error: No app set; either start appium with –app or pass in an ‘app’ value in desired capabilities, or set androidPackage to launch pre-existing app on device
    > info: [debug] Got configuration error, not starting session
    > info: [debug] Cleaning up appium session
    > error: Could not pre-launch appium: Error: No app set; either start appium with –app or pass in an ‘app’ value in desired capabilities, or set androidPackage to launch pre-existing app on device
    >

    July 14, 2017
    Reply
    • Rohan Joshi Rohan Joshi said:

      Hii Roshni,
      1. Are you testing in Simulator or real physical device?
      2. Do you have the app already installed, if not then get the .apk file of the app and set ‘app’ field in desired capabilities with the path of the .apk file .Refer https://qxf2.com/blog/appium-mobile-automation/ on how to set desired capabilities for ‘app’ field.
      3. If this doesn’t solve your problem then kindly tell us what desired capabilities are you passing in setup code.

      July 17, 2017
      Reply
      • Roshni said:

        Hi Rohan,
        Thanks for the quick reply. I have already installed the app mentioned in this article on my device. I am not using any simulator.
        The below are the desired capabilities which I have mentioned in the program,
        def setUp(self):
        “Setup for the test”
        desired_caps = {}
        desired_caps[‘platformName’] = ‘Android’
        desired_caps[‘platformVersion’] = ‘6.0.1’
        desired_caps[‘deviceName’] = ’38fcda2f’
        # Since the app is already installed launching it using package and activity name
        desired_caps[‘appPackage’] = ‘atpwta.live’
        desired_caps[‘appActivity’] = ‘.activity.Main’
        # Adding appWait Activity since the activity name changes as the focus shifts to the ATP WTA app’s first page
        desired_caps[‘appWaitActivity’] = ‘.activity.root.TournamentList’
        self.driver = webdriver.Remote(‘http://127.0.0.1:4722/wd/hub’, desired_caps)

        Also, this http://127.0.0.1:4722 , I have mentioned in appium server settings.

        July 17, 2017
        Reply
        • Avinash Shetty Avinash Shetty said:

          Hi Roshini,
          Sorry for the delayed response. Your desired capabilities seem to be fine. I am not sure why you are getting the error. Probably you can try these two things
          1) Double check the appPackage and appActivity name of the app. If that’s fine try the below approach also
          2) Get the .apk file of the app and set ‘app’ field in desired capabilities with the path of the .apk file.

          Thanks & Regards
          Avinash Shetty

          July 20, 2017
          Reply
  31. Roshni said:

    Hi,

    Today I am getting an another error of URLError:

    Any help will be appreciated.

    July 18, 2017
    Reply

Leave a Reply to selva Cancel reply

Your email address will not be published.