Background
Recently the Android side do a little irritability, the main or our third party pack of Android, resulting in more than the limit of Google, can not play out the package, a lot of H5 part of the test, our Android development is always used to prohibit the webview handle, to the activity plus permissions, resulting in a variety of errors run out of the results, For a different flavor, play iOS automation.
Conditions
Testing iOS must be a Mac OS x System , please do not ask if you can use Windows to test this problem with iOS.
My computer is the latest version, such as the system, such as Xcode, such as Appium.
Original intention
I am more lazy, do not want to see those English, the results of the search came out, is basically not what I want, as if the whole network is the great God, and no one to write such a hands-on guide How to run the official demo tutorial, had to run a feeling.
Official demo
The official demo is certainly the best of a thing, but the official introduction is also very short, but also in English. There is a full official demo source on GitHub. All at once down. You can find the iOS test pack in apps. That's the thing.
Run.
Running is very simple, if the appium environment is normal, then just start the Appium service, and then execute the Python demo code on the line.
The official note is this:
These is simple samples of the use Python to run Appium tests. It is suggested, so you use a test runner such as Pytest or nose.
Sauce Labs examples require at least version 0.12 of the Appium Python Client, which includes the Appium. Saucetestcase base class.
Usage:py.test ios_simple.pypy.test -n2 --boxed ios_simple.py
After successful execution, the result looks like this.
Different bash show is not the same, during the execution you can see in the iOS simulator launch, and then launch the official demo, to perform the entire process of these two use cases
Description of Demo
In fact, the official demo is very simple, you do not need to know how the iOS code is running up. The demo is written based on the UnitTest test framework. Do not understand, please in my blog to turn over how they run.
Initialize Driver
class simpleiostests(unittest. TestCase): def setUp(self): # set up AppiumApp = Os.path.abspath ('. /.. /apps/testapp/build/release-iphonesimulator/testapp.app ') Self.driver = Webdriver. Remote (command_executor=' Http://127.0.0.1:4723/wd/hub ', desired_capabilities={' app ': Apps,' PlatformName ':' IOS ',' Platformversion ':' 9.3 ',' DeviceName ':' IPhone 6 '})
You can see several parameters that are important in the initialization, the app path, the system name, the system version, and the device name.
From these parameters, test iOS with the simulator must have the source code , if there is no source of your first app path also can not fill.
First Test case
def test_scroll(self):Els = Self.driver.find_elements_by_class_name (' Uiabutton ') els[5].click () Sleep (1)Try: el = self.driver.find_element_by_accessibility_id (' OK ') El.click () Sleep (1)except:PassEl = Self.driver.find_element_by_xpath ('//uiamapview[1] ') location = El.location Self.driver.swipe (start_x=location[' x '], start_y=location[' y '], end_x=0.5, end_y=location[' y '], duration= -)
There's nothing to explain about this use case, and the use of Appium on Android is basically a consistent way of using it. First find classname is the Uiabutton element click. Then do a sliding operation.
Second Test case
def _populate(self): # Populate text fields with both random numbersEls = [Self.driver.find_element_by_name (' TextField1 '), Self.driver.find_element_by_name (' TextField2 ')] Self._sum =0 forIinchRange2): rnd = Randint (0,Ten) Els[i].send_keys (rnd) Self._sum + = Rnd def test_ui_computation(self): # Populate text fields with valuesSelf._populate ()# Trigger computation by using the buttonSELF.DRIVER.FIND_ELEMENT_BY_ACCESSIBILITY_ID (' Computesumbutton '). Click ()# is sum equal? # sauce does not handle class name, so get fourth elementsum = Self.driver.find_element_by_name (' Answer '). Text self.assertequal (int (sum), self._sum)
In simple terms, two input boxes randomly enter a number within 10, sum, and then the next assertion. The code looks fairly simple, no wonder no one would want to write a tutorial, because it's basically down and down and just running.
At last
Appium has a common problem whether it's Android or iOS. Efficiency is low. The official two demo so simple example, the implementation needs 1 minutes and a half, if the test case more, a run is a day!
A glimpse of Appium learning-ios