Most of our case branch have been supported by iOS, or Android. If you want to automate both ends, write only two copies of the code. After learning about Appium and testng, we started experimenting with the same set of code in automation, which supports iOS and Android. It is hoped that this approach will improve the efficiency of our automation development.
1.case Code Support 1.1 Business case Section
If iOS and Android interact similarly with the same functionality, we can use the same set of business case codes. Appium is basically consistent with the operating interface of iOS and Android systems. If not, you can use driver instanceof iosdriver or driver instanceof androiddriver to make a branch decision.
Example:
public void Login () throws exception{//here iOS is different from the Android app, so it's handled differently. if (driver instanceof iosdriver) { loginpage.getotherwaytologin (). click (); Loginpage.getbtnusepassword (). click (); } Assert.asserttrue (Loginpage.setphone (Testdata.account), "Unable to enter the correct phone"); if (driver instanceof androiddriver) { loginpage.getbtnnext (). click (); Loginpage.getbtnusepassword (). click (); } Getautomationutil (). SetValue (Loginpage.getedtxtpassword (), Testdata.password); Loginpage.getbtnlogin (). click (); Assert.asserttrue (Loginpage.getmenubutton ()! = NULL, "Suspect login not successful"); }
1.2 Page class
The elements used in the business case are dependent on the page class for identification. Use the notation provided by Appium to write code in a concise manner. Example:
public class LoginPage extends basepage{ @AndroidFindBy (uiautomator = "New Uiselector ()." ResourceId (\ "xxx:id/xxxx\ ")") @iOSXCUITFindBy (accessibility = "consent") private mobileelement btnprivacyruleagree; @iOSXCUITFindBy (accessibility = "Log in using other means") private mobileelement otherwaytologin; Public Mobileelement Getotherwaytologin () { return otherwaytologin; } Public Mobileelement Getbtnprivacyruleagree () { return btnprivacyruleagree; } ...} public class BasePage {public basepage (appiumdriver<webelement> driver) { //appium uses this code to support annotation positioning elements pagefactory.initelements (New appiumfielddecorator (Driver, new Timeoutduration (Timeunit.seconds)), this); } ...}
2. TESTNG supports 2.1 testng case related configuration
TestNG can divide the case into groups, and each time the specified case group is run according to the suit configuration.
You can use dependsongroups to represent dependencies, such as if you must run the Ios_login group case before you can run the Ios_case group.
Priority can be used to prioritize case in the same group. The higher the value, the more first the run, the default value is 0, and the order of the case with the same value is determined by testng.
@Test (groups = {"Ios_login", "Adr_login"}) public void login () throws exception{...} @Test (groups = "Adr_login", priority = 1) public void Getuuidtest () {...} @Test (enabled = True,groups = "Ios_case", dependsongroups = "ios_login") public void testxxxx () {...}
2.2 TestNG Suit Configuration
TestNG can specify the groupings to run in the suit configuration file. Example, specify three groups to run.
<?xml version= "1.0" encoding= "UTF-8"? ><suite name= "Android-all" > <test name= "Android" > <groups> <run> <include name= "Android_login"/> <include name= "android_cases"/ > <include name= "android_logout"/> </run> </groups> <packages> <package name= "com. HHHH.autotest.cases "/> </packages> </test></suite>
3. Jenkins Job Support
Single branch with iOS or Android only, use the app.properties and testng suit configuration to use the corresponding file content in case. But with Jenkins running automation on the company's automation platform, the App.properties file has been rewritten by the company's automation platform with only a few incoming configurations. To support the same branch measurable ends, the testng suit configuration also requires us to run the automation rewrite. We can rewrite these two files on Jenkins.
3.1 Rewriting App.properties and Testng.xml
In command, YYYY is the name of the job. iOS only uses platformname and automationname;android to transmit PlatformName and appactivity.
Create_app_properties () {if [$platform = = ' IOS '];then ' echo-e "platformname = Ios\nautomationname = Xcuitest" > app.properties "mv app.properties YYYY" echo-e "<?xml version=\" 1.0\ "encoding=\" utf-8\ "? >\n& Lt;suite name=\ "ios-all\" >\n<test name=\ "ios\" >\n<groups>\n<run>\n<include name=\ "Ios_ Login\ "/>\n<include name=\" ios_cases\ "/>\n<include name=\" ios_logout\ "/>" > Testng.xml "echo-e "</run>\n</groups>\n<packages>\n<package name=\" com. Hhhh.autotest.cases\ "/>\n</packages>\n</test>\n</suite>" >> testng.xml "MV Testng.xml Y YYY ' Else ' echo-e "platformname = android\nappactivity=com. HHHH.main.activity.MainSplashActivity "> app.properties" mv app.properties YYYY "echo-e" <?xml vers Ion=\ "1.0\" encoding=\ "utf-8\"? >\n<suite name=\ "android-all\" >\n<test name=\ "android\" >\n< Groups>\n<run> \n<include name=\ "android_login\"/>\n<include name=\ "android_cases\"/>\n<include name=\ "android_ Logout\ "/>" > Testng.xml "echo-e" </run>\n</groups>\n<packages>\n<package name=\ "Com.H Hhh.autotest.cases\ "/>\n</packages>\n</test>\n</suite>" >> testng.xml "MV Testng.xml YY YY '}
Use Appium to support both iOS and Android case structures and Jenkins job configurations