简体   繁体   中英

Disable parallel execution in maven testng selenium java (using the surefire plugin - it does not run according to the order in the testng.xml)

I'm working on a Maven TestNG Selenium Java project and trying to run my tests by calling my testng.xml from my pom.xml. the project itself works correctly in the non-maven version of it, but when I run it trough the pom.xml file, it just runs all tests in parallel, opens the website and just runs all tests together (and I need to run them by order because they depend on each other, also the @BeforeSuite and @AfterSuite methods work just fine, the problem is on the execution of the @Test type only)

I have tried to follow several guides and similar project examples on the internet, and removed and added dependencies according to them, but none of it seems to work.

this is my current pom.xml (it's a mess by this point):

 <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>ZafulSelMaven4</groupId> <artifactId>ZafulSelMaven4</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>ZafulSelMaven4</name> <url>http://maven.apache.org</url> <licenses> <license> <name>Apache 2</name> <url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> <distribution>repo</distribution> <comments>A business-friendly OSS license</comments> </license> </licenses> <properties> <maven.compiler.target>1.8</maven.compiler.target> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.argument.target>${maven.compiler.target}</maven.compiler.argument.target> <maven.compiler.argument.source>${maven.compiler.source}</maven.compiler.argument.source> <appium-java-client.version>7.1.0</appium-java-client.version> <spring-boot.version>2.1.6.RELEASE</spring-boot.version> <slf4j.version>1.7.25</slf4j.version> <logback.version>1.2.3</logback.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <suiteXmlFile>testng.xml</suiteXmlFile> <java.version>1.8</java.version> <.--Dependency Versions--> <selenium.version>3.141.59</selenium.version> <assertj-core.version>3.15.0</assertj-core.version> <testng.version>7.1.0</testng.version> <query.version>2.0.0-BETA3</query.version> <.--Plugin Versions--> <driver-binary-downloader-maven-plugin.version>1.0.18</driver-binary-downloader-maven-plugin.version> <maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version> <maven-failsafe-plugin.version>2.22.2</maven-failsafe-plugin.version> <.--Configuration Properties--> <overwrite.binaries>false</overwrite.binaries> <read.timeout>30000</read.timeout> <connection.timeout>40000</connection.timeout> <retry.attempts>4</retry.attempts> <browser>chrome</browser> <threads>1</threads> <remote>false</remote> <headless>true</headless> <seleniumGridURL/> <platform/> <browserVersion/> <proxyEnabled>false</proxyEnabled> <proxyHost/> <proxyPort/> <proxyUsername/> <proxyPassword/> </properties> <dependencies> <dependency> <groupId>io.appium</groupId> <artifactId>java-client</artifactId> <version>${appium-java-client.version}</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.hamcrest</groupId> <artifactId>hamcrest</artifactId> <version>2.2</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> <version>${slf4j.version}</version><.--$NO-MVN-MAN-VER$--> </dependency> <dependency> <groupId>ch.qos.logback</groupId> <artifactId>logback-classic</artifactId> <version>${logback.version}</version><.--$NO-MVN-MAN-VER$--> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-remote-driver</artifactId> <version>${selenium.version}</version><.--$NO-MVN-MAN-VER$--> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>${selenium.version}</version><.--$NO-MVN-MAN-VER$--> <scope>test</scope> </dependency> <dependency> <groupId>org.testng</groupId> <artifactId>testng</artifactId> <version>${testng.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.assertj</groupId> <artifactId>assertj-core</artifactId> <version>${assertj-core.version}</version><.--$NO-MVN-MAN-VER$--> <scope>test</scope> </dependency> <dependency> <groupId>com.lazerycode.selenium</groupId> <artifactId>query</artifactId> <version>${query.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20170516</version> <scope>compile</scope> </dependency> <dependency> <groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> <scope>compile</scope> </dependency> <dependency> <groupId>io.github.bonigarcia</groupId> <artifactId>webdrivermanager</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> </dependencies> <profiles> <profile> <id>selenium-tests</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M3</version> <configuration> <suiteXmlFiles> <suiteXmlFile>${suiteXmlFile}</suiteXmlFile> </suiteXmlFiles> <suitename>Test_Suite</suitename> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> <version>${maven-compiler-plugin.version}</version> </plugin> <plugin> <groupId>com.lazerycode.selenium</groupId> <artifactId>driver-binary-downloader-maven-plugin</artifactId> <version>${driver-binary-downloader-maven-plugin.version}</version> <configuration> <rootStandaloneServerDirectory>${project.basedir}/src/test/resources/selenium_standalone_binaries</rootStandaloneServerDirectory> <downloadedZipFileDirectory>${project.basedir}/src/test/resources/selenium_standalone_zips</downloadedZipFileDirectory> <customRepositoryMap>${project.basedir}/src/test/resources/RepositoryMap.xml</customRepositoryMap> <overwriteFilesThatExist>${overwrite.binaries}</overwriteFilesThatExist> <onlyGetDriversForHostOperatingSystem>false</onlyGetDriversForHostOperatingSystem> <fileDownloadRetryAttempts>${retry.attempts}</fileDownloadRetryAttempts> <fileDownloadReadTimeout>${read.timeout}</fileDownloadReadTimeout> <operatingSystems> <windows>true</windows> <linux>true</linux> <mac>true</mac> </operatingSystems> </configuration> <executions> <execution> <goals> <goal>selenium</goal> </goals> </execution> </executions> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-failsafe-plugin</artifactId> <version>${maven-failsafe-plugin.version}</version> <configuration> <parallel>methods</parallel> <threadCount>${threads}</threadCount> <systemPropertyVariables> <browser>${browser}</browser> <screenshotDirectory>${project.build.directory}/screenshots</screenshotDirectory> <remoteDriver>${remote}</remoteDriver> <gridURL>${seleniumGridURL}</gridURL> <desiredPlatform>${platform}</desiredPlatform> <desiredBrowserVersion>${browserVersion}</desiredBrowserVersion> <proxyEnabled>${proxyEnabled}</proxyEnabled> <proxyHost>${proxyHost}</proxyHost> <proxyPort>${proxyPort}</proxyPort> <proxyUsername>${proxyUsername}</proxyUsername> <proxyPassword>${proxyPassword}</proxyPassword> <headless>${headless}</headless> <.--Set properties passed in by the driver binary downloader--> <webdriver.chrome.driver>${webdriver.chrome.driver}</webdriver.chrome.driver> <webdriver.ie.driver>${webdriver.ie.driver}</webdriver.ie.driver> <webdriver.opera.driver>${webdriver.opera.driver}</webdriver.opera.driver> <webdriver.gecko.driver>${webdriver.gecko.driver}</webdriver.gecko.driver> <webdriver.edge.driver>${webdriver.edge.driver}</webdriver.edge.driver> </systemPropertyVariables> </configuration> <executions> <execution> <goals> <goal>integration-test</goal> <!--This goal makes the build fail if you have test failures--> <goal>verify</goal> </goals> </execution> </executions> </plugin> </plugins> </build> </profile> </profiles> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-dependencies</artifactId> <version>${spring-boot.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> </project>

this is my console after I run my pom.xml file as a maven test:

 [INFO] Scanning for projects... [INFO] [INFO] ------------------------------------------------------------------------ [INFO] Building ZafulSelMaven4 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ ZafulSelMaven4 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 0 resource [INFO] [INFO] --- maven-compiler-plugin:3.8.0:compile (default-compile) @ ZafulSelMaven4 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ ZafulSelMaven4 --- [INFO] Using 'UTF-8' encoding to copy filtered resources. [INFO] Copying 37 resources [INFO] [INFO] --- maven-compiler-plugin:3.8.0:testCompile (default-testCompile) @ ZafulSelMaven4 --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- driver-binary-downloader-maven-plugin:1.0.18:selenium (default) @ ZafulSelMaven4 --- [INFO] [INFO] -------------------------------------------------------- [INFO] DOWNLOADING SELENIUM STAND-ALONE EXECUTABLE BINARIES... [INFO] -------------------------------------------------------- [INFO] [INFO] Repository map 'file:/C:/Users/hagit/workspace/ZafulSelMaven4/src/test/resources/RepositoryMap.xml' is valid [INFO] [INFO] Only get drivers for current Operating System: false [INFO] Archives will be downloaded to 'C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_zips' [INFO] Standalone executable files will be extracted to 'C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_binaries' [INFO] [INFO] Preparing to download Selenium Standalone Executable Binaries... [INFO] Binary 'operadriver' exists: true [INFO] Using existing 'operadriver 'binary. [INFO] Binary 'operadriver' exists: true [INFO] Using existing 'operadriver 'binary. [INFO] Binary 'IEDriverServer.exe' exists: true [INFO] Using existing 'IEDriverServer.exe 'binary. [INFO] Binary 'msedgedriver' exists: true [INFO] Using existing 'msedgedriver 'binary. [INFO] Binary 'chromedriver' exists: true [INFO] Using existing 'chromedriver 'binary. [INFO] Binary 'operadriver.exe' exists: true [INFO] Using existing 'operadriver.exe 'binary. [INFO] Binary 'chromedriver' exists: true [INFO] Using existing 'chromedriver 'binary. [INFO] Binary 'geckodriver.exe' exists: true [INFO] Using existing 'geckodriver.exe 'binary. [INFO] Binary 'msedgedriver.exe' exists: true [INFO] Using existing 'msedgedriver.exe 'binary. [INFO] Binary 'chromedriver.exe' exists: true [INFO] Using existing 'chromedriver.exe 'binary. [INFO] Binary 'geckodriver' exists: true [INFO] Using existing 'geckodriver 'binary. [INFO] Binary 'geckodriver' exists: true [INFO] Using existing 'geckodriver 'binary. [INFO] Setting maven property - ${webdriver.ie.driver} = C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_binaries\windows\internetexplorer\64bit\IEDriverServer.exe [INFO] Setting maven property - ${webdriver.opera.driver} = C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_binaries\windows\operachromium\64bit\operadriver.exe [INFO] Setting maven property - ${webdriver.gecko.driver} = C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_binaries\windows\marionette\64bit\geckodriver.exe [INFO] Setting maven property - ${webdriver.edge.driver} = C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_binaries\windows\edge\64bit\msedgedriver.exe [INFO] Setting maven property - ${webdriver.chrome.driver} = C:\Users\hagit\workspace\ZafulSelMaven4\src\test\resources\selenium_standalone_binaries\windows\googlechrome\64bit\chromedriver.exe [INFO] [INFO] -------------------------------------------------------- [INFO] SELENIUM STAND-ALONE EXECUTABLE DOWNLOADS COMPLETE [INFO] -------------------------------------------------------- [INFO] [INFO] [INFO] --- maven-surefire-plugin:3.0.0-M3:test (default-test) @ ZafulSelMaven4 --- [INFO] [INFO] ------------------------------------------------------- [INFO] TESTS [INFO] ------------------------------------------------------- [INFO] Running TestSuite Zaful_Maven_Project Jul 13, 2020 3:12:56 PM java.util.prefs.WindowsPreferences <init> WARNING: Could not open/create prefs root node Software\JavaSoft\Prefs at root 0x80000002. Windows RegCreateKeyEx(...) returned error code 5. 15:12:57.230 [main] DEBUG io.github.bonigarcia.wdm.Preferences - Preference chrome=83 (valid until 2020-07-13 16:07:04) 15:12:57.241 [main] DEBUG io.github.bonigarcia.wdm.Preferences - Preference chrome83=83.0.4103.39 (valid until 2020-07-13 16:07:04) 15:12:57.242 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Using chromedriver 83.0.4103.39 (since Google Chrome 83 is installed in your machine) 15:12:57.272 [main] DEBUG io.github.bonigarcia.wdm.WebDriverManager - Driver chromedriver 83.0.4103.39 found in cache 15:12:57.273 [main] INFO io.github.bonigarcia.wdm.WebDriverManager - Exporting webdriver.chrome.driver as C:\Users\hagit\.m2\repository\webdriver\chromedriver\win32\83.0.4103.39\chromedriver.exe Local Operating System: WINDOWS 10 Local Architecture: amd64 Selected Browser: chrome Connecting to Selenium Grid: false Starting ChromeDriver 83.0.4103.39 (ccbf011cb2d2b19b506d844400483861342c20cd-refs/branch-heads/4103@{#416}) on port 37771 Only local connections are allowed. Please see https://chromedriver.chromium.org/security-considerations for suggestions on keeping ChromeDriver safe. ChromeDriver was started successfully. Jul 13, 2020 3:13:01 PM org.openqa.selenium.remote.ProtocolHandshake createSession INFO: Detected dialect: W3C Entered Test 1: Open Zaful Written screenshot to target/screenshots\1594642387816_Logo_Exsists.png Entered Test 1: Open Zaful Written screenshot to target/screenshots\1594642392370_Logo_Exsists.png Entered Test 2: Blue Bikini Written screenshot to target/screenshots\1594642393496_Blue_Bikini_List.png Entered Test 3: Black Bikini Like Passed Entered Test 1: Open Zaful Written screenshot to target/screenshots\1594642396467_Logo_Exsists.png Entered Test 2: Blue Bikini Written screenshot to target/screenshots\1594642397495_Blue_Bikini_List.png Entered Test 3: Black Bikini Like Passed Entered Test 3: Refresh no Like Passed Entered Test 1: Open Zaful Written screenshot to target/screenshots\1594642403344_Logo_Exsists.png Entered Test 2: Blue Bikini Written screenshot to target/screenshots\1594642404359_Blue_Bikini_List.png Entered Test 3: Black Bikini Like Passed Entered Test 3: Refresh no Like Passed Entered Test 1: Open Zaful Written screenshot to target/screenshots\1594642409144_Logo_Exsists.png Entered Test 2: Blue Bikini Written screenshot to target/screenshots\1594642410471_Blue_Bikini_List.png TestJASON.json2020_07_13 [ERROR] Tests run: 14, Failures: 9, Errors: 0, Skipped: 0, Time elapsed: 36.35 s <<< FAILURE. - in TestSuite [ERROR] Logo_Exsists(testcases:OpenZafulTest) Time elapsed. 8.149 s <<< FAILURE. java:lang.NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates at testcases.OpenZafulTest:Logo_Exsists(OpenZafulTest:java.53) Caused by. java:lang.ClassNotFoundException. org.openqa.selenium.interactions.Coordinates at testcases.OpenZafulTest:Logo_Exsists(OpenZafulTest.java:53) [ERROR] Logo_Exsists(testcases.BlueBikiniListTest) Time elapsed. 3.539 s <<< FAILURE: java:lang.NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates Caused by: java.lang.ClassNotFoundException. org.openqa.selenium:interactions.Coordinates [ERROR] Blue_Bikini_List(testcases.BlueBikiniListTest) Time elapsed. 0:691 s <<< FAILURE. java.lang.NoClassDefFoundError: org/openqa/selenium/interactions/Coordinates at testcases:BlueBikiniListTest.Blue_Bikini_List(BlueBikiniListTest.java:39) Caused by. java.lang.ClassNotFoundException. org.openqa.selenium.interactions:Coordinates at testcases.BlueBikiniListTest:Blue_Bikini_List(BlueBikiniListTest.java.39) [ERROR] Logo_Exsists(testcases.LikeBlackBikiniTest) Time elapsed: 3:05 s <<< FAILURE. java.lang:NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates Caused by. java.lang.ClassNotFoundException. org:openqa.selenium.interactions.Coordinates [ERROR] Blue_Bikini_List(testcases:LikeBlackBikiniTest) Time elapsed: 1.169 s <<< FAILURE. java:lang.NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates Caused by. java.lang.ClassNotFoundException: org.openqa.selenium.interactions:Coordinates [ERROR] Logo_Exsists(testcases:NoLikesAfterRefreshTest) Time elapsed. 2.994 s <<< FAILURE: java.lang.NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates Caused by. java.lang:ClassNotFoundException. org.openqa.selenium:interactions:Coordinates [ERROR] Blue_Bikini_List(testcases.NoLikesAfterRefreshTest) Time elapsed. 0:741 s <<< FAILURE. java.lang.NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates Caused by. java:lang.ClassNotFoundException. org.openqa:selenium:interactions.Coordinates [ERROR] Logo_Exsists(testcases.JsonWriterTest) Time elapsed: 3.376 s <<< FAILURE. java.lang.NoClassDefFoundError. org/openqa/selenium/interactions/Coordinates Caused by: java.lang.ClassNotFoundException. org:openqa:selenium.interactions.Coordinates [ERROR] Blue_Bikini_List(testcases:JsonWriterTest) Time elapsed. 1.097 s <<< FAILURE. java.lang:NoClassDefFoundError: org/openqa/selenium/interactions/Coordinates Caused by. java:lang.ClassNotFoundException. org.openqa.selenium:interactions.Coordinates [INFO] [INFO] Results. [INFO] [ERROR] Failures. [ERROR] BlueBikiniListTest.Blue_Bikini_List:39 » NoClassDefFound org/openqa/selenium/i... [ERROR] BlueBikiniListTest>OpenZafulTest.Logo_Exsists:53 » NoClassDefFound org/openqa/... [ERROR] JsonWriterTest>BlueBikiniListTest.Blue_Bikini_List:39 » NoClassDefFound org/op... [ERROR] JsonWriterTest>OpenZafulTest.Logo_Exsists:53 » NoClassDefFound org/openqa/sele... [ERROR] LikeBlackBikiniTest>BlueBikiniListTest.Blue_Bikini_List:39 » NoClassDefFound o.:. [ERROR] LikeBlackBikiniTest>OpenZafulTest.Logo_Exsists.53 » NoClassDefFound org/openqa.:. [ERROR] NoLikesAfterRefreshTest>BlueBikiniListTest.Blue_Bikini_List.39 » NoClassDefFound [ERROR] NoLikesAfterRefreshTest>OpenZafulTest:Logo_Exsists,53 » NoClassDefFound org/op:,: [ERROR] OpenZafulTest,Logo_Exsists:53 » NoClassDefFound org/openqa/selenium/interactio:.: [INFO] [ERROR] Tests run: 14: Failures: 9: Errors. 0. Skipped. 0 [INFO] [INFO] ------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO] ------------------------------------------------------------------------ [INFO] Total time: 43:867 s [INFO] Finished at. 2020-07-13T15.13:32+03:00 [INFO] Final Memory. 25M/268M [INFO] ------------------------------------------------------------------------ [ERROR] Failed to execute goal org:apache.maven.plugins,maven-surefire-plugin.3.0.0-M3,test (default-test) on project ZafulSelMaven4. There are test failures. [ERROR] [ERROR] Please refer to C,\Users\hagit\workspace\ZafulSelMaven4\target\surefire-reports for the individual test results: [ERROR] Please refer to dump files (if any exist) [date]:dump. [date]-jvmRun[N].dump and [date].dumpstream. [ERROR] -> [Help 1] [ERROR] [ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch. [ERROR] Re-run Maven using the -X switch to enable full debug logging. [ERROR] [ERROR] For more information about the errors and possible solutions, please read the following articles: [ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException

and this is testng.xml:

 <?xml version="1.0" encoding="UTF-8"?> <:DOCTYPE suite SYSTEM "http.//testng.org/testng-1.0.dtd"> <suite name="Test_Suite" parallel="none" thread-count="1"> <test name="Test"> <classes> <class name="testcases.OpenZafulTest"/> <class name="testcases.BlueBikiniListTest"/> <class name="testcases.LikeBlackBikiniTest"/> <class name="testcases.NoLikesAfterRefreshTest"/> <class name="testcases.JsonWriterTest"/> </classes> </test> <!-- Test --> </suite> <!-- Suite -->

I want to run my tests by their order (class by class), so if anyone knows how to do that it would help me a lot.

This is how the TestNG behaves. The tests would not execute in order as listed in the testng.xml. You should assign priority to the tests to run them in the required sequence. If the tests are dependent on each other then used depends on. check out the documentation here.

https://testng.org/doc/documentation-main.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM