Python scripts automate testing of mobile applications on the Appium library _python

Source: Internet
Author: User
Tags virtual environment appium in python

The most cool thing about automated functional testing with Appium is that you can write your test code in any language that is best suited to your test tools. One of the most common test programming languages you choose is Python. Using Appium and Python to write test code for iOS and Android apps is easy.

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

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


I also need to install all of appium dependencies and compile the sample apps. You can complete this task by running the following command in the Appium working directory:

$./reset.sh--ios

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

$ grunt Appium

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

$ 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 just ran. The test starts with the sample application, then fills in several input boxes, and finally makes a comparison between the results and the expected 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 applications we want to test. We then added a teardown method that sent an exit command after each test was completed:

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

Finally, we define the auxiliary method and the main test method for filling in the form:


Def_populate (self):
  # Populate text fields with two 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 button
  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 Appium sample test code. If you have any questions or comments about running the Appium test using nose and python, please let me know.

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.