Everything has, only owe code!
Here is a simple example that verifies the common sign-in functionality. The application of this example is being developed by my company and is not officially on-line, it does not provide the download path. Login function is used in many applications, this everyone knows what kind of function.
First, look at the code for the Resource.txt file:
Settings ***library appiumlibrary*** Variables ***${remote_url} http://192.168.1.6:4723/wd/hub${ Platform_name} Ios${platform_version} 8.3${device_name} iPhone 5s${app} /users/admin/xxx_ios/ Xxx/build/debug-iphonesimulator/xxx.app${user} 138****6789${password} 888888*** Keywords ***Setup Open application Remote_url=${remote_url} platformname=${platform_name} platformversion=${ Platform_version} Devicename=${device_name} App=${app} short Sleep Swipe 200 #滑动 Short Sleep Swipe 500 #滑动 Short Sleep Click Element xpath=//uiaapplication[1]/uiawindow[1]/uiabutton[1] #点击立即体验 Short Sleepteardown Close All applications
Simply explained, because the test with appium, so add appiumlibrary in the settings, also need to install appiumlibrary in OS X, the specific installation method can refer to the previous article appium+ Robotframework implements automated test -4:appiumlibrary introduction and installation for Android applications.
The parameters required to run the Appium are set in the following variables, as described below:
${remote_url}: Remote URL, refers to the address of the Appium and the port number, after the/wd/hub is a fixed format, please do not change.
${platform_name}: Platform name, we test in iOS, can only write iOS.
${platform_version}: Platform version, i.e. IOS version number, which is available by running the command in the terminal of OS X Xcodebuild-showsdks know the version number, as shown in thespecific use of xcodebuild instructions you can find the information yourself .
${device_name}: Device name, even if the name of the Apple device, be careful to match the above version number.
${app}: The full path of the APP to be tested, note that this path refers to the path of the machine relative to the Appium, which is the path on the machine where OS X resides, using the Xcodebuild The app files that are obtained after the instruction is compiled.
${user}: Login user name, because the mobile phone number as login, so here is actually the user's complete mobile phone number.
${password}: The password for the logged-on user name.
The setup in keywords automatically executes the script here when the test starts, first by installing and opening the app with the Open application keyword (if it was previously installed, it will be uninstalled automatically), and then because the app has two welcome screens, Therefore, you need to go to the start page by performing a swipe to the left with the swipe keyword, and then click on the button of the element keyword to enter the homepage.
It is important to note that because appiumlibrary do not have keywords to wait for the duration of the keyword, here are used for short sleep to use as the wait time between the execution of the keyword, the little sleep keyword is a custom keyword, in fact, is the package of sleep X, The specific wait length x can be set according to the actual situation.
Teardown will automatically execute the script here at the end of the test, and simply call close all applications to close all applications.
Next look at the specific login verification script:
TestCase Authentication login Click Element name= login/Register short Sleep Input Value xpath=//uiaapplication[1]/uiawindow[1]/ui ATEXTFIELD[1] ${user}1 #输入错误用户名 Input Text xpath=//uiaapplication[1]/uiawindow[1]/uiasecuretextfield[1] ${P Assword} #密码 Click element name= login Page should contain element name= login #停留在登录页面 Input Value xpath= UIAAPPLICATION[1]/UIAWINDOW[1]/UIATEXTFIELD[1] ${user} #正确用户名 Input Text Xpath=//uiaapplication[1]/uiawindow [1]/uiasecuretextfield[1] ${password}a #输入错误密码 Click element name= login Page should contain Element name= login #停留在登录页面 input Value xpath=//uiaapplication[1]/uiawindow[1]/uiatextfield[1] ${user} #正确用户名 input Text XPATH=//UIAAPPLICATION[1]/UIAWINDOW[1]/UIASECURETEXTFIELD[1] ${password} #输入正确密码 Click Element name= Login Sh ORT Sleep Element Name should be xpath=//uiaapplication[1]/uiawindow[1]/uiatableview[1]/uiastatictext[5] xxx #验证登录后显示的用户是指定的用户Here is the first to have two negative test verification: Enter the wrong user name and enter the wrong password after logging in, expect the result should be login failure, still on the login page, after the positive verification, enter the correct user name and password should be logged in successfully and can display the user's user name, the script is simple, no longer repeat.
Please continue to pay attention to ...
This article copyright to the Green Tree all, welcome reprint, but please specify the author and source, strictly prohibited for any commercial use, otherwise the consequences!
Appium+robotframework automated testing for iOS apps-5: A simple example