in testng.xml run as testng suit triggers IE browser & run each test manually it runs with chrome. Why so? - selenium

when i run with testng.xml then IE browser opens with the message "This is the initial start page for the WebDriver server."
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "testng.org/testng-1.0.dtd"> <suite name="abc"> <groups> <run> <!-- include name = "HC"></include> --> <!--include name = "Reg"></include> --> <include name = "test"></include> </run> </groups> <test name="regression"> <classes> <class name="A"></class> <class name="B"></class> <class name="C"></class> </classes> </test> </suite> <!-- Suite -->

Related

Is there a possible way to run two parameterized testng.xml files?

Is there any way to run these two xml files parallel?
test1.xml
<?xml version="1.0" encoding="UFT-8">
<suite name="Runner">
<listeners>
<listener class-name = "package1.Tester"/>
</listener>
<parameter name = "Excel name" value = "Excel1"/>
<test name = "Excel" parallel = "tests" thread-count="1" verbose = "2">
<classes>
<class name = "package2.Run"/>
</classes>
</test>
</suite>
test2.xml
same as test1.xml only the parameter value differs from Excel1 to Excel2
1 You have an issue in testNG XML:
Instead of <?xml version="1.0" encoding="UFT-8"> (note UFT is typo, also ? missed) should be <?xml version="1.0" encoding="UTF-8"?>.
2 Once you fix this, just create 2 files test1.xml, test2.xml as you want and create a new runSuites.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Run-all-testNG-files">
<suite-files>
<suite-file path="test1.xml"/>
<suite-file path="test2.xml"/>
</suite-files>
</suite>

When a #BeforeTest method fails, why is it not being listed in the testng-failed.xml?

I am using maven with testng 6.14.3.
Here is my code structure:
testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="set-3" parallel="tests" thread-count="10">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter" />
</listeners>
<test name="Customer Tests">
<groups>
<run>
<include name="abc"/>
</run>
</groups>
<classes>
<class name="apps.Test1_BeforeTest_Of_Test2"></class>
<class name="apps.Test2"></class>
</classes>
</test>
</suite>
Test1_BeforeTest_Of_Test2.java
public class Test1_BeforeTest_Of_Test2{
#BeforeTest(groups = {"abc"})
public void test1Method() throws Exception {
}
#AfterTest(groups={"abc"})
public void test1AfterMethod() throws Exception {
}
}
Test2.java
public class Test2{
#Test(groups = {"abc"})
public void test2Method(){
}
}
During my run, Test1_BeforeTest_Of_Test2 class fails. So, Test2 is marked as skipped.
But, when I look at the testng-failed.xml that is generated at the end of the run, the failed #BeforeTest class (Test1_BeforeTest_Of_Test2) is not included/listed:
testng-failed.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite thread-count="10" name="Failed suite [set-3]" parallel="tests">
<listeners>
<listener class-name="org.uncommons.reportng.HTMLReporter"/>
</listeners>
<test name="Customer Tests(failed)">
<groups>
<run>
<include name="abc"/>
</run>
</groups>
<classes>
<class name="apps.Test2">
<methods>
<include name="test2Method"/>
</methods>
</class>
</classes>
</test>
</suite>
Is this expected behaviour? Or a bug/gap in testng-failed.xml?
Ideally, when we re-run the failed tests, we expect the #BeforeTest to run as well, because it is pre-req for Test 2.
TestNG currently seems to be honouring configurations to be considered in the testng-failed.xml if its part of the skipped test method's test class i.e., the configuration (which is perhaps what has caused a test to be skipped) needs to reside in the same java class as your skipped method for TestNG to consider it to be included.
In your example, that's not the case and the configuration method exists in a different test class (which is perfectly valid).
This looks like a bug in TestNG to me.
I have submitted a bug on your behalf on the TestNG project and will get it fixed in the upcoming version (7.5.0).
Defect : https://github.com/cbeust/testng/issues/2611

How to run test cases in different Java classes in a new window every time using TestNG and Selenium

I have 15 test methods in 3 Java classes (Selenium Script). I want to run each Test class with new window. I am using TestNg framework.
Here is the code of TestNG:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Fanfight Test" thread-count="10" parallel="methods">
<listeners>
<listener class-name="com.fanfight.test_case.ListenerClass">
</listener>
</listeners>
<test name="User Login" parallel="false">
<classes>
<class name="com.fanfight.test_case.UserLogin"></class>
</classes>
</test>
<test name="Contest Creation" parallel="false" >
<classes>
<class name="com.fanfight.test_case.ContestCreation"></class>
</classes>
</test>
<test name="User Profile Test" parallel="false" >
<classes>
<class name="com.fanfight.test_case.UserProfileTest"></class>
</classes>
</test>
<test name="Menu Bar Test" parallel="false">
<classes>
<class name="com.fanfight.test_case.MenuBarTest">
</class>
</classes>
</test>
<test name="Home Page Elements" parallel="false" >
<classes>
<class name="com.fanfight.test_case.HomePageElementTest"></class>
</classes>
</test>
</suite>
Without using parallel="false" my script is running in alphabetical order due to which selenium unable to find the path and execution got stuck.
Also please suggest how to make execution continue even after getting an exception during execution.
Add a setup and tear down method in each of the 3 test classes. The setup method should launch the browser and teardown method should close that browser instance.
class TestOne {
WebDriver driver;
#BeforeClass
public void setup(){
driver = new ChromeDriver();
}
#Test
public void testCase1(){
}
//.... Other test methods
#AfterClass
public void tearDown(){
driver.quit();
}
You can also create a parent class having just the setup and tear down methods , pseudo coded above. All 3 of your test class shall extend this parent class. It will be an optimised approach as the driver instantiation and destruction is now centralised to a single class.
And finally , change the parallel attribute in the suite tag of your testNG xml, in order to make them run parallel.
<suite name="Fanfight Test" thread-count="10" parallel="classes">

Test method not run with sequence in testng

I am using TestNG + WebDriver for my automation project but order of test execution is not working as expected have specified the order for each method below is the method signature and notation
#Test(dependsOnMethods="verifyElementsOnProfileScreen",alwaysRun = true)
public void verifyMySelfProfileVisibility(){
TestSuit the I have using :
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="regressionSuite" parallel="none">
<parameter name="ApplicationOpt" value="web"></parameter>
<parameter name="Browser" value="firefox"></parameter>
<test name="Test">
<classes>
<!-- Login Module -->
<class name="Tests.Login.LoginApp"/>
<method>
<include name ="loginUser"></include>
</method>
<!-- Portal Module -->
<class name="Tests.Profile.ProfileModule">
<method>
<include name="verifyElementsOnProfileScreen"></include>
<include name="verifyMySelfProfileVisibility"></include>
</method>
</class>
<class name="Tests.Profile.participantAuditLog">
<method>
<include name="verifyAuditLogForCreateProfileEvent"></include>
<include name="verifyAuditLogForUpdateContactInfoEvnet"></include>
<include name="verifyAuditLogForUpdatePrivacyDirective"></include>
</method>
</class>
</classes>
</test> <!-- Test -->
</suite> <!-- regressionSuite -->
Do you mean Classes which specified in testng.xml file not executing in specified order.. then please use preserve-order= "true"
<suite name="MySuite" preserve-order= "true">
<test name="MyTest">
If you want to specify order of methods execution in Class then use priority
#Test( priority = 1 )
group-by-instances="true" also useful if you face situation like execution order of priority methods of different classes are not as expected..
<suite thread-count="2" verbose="10" name="testSuite" parallel="tests">
<test verbose="2" name="MytestCase" group-by-instances="true">
Thank You,
Murali

Maven issue:Regarding Testng

I have a module A which runs through pom.xml and accesses a testng.xml which in turn calls a specific class.This class displays a list of things for the user to choose from.
I am taking the user value through bufferRead.The bufferRead does not detect the value entered by the User.
ie
Enter the test u want to run
1.Test1
2.Test2
3.Test3
1
(control never goes to the next line)
There goes my pom.xml
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>`
This is my testng.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?><suite allow-return-values="false" configfailurepolicy="skip" data-provider-thread-count="10" group-by-instances="false" junit="false" name="Suite" parallel="false" preserve-order="true" skipfailedinvocationcounts="false" thread-count="5">
<test allow-return-values="false" group-by-instances="false" junit="false" name="Test" preserve-order="true" skipfailedinvocationcounts="false">
<classes>
<class name="com.org.Console1"<methods>
<include name="main" />
</methods>
</class>
</classes>
</test> <!-- Test -->
This is my java code that runs
System.out.println("Which tests do you want to run");
String input = bufferRead.readLine();