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 on multiple platforms (iOS, Android), using the same API. This enables a large or total amount of code reuse between iOS and Android test suites.
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 appium-desktop-Setup-1.5.0-ia32.exe. You can run the exe to install the appium desktop app
2. Download and Install Android Studio
Once you install Android Studio make sure the AVD Manager is also installed as we are going to run our tests on an emulator. Set ANDROID_HOME to be your Android SDK path and add the tools and platform-tools folders to your PATH variable. I could find the Android SDK installed on the below-mentioned path
$\AppData\Local\Android\Sdk
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 set up. Next stop: launch the emulator and start the Appium server.
5. Start the Android Virtual Device (AVD) Manager
Start the Android Studio and launch the Android Virtual Device (AVD) Manager from by clicking on the link as shown in the screenshot below.
Create an emulator with the preferences you need and launch it using the start button
6. Start the Appium server console
Start the Appium server console by double clicking on the Appium file.
7. Launch the Appium node server
Click on the ‘rocket’ icon to launch the Appium node server
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 click on “PLAY” button.
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 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 |
Another approach is using the AndroidManifest.xml which is present in the root directory of all Android applications and has the information we need. You can use Android Studio to view the AndroidManifest.xml file. Go to Build/Analyze APK and select your apk. Then you can see the content of the AndroidManifset file.
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 """ 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'] = '8.0' desired_caps['deviceName'] = 'Pixel' # 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 Chess app launches correctly and click on Play button" element = self.driver.find_element_by_id("uk.co.aifactory.chessfree:id/ButtonPlay") element.click() sleep(5) #---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
5. Check the result
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. If you are looking for Python based mobile automation framework, check out our open-sourced GUI and API automation framework based on the page object model. 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.
© 2013-2018, Vrushali Toshniwal. All rights reserved.

[…] Getting Started With Mobile Automation: Appium & Python – Qxf2 – http://qxf2.com/blog/appium-mobile-automation/ […]
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.
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.
Hi, Thank you for the useful posts.I am just starting on automation with python 2.7 and appium and AWS device farm in my company.Please could you provide some posts for these to guide me as a starter.
Hi Rajkhowa,
I have not tried this. But i found this link on how to test an ios app on AWS device farm using Appium. This example is using Java. Probably you can refer to this in case you haven’t already had a look at it.
Thanks & Regards
Avinash Shetty
If any steps to setup Appium on Ubuntu and use it with Android emulator can be provided, then it would be of great help.
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.
https://www.built.io/blog/2015/03/start-automating-native-ios-testing-with-appium-using-node-js/
Thanks a lot.
Very useful article.
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…….
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!
Thanks,Article was really Helpful,though i was new to selenium i was able to run the Appium.
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 .
Priya, can you check if adding capabilities.setCapability(“autoAcceptAlerts”, true); works with your version of Appium?
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)
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.
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!
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.
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.
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
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.
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
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.
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.
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?
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
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.
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’
———————————————————————-
Ran 1 test in 0.022s
FAILED (errors=1)
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.
bingo!! thankU
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 …
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 …
Eldad, does the Python script just hang? It will be helpful if you post the entire content of what the Python script writes out.
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
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
Hi,
Thanks on the help , it worked.
The issue was wrong platform-tools folder in my PATH variable..
please help me out
i have a scenario like i need to print all the contacts of the contact list, some contacts are below the screen, it should not print duplicate contacts using appium code.
can you mail me a code
reddynaga33@gmil.com
Nagarjuna, for intelligent scrolling using Appium, please see this post: https://qxf2.com/blog/python-appium-scroll-through-search-result-table/
Very Usefull …….Thank you Can i run both android and iOS scripts in mac using appium +python
can we test a website functionality using appium and selenium scripts??
i want to create selenium scripts to test a website functionality.
actually i wanna perform mobile testing on a website using appium and selenium…
hi,
how do i implement swipe screen. Any advice please?
Hi Selva,
I replied to your comments on other blog regarding swipe functionality.
“http://qxf2.com/blog/appium-tutorial-python-physical-device/”
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.
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
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.
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.
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
For ubuntu
https://coderwall.com/p/rcvkrq/install-nodejs-using-homebrew-and-install-appium
and
https://www.digitalocean.com/community/tutorials/how-to-install-and-use-linuxbrew-on-a-linux-vps
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
Rajendra,
Which version of Appium are you using?
Similar issue was reported https://github.com/appium/appium/issues/2629.
Please take a look
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 ..
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
As a manual QA tester looking to break in to automation (specifically Android automation), this has helped me a lot. Thanks!
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)
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
[…] Follow everything in this link […]
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 ?
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
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 .
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
It helps me to kickstart on writing appium scripts! Really simple and helpful, thanks a lot!
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?
@Sonu Arora: Thank you for your kind words. We will publishing a blog related to automation on Mac very soon. Keep in touch.
Hi Sonu Arora,Here is the link to Get Set Test an iOS app using Appium and Python:https://qxf2.com/blog/get-set-test-an-ios-app-using-appium-and-python/
Why starting/stopping simulator is a manual step instead of part of your test?
Cheers,
Harry
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/
how to print all the contacts of the contact list , using appium code
Nagarjuna, as I understand it, you are already able to access the contact list but want to know how to scroll and avoid duplicates using Appium. You see this post: https://qxf2.com/blog/python-appium-scroll-through-search-result-table/ which shows you how to do something similar.
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?
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.
/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
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).
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?
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
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?
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’)
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?
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)
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”
Hi Satish,
Thanks for sharing your Observation…
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 ?
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.
JLyon, I’m not sure. I haven’t faced this error before. I googled around for ‘appium zipexception’ and thought that this link looked promising: https://github.com/appium/appium/issues/3143
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.
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
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.
Awesome list! 🙂 love your answers.
I am familiar with Python, while in my past life used C++. I am thinking of choosing Python now when deciding to start with Appium (as opposed to Java, that would seem close to C++, natural for me to pickup). Python is super friendly.
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
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.
Hello,
I have Appium version 1.6.5, when running example it reports error:
InvalidSelectorException: Message: Locator Strategy ‘name’ is not supported for this session
When narrow-down it seems that
.find_element_by_name
.find_elements_by_class_name
are not supported in latest versions of Appium anymore.
I was able to use this for the name:
find_element_by_xpath(“//*[contains(@text, ‘PLAY!’)]”)
but this doesn’t work for class_name.
Any suggestions?
I would really like to be able to complete the jump-start example 🙂
Thanks a lot!
Billiana
Billiana, I haven’t tried this, but the general way to write an xPath based on class name would be:
//class[@some_attribute="blah"]
OR//class[contains(@some_attribute,"blah")]
So, in your case, it is probably something like
find_elements_by_xpath("//android.widget.TextView")
.Try it and let us know if it does not work. We can try the example out with Appium 1.6.5 and figure out the solution.
This is great Arunkumar, thanks a lot for your support.
Yes, your example worked perfectly. I was able to get list of all elements and then select one with actual attribute value afterwards.
Alternatively, I have tried specifying text value inline, that worked too.
Your blog is the best! simple and to the point, also fun. Keep up the great work.
Can i use real devices instead of emulator? if yes what are the changes in the code need to be done?
Hii Ravi D,
Yes, you can use real device instead of emulator. Please refer to our blog https://qxf2.com/blog/appium-tutorial-python-physical-device/ which will give you enough idea about how to run python tests on mobile devices.
Hi, I am getting the below error. Please help
from webdriver import WebDriver as Remote
ModuleNotFoundError: No module named ‘webdriver’
Hi SJ,
From your question description, I see that you are importing webdriver incorrectly. It should be from appium import webdriver . If thats not the case then check whether appium is installed correctly and appium is started before you run your tests. If doing above changes don’t fix the issue then let us know the python version you are using.