Python script automates testing of mobile applications on the Appium library

Source: Internet
Author: User
Tags virtual environment appium
Automated functional testing with Appium the coolest thing is that you can write your test code in any language that has the most appropriate test tool for you. One of the most selected test programming languages is Python. It's easy to write test code for iOS and Android apps using Appium and Python.

In this post we will explain in detail the steps involved in testing an iOS sample app using the example code of the test written in Python under Appium, and the steps required to test the Android app are very similar.

Start with Https://github.com/appium/appiumfork and clone Appium, then follow the installation Guide to install the Appium on your machine.


I also need to install all the dependencies of Appium and compile the sample apps. You can do this by running the following command under Appium's working directory:

$./reset.sh--ios

Once the compilation is complete, you can run the following command to start Appium:

$ grunt Appium

Now that the Appium is running, the current directory is switched to Sample-code/examples/python. Then use the PIP command to install all dependent libraries (you will need to use the sudo command if not under the virtualenv of the virtual environment):

$ pip Install-r requirements.txt

Next Run the sample test:

$ nosetests simple.py

Now that you have installed the required software and run the test code to get a general idea of how the Appium works, let's take a closer look at the sample test code that we just ran. The test first launches the sample application, then fills in several input boxes, and finally makes a comparison between the results of the operation and the desired results. First, we created the test class and its Setup method:

Classtestsequencefunctions (unittest. TestCase):   Defsetup (self):    app=os.path.join (Os.path.dirname (__file__),              '. /.. /apps/testapp/build/release-iphonesimulator ',              ' Testapp.app ')    App=os.path.abspath (APP)    self.driver= Webdriver. Remote (      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 running platform (IOS 6.0) and the app we want to test. Next we add a teardown method that sends an exit command after each test is completed:

Defteardown (self):  self.driver.quit ()

Finally, we define the helper methods and main test methods for filling out the form:


Def_populate (self):  # Populate text fields with both random number  Elems=self.driver.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 ton  buttons=self.driver.find_elements_by_tag_name ("button")  Buttons[0].click ()  # is sum equal?  Texts=self.driver.find_elements_by_tag_name ("Statictext")  self.assertequal (int (texts[0].text), self._ VALUES[0]+SELF._VALUES[1])

That's it! There are many examples of Python in the sample test code for Appium. If you have any questions or comments about using nose and python to run the Appium test, kindly inform us.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.