The Python script implements automated testing for mobile applications on the Appium library, pythonappium

Source: Internet
Author: User
Tags appium

The Python script implements automated testing for mobile applications on the Appium library, pythonappium

The coolest thing about automated functional testing with Appium is that you can write your test code in any language that best fits your testing tool. One of the most popular test programming languages is Python. It is very easy to write test code for iOS and Android apps using Appium and Python.

In this blog, we will explain in detail the steps involved in testing an iOS sample application using the example code written in Python under Appium, the steps required for testing Android applications are similar.

Start with https://github.com/appium/appiumforkand clone Appium. then install Appium on your machine according to the installation guide.


I also need to install all the dependencies of Appium and compile the sample apps. Run the following command in the Appium working directory to complete the task:
 

$ ./reset.sh --ios

After compilation, you can run the following command to start Appium:
 

$ grunt appium

Now that Appium is running, switch the current directory to sample-code/examples/python. Run the pip command to install all the dependent libraries (if it is not in the virtual environment virtualenv, you 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, you have a general understanding of the Appium process. Now let's take a closer look at the sample test code just run. This test starts the sample application, then fills in some content in several input boxes, and finally compares the running results with the expected results. First, we created a 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 application we want to test. Next, we added a tearDown method and sent the exit command after each test is completed:
 

deftearDown(self):  self.driver.quit()

Finally, we define the auxiliary method and main test method used to fill 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 Python examples in the sample code of Appium. If you have any questions or opinions about using Nose and Python to run the Appium test, please let us 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.