Python and Nose realize automatic test of mobile application

Today I'm talking with you about Python and Nose's automatic testing of mobile applications. I hope it can help you. There's something bad to say. Please give me more advice!

The coolest thing about automated functional testing with Appium is that you can write your test code in any language that has the best testing tools for you. Python is the most widely chosen test programming language. It's easy to write test code for iOS and Android applications using Appium and python.

In this blog, we will explain in detail the steps involved in testing an iOS sample application with the test code written in Python under Appium, and the steps required for testing an Android application are very similar to this.

First, start from https://github.com/appium/appiumfork and clone Appium, then follow the installation guide to install Appium on your machine.

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

$ ./reset.sh --ios

After compiling, 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. Then use the pip command to install all the dependent libraries (if not under the virtualenv, you need to use the sudo command):

$ pip install -r requirements.txt

Next, run the sample test:

$ nosetests simple.py

If for software testing, interface testing, automation testing, interview experience exchange. If you are interested, you can add software test exchange: 1085991341, and there will be technical exchanges with peers.

Now that you have installed the required software and run the test code, and have a general understanding of Appium's work process, let's take a closer look at the sample test code that just ran. This test starts the sample application, fills in some contents in several input boxes, and finally compares the running results with 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 application we want to test. Next, we add a tearDown method and send the exit command after each test:

deftearDown(self):

self.driver.quit()

Finally, we define the auxiliary method and the main test method 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 Appium's sample test code. If you have any questions or comments on using Nose and python to run Appium tests, please let me know. I hope the above content can help you. If you have any friends who have been helped, please comment

Keywords: Programming Python iOS Android pip

Added by sottwell on Wed, 06 May 2020 15:13:20 +0300