Parallel execution under CMD appium +maven+testng test

Source: Internet
Author: User
Tags appium testng

1:

First:open command wins to start Appium:

Appium-p 4725-BP 4726-u Ep7333w0ur

Appium-p 4723-BP 4724-u 3a2acab

Thus,appium server for the devices have started

2:

Go to the directory of the project:

Cd/users/huangxiaoshi/documents/eclipse/test2

3:

Import the Lib files:

MVN Dependency:copy-dependencies-doutputdirectory=lib

4:

Decode to produce the class file:

MVN Clean Test

5:

Finally execute:

Java-classpath "/users/huangxiaoshi/documents/eclipse/test2/target/test-classes/:/users/huangxiaoshi/documents/ Eclipse/test2/lib/testng-6.3.1.jar "-djava.ext.dirs=lib org.testng.testng-suitethreadpoolsize 2 Testng1.xml Testng2.xml

If you have the set the CLASSPATH Of/users/huangxiaoshi/documents/eclipse/test2/lib/testng-6.3.1.jar

You can execute like this:

Java-classpath "/users/huangxiaoshi/documents/eclipse/test2/target/test-classes/"-Djava.ext.dirs=lib Org.testng.testng-suitethreadpoolsize 2 Testng1.xml Testng2.xml

6:

Check the test output files.

Below turn from: https://testerhome.com/topics/1639

First, test class * Note 1

PackageCom.Testerhome;ImportIo.appium.java_client.android.AndroidDriver;ImportJava.net.MalformedURLException;ImportJava.net.URL;ImportOrg.openqa.selenium.By;ImportOrg.openqa.selenium.WebElement;ImportOrg.openqa.selenium.remote.DesiredCapabilities;ImportOrg.testng.annotations.BeforeSuite;ImportOrg.testng.annotations.Parameters;ImportOrg.testng.annotations.Test;ImportOrg.testng.annotations.BeforeClass;ImportOrg.testng.annotations.AfterClass;PublicClassSuite1{PublicStringPort;PublicStringUdid;PrivateAndroiddriverDriver;@TestPublicvoidSwitches()ThrowsInterruptedexception{WebelementSound=Driver.Findelementbyandroiduiautomator("New Uiselector (). Text (\" sound\ ")");Sound.Click();System.Out.println("Checked");Thread.Sleep(2000);System.Out.println(Thread.CurrentThread());}@BeforeSuite@Parameters({"Port","Udid"})PublicvoidBeforesuite(StringPort,StringUdid){This.Port=Port;This.Udid=Udid;}@BeforeClassPublicvoidBeforeclass()ThrowsMalformedurlexception{System.Out.println(“PortIs”+Port+“,UdidIs"+ Udid); Desiredcapabilities capabilities = new Desiredcapabilities (); Capabilities.setcapability ("DeviceName","Device"); Capabilities.setcapability ("Automationname","Appium"); Capabilities.setcapability ("Platformversion", "4.4"); Capabilities.setcapability ("udidapppackage", "com.< Span class= "NA" >android.appactivity", ". Settingshttp://127.0.0.1:" + port + "/wd/hub"), capabilities);   @AfterClass public void  Afterclass () {driver. Quit (); }             /span>                

Second, connect two Android devices or start two virtual machines
Use
adb devices
Get Udid

Iii. two new Testng.xml under Project path
Testng1.xml

<?xml version= "1.0" encoding= "UTF-8"?> <suite name=< Span class= "s" "Suite1" > <parameter name =  "port" value =  "4723" /> < Parameter name =  "Udid" value =  "emulator-5554" Span class= "NT" >/> <test name= "test" > <classes> <class name= " Com.testerhome.Suite1 "/> </classes> </test> Span class= "NT" ></suite>             

Testng2.xml

<?xml version= "1.0" encoding= "UTF-8"?> <suite name=< Span class= "s" "Suite2" > <parameter name =  "port" value =  "4725" /> < Parameter name =  "Udid" value =  "emulator-5556" Span class= "NT" >/> <test name= "test" > <classes> <class name= " Com.testerhome.Suite1 "/> </classes> </test> Span class= "NT" ></suite>             

Four, open two Appium server * Note 2, note 3
If the command line starts with the add parameter
appium -p 4723 -bp 4724
appium -p 4725 -bp 4726

If it is a graphical interface, modify:
The first one:
The Port in general Settings, changed to 4723
Bootstrap Port in Android Settings, instead of 4724

The second one:
The Port in general Settings, changed to 4725
Bootstrap Port in Android Settings, instead of 4726

Five, export dependence * Note 4
Because it was created with a MAVEN project, the pilot is dependent on the Lib folder under the project path
mvn dependency:copy-dependencies -DoutputDirectory=lib

VI. implementation of the test
First run with Maven serially to compile the class file
mvn clean test
And then
java -classpath ".\target\test-classes" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml
If the TESTNG environment variable is not configured
java -classpath ".\target\test-classes;D:\Programs\testng-6.8\testng-6.8.jar" -Djava.ext.dirs=lib org.testng.TestNG -suitethreadpoolsize 2 testng1.xml testng2.xml

Vii. Viewing reports
Default Test-output folder under Project path

Note 1:
This test class does not specify an app path and, if specified, conflicts when unzip. Now there are multiple apk copies.
File app = new file (appdir, "AppName" +port+ ". apk");
and specify a different temporary file path in the Appium server, such as:
--tmp D:\tem1
--tmp D:\tem2

NOTE 2:
The two-port introduction can look at these two links:
Appium Automated Test Tutorial ppt (second edition)
Appium Android Bootstrap Source code analysis of the introduction

Note 3:
If you use to Selendroid or Chromium, you also need to specify a different port (you need to modify the test class)
Selendroid port:8080
Selendroid port:8081
Chromium port:9515
Chromium port:9516

Note 4:
Originally intended to be executed directly in parallel with MVN test, but did not try to pass the Suitethreadpoolsize parameter method

Parallel execution under CMD appium +maven+testng test

Related Article

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.