Issue
I need to create a .bat file to execute my selenium project that i created with TestNG. I created the .xml file:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Testing 07ZR" parallel="methods" thread-count="2">
<test name="Automation">
<classes>
<class name="AjouterPanier.AjoutPanier"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
The problem is i have two @Test and for some reason he executes them as if in the same time since when he tries to login he puts the login values twice. for reference this is my .bat file:
set projectLocation="Project Path"
cd %projectLocation%
set classpath=%projectLocation%\bin;%projectLocation%\lib\*
java org.testng.TestNG %projectLocation%\testng.xml
pause
Can some one tell me what do i need to do so the two @Test execute one after the other ?
Solution
parallel="methods" thread-count="2"
You are requesting TestNG
to run each Method
in threads , in parallel
, using a pool of 2 threads. Therefore that could explain the ABCABC
Few things to consider:
The parallel
attribute on the <suite>
tag can take one of following values:
<suite name="My suite" parallel="methods" thread-count="5">
<suite name="My suite" parallel="tests" thread-count="5">
<suite name="My suite" parallel="classes" thread-count="5">
<suite name="My suite" parallel="instances" thread-count="5">
parallel="methods": TestNG will run all your test methods in separate threads. Dependent methods will also run in separate threads but they will respect the order that you specified.
parallel="tests": TestNG will run all the methods in the same <test> tag in the same thread, but each <test> tag will be in a separate thread. This allows you to group all your classes that are not thread safe in the same <test> and guarantee they will all run in the same thread while taking advantage of TestNG using as many threads as possible to run your tests.
parallel="classes": TestNG will run all the methods in the same class in the same thread, but each class will be run in a separate thread.
parallel="instances": TestNG will run all the methods in the same instance in the same thread, but two methods on two different instances will be running in different threads.
In your case, because your methods don't seem to be thread-safe, I recommend you use thread-count="1", or simply look at the options above to see what works best for you if you really wanted to run in parallel
mode.
<suite name="Testing 07ZR" parallel="methods" thread-count="1">
or not in parallel mode:
<suite name="Testing 07ZR">
If you wanted your methods inside the same TestClass to run in specific order, you could also use priority
:
priority The priority for this test method. Lower priorities will be scheduled first.
Example:
@Test(priority=1)
public void Test1() {
}
@Test(priority=2)
public void Test2() {
}
@Test(priority=3)
public void Test3() {
}
Then they would run, as Test1, Test2, Test3 in this order respectively.
https://testng.org/doc/documentation-main.html#test-groups
Answered By - SMA
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.