adoptionAppiumOne of the coolest things about doing automated functional testing is that you can write your test code in whichever language has the most appropriate testing tools for you. One of the most popular test programming languages that people choose is Python. Writing test code for iOS and Android apps is very easy using Appium and Python.
In this blog post we'll go into more detail about using Appium under theExample code for a test written in PythonmisidentificationSample apps for iOSThe various steps involved in conducting a test are very similar to the steps required to test an Android application.
To get started, fork and clone Appium from /appium/appiumfork, then follow the installation guide and get Appium installed on your machine.
I also need to install all of Appium's dependencies and compile the sample apps. This can be done by running the following commands in Appium's working directory:
$ ./ --ios
Once the compilation is complete, you can run the following command to start Appium:
$ grunt appium
Now that Appium is up and running, it's time to switch the current directory to sample-code/examples/python. then use the pip command to install all the dependent libraries (you'll need to use the sudo command if you're not under the virtual environment virtualenv):
$ pip install -r
Next run the sample test:
$ nosetests
Now that we have installed the required software and run the test code to get a general idea of how Appium works, let's take a look at the sample test code we just ran in further detail. The test starts the sample application, then fills in a couple of input boxes, and finally compares the results of the run with the desired results. First, we created the test class and its setUp method:
classTestSequenceFunctions(): defsetUp(self): app=((__file__), '../../apps/TestApp/build/Release-iphonesimulator', '') app=(app) =( command_executor='http://127.0.0.1:4723/wd/hub', desired_capabilities={ 'browserName':'iOS', 'platform':'Mac', 'version':'6.0', 'app': app }) self._values=[]
The "desired_capabilities" parameter is used to specify the platform (iOS 6.0) and the application we want to test. Next we added a tearDown method that sends an exit command after each test is completed:
deftearDown(self): ()
Finally, we define the helper and main test methods used to fill out the form:
def_populate(self): # populate text fields with two random number elems=.find_elements_by_tag_name('textField') foreleminelems: rndNum=randint(0,10) elem.send_keys(rndNum) self._values.append(rndNum) deftest_ui_computation(self): # populate text fields with values self._populate() # trigger computation by using the button buttons=.find_elements_by_tag_name("button") buttons[0].click() # is sum equal ? texts=.find_elements_by_tag_name("staticText") (int(texts[0].text),self._values[0]+self._values[1])
That's it! There are many more Python examples in Appium's sample test code. If you have any questions or comments about using Nose and Python to run Appium tests, please let us know.