TestNG file is not reading parameter value if add another script - selenium

i am trying to run multiple test in sequence in in one by one different browser , for that i am defining browser parameter in testNg.xml file .
<test name="iexplore">
<parameter name="browser" value="iexplore"/>
<classes>
<class name="com.slingmedia.safe.testscripts.BRO_139"/>
<class name="com.slingmedia.safe.testscripts.BRO_140"/>
</classes>
</test>
its working fine and taking correct browser , but when i am defining all the test in other xml file and trying to run , browser value is not getting read.
<test name="iexplore">
<parameter name="browser" value="iexplore"/>
<suites-file>
<suite path="Sample3.xml" />
</suites-files>
</test>

Related

How to get logs for each test tag in a file in parallel run in Selenium which is running based on test parameter

I have a testng.xml which will create a Claim for 2 companies parallel, the parameter here is company name. A gist of test tags in testng.xml are as below:
<suite name="Suite" thread-count="2" parallel="tests">
<test name="Test1">
<parameter name="TestParam" value="CompanyName1" />
<classes>
<class name="CreateClaim" />
</classes>
</test>
<test name="Test2">
<parameter name="TestParam" value="CompanyName2" />
<classes>
<class name="CreateClaim" />
</classes>
</test>
When I run this testng.xml, logs are generated haphazardly, mixing the logs of two test tags.
Is there any way in which I can save the logs of first test tag in one file and second test tag in other file?
It will be easy for us to check logs of each company specifically.

My framework is not connecting to Browserstack

I signed up an account in browserstack. Edited My xml file and enabled it to true. It keeps saying that it does not recognize my browser version or the OS.Here is my code in XML file.
<parameter name="useCloudEnv" value="true"/>
<parameter name="cloudEnvName" value="browserstack"/>
<!--<parameter name="cloudEnvName" value="saucelabs"/>-->
<parameter name="os" value="Windows"/>
<parameter name="os_version" value="10"/>
<parameter name="browserName" value="chrome"/>
<parameter name="browserVersion" value="60.0"/>
<parameter name="url" value="https://www.uhc.com//"/>
<test name = "Test">
<classes>
<class name="testhomepage.TestHomePage"/>
</classes>
</test>
Please find below link, I ran a sample test on BrowserStack Automate with the same capabilities you are providing in the XML file:
https://automate.browserstack.com/builds/5854b3a5d9e5e91d1562b5daeb33460e64e11599/sessions/e0102645e1af034a26cd7c7abb52257b4c506185?auth_token=6607bebe9a9de8fbd062fe46324a4c64aecabc5242d835b48bd8876a0727ee22
Please refer BrowserStack sample code here:
https://www.browserstack.com/docs?product=automate
To find the BrowserStack capabilities click here:
https://www.browserstack.com/automate/capabilities
You have mentioned the correct BrowserStack capabilities in the XML file but make sure your tests scripts are receiving the same capabilities.
Could you please review your framework once?

TestNG not ordering classes as specified in the testng.xml file

My testng.xml file looks like:
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="testng.Test1"/>
<methods>
<include name="Browse()"></include>
<include name="Login()"></include>
<include name="Reg()"></include>
</methods>
<class name="testng.Test2"></class>
</classes>
</test> <!-- Test -->
The output of Test1 is:
*Login
Register
Browse*
The output of Test2 is
2
But, when i run the testng.xml file, the output looks like:
*Login Register 2 Browse*.
So, before the Test1 is completed, it is picking the Test2 and printing the output.
How can we run it, so that Test1 is executed first completely, followed by Test2?
I tried using preserve-order="true" but it didn't work.
Not sure what exactly you are asking for here but according to your xml file, you should include your methods in your class before closing it.
<suite name="Suite" parallel="none">
<test name="Test">
<classes>
<class name="testng.Test1">
<methods>
<include name="Browse()"></include>
<include name="Login()"></include>
<include name="Reg()"></include>
</methods>
</class>
<class name="testng.Test2"/>
</classes>
</test> <!-- Test -->
This way all the methods in your "Test1" will run first and then rest of the tests will run.
Learn more here.

Parallel execution of two suites using web driver and Selenium

I have two testNG suites in my project. I want to run both of them in parallel.
Suite1:
class A
class B
Suite2:
class C
class D
I want to run SUITE1 and SUITE2 in parallel on the same machine. However, Class B of SUITE1 should be run only after Class A. Same with the second suite: the first and second classes need to be run in serial.
How do I achieve this?
In order to achieve, you need to add annotation as #Test(priority=??). The default value will be zero for priority.
If you don't mention the priority, it will take all the test cases as "priority=0" and execute.
If we define priority as "priority=", these test cases will get executed only when all the test cases which don't have any priority as the default priority will be set to "priority=0"
You dont need two xml for your requirement. Follow these and you should have same test running parallel.
<suite name="Test-class Suite" parallel="tests" thread-count="2">
<test name="Test-class test 1">
<classes>
<class name="com.ClassA" />
<class name="com.ClassB" />
</classes>
</test>
<test name="Test-class test 2">
<classes>
<class name="com.ClassC" />
<class name="com.ClassD" />
</classes>
</test>
Make sure your parallel parameter have parallel='true' and thread-count as per your requirement.
to execute classes as specified order, need to use preserve-order="true". As per below xml file, ClassB is specified first so ClassB is executed first then ClassA as we specified preserve-order="true"
If you want to execute #Test methods in class as per required order, please use priority. like below
#Test(priority=1)
below is xml file for example..
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="tests" preserve-order="true">
<test name="TestA">
<classes>
<class name="com.test.ClassB"/>
<class name="com.test.ClassA"/>
</classes> </test> <!-- Test A-->
<test name="TestB">
<classes>
<class name="com.test.ClassD"/>
<class name="com.test.ClassC"/>
</classes> </test> <!-- Test B-->
</suite> <!-- Suite -->
*****updating as per comment
Hi,
To execute two suites, need to create two xml files and specify your suites in those xml files. Then create another xml file to call these suites xml files..
Lets say i have one suite in testng1.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite1" parallel="false" preserve-order="true">
<test name="TestA">
<classes>
<class name="com.test.NewTest1"/>
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
another suite in testng2.xml file
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite2" parallel="false" preserve-order="true">
<test name="TestB">
<classes>
<class name="com.test.NewTest1"/>
</classes>
</test> <!-- Test -->
then use another testng.xml file and call these two file. by executing this file, two suite will be executed.
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="My test suite" preserve-order="true">
<suite-files>
<suite-file path="Testng1.xml"></suite-file>
<suite-file path="Testng2.xml"></suite-file>
</suite-files>
</suite>

Using TestNG to file Selenium test - But NOT Parallel

This is my first question here, and I will be very happy to be helped.
I have been using TestNG as a part of my framework for a long time now.
And the question I have today is about the testng.xml configuration - to NOT run tests in parallel. And NO, none of my tests are dependent, they are all independent. But, this is for my requirement.
My testng.xml file looks like this:
<suite name="Smoke Test Suite" verbose="3" parallel="tests" thread-count="2">
<test name="Run on Firefox" preserve-order="true">
<parameter name="browser" value="firefox"/>
<classes>
<class name="com.test1"/>
<class name="com.test2"/>
<class name="com.test3"/>
<class name="com.test4"/>
</classes>
</test>
<test name="Run on IE9" preserve-order="true">
<parameter name="browser" value="iexplore"/>
<classes>
<class name="com.test1"/>
<class name="com.test2"/>
<class name="com.test3"/>
<class name="com.test4"/>
</classes>
</test>
<test name="Run on Google Chrome" preserve-order="true">
<parameter name="browser" value="chrome"/>
<classes>
<class name="com.test1"/>
<class name="com.test2"/>
<class name="com.test3"/>
<class name="com.test4"/>
</classes>
</test>
I want the Tests to run in Parallel, but the classes to run one after the other.
What I am currently seeing is that when the test is fired off, I have 8 instance of FF, IE9 and Chrome open up. How can I configure it so that "test1" is executed, the browser is closed, new instance opened and then "test2" is run and so forth?
The reason for me having to do this is that, my app has multiple windows opened during each test. And IE9 (being the evil browser it is) does not know how to handle the situation, panics and loses focus on the window midway through the test. It has been suggested, and I have found the same - that it is best to have one instance of IE9 running with nothing else interrupting it.
Suggestions and solutions will be gratefully accepted.
NOTE: All classes are in the same package.
Thanks,
-Alister
You can create Three objects for DefaultSelenium in your #Before method.One for IE, One for FF and One for chrome.
If you are using webdriver you can create 3 separate drivers for the same.
You could use three separate suites (xml files) then add them one after the other in the command line. That has the effect of running them in sequence.