I need to automate the two Web applications in parallel and that needs to validate in Chrome browsers.
So I have two testng XML files(testng1.xml and testng2.xml), my scenario is to launch one chrome browser per xml file, so two chrome browsers in parallel.
Also I have common class for launching Chrome browser where I have initialized the webdriver.
Launch Browser code:
public class LaunchBrowser
{
public static WebDriver driver = null;
public LaunchBrowser()
{
}
public LaunchBrowser(WebDriver drive)
{
driver=drive;
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
@Test
public void initDriver()
{
if (driver == null)
{
System.setProperty("webdriver.chrome.driver", "C:\\selenium\\drivers\\chromedriver.exe");
driver = new ChromeDriver();
driver.manage().window().maximize();
}
}
}
testng1.xml
<suite name="Suite1">
<test name="Browser">
<classes>
<class name="com.ci.selenium.LaunchBrowser" />
</classes>
</test>
<test name="Google">
<classes>
<class name="com.ci.selenium.Google" />
</classes>
</test>
<test name="Gmail">
<classes>
<class name="com.ci.selenium.GmailLogin" />
</classes>
</test>
</suite>
testng2.xml
<suite name="Suite2">
<test name="01StackOverflow">
<classes>
<class name="com.ci.selenium.Stackoverflow" />
</classes>
</test>
<test name="02StackLogin">
<classes>
<class name="com.ci.selenium.StackLogin" />
</classes>
</test>
</suite>
Google Class in xml1
public class Google
{
WebDriver d;
LaunchBrowser l = new LaunchBrowser();
@BeforeClass
public void launch()
{
LaunchBrowser ll = new LaunchBrowser(d);
}
@Test
public void f() throws InterruptedException
{
l.getURL("https://www.google.co.in");
Thread.sleep(3000);
System.out.println("google");
}
}
GmailLogin Class in xml1
public class Gmail
{
@Test
public void test() throws InterruptedException
{
driver.findElement(By.xpath("//a[@href='https://mail.google.com/mail/?tab=wm'][text()='Gmail']")).click();
Thread.sleep(3000);
}
}
StackOverflow class in xml2
public class Stackoverflow
{
WebDriver d1;
LaunchBrowser l = new LaunchBrowser(d1);
@Test
public void f() throws InterruptedException
{
System.out.println(l==null ? "null" : "not null");
l.getURL("https://stackoverflow.com");
Thread.sleep(3000);
System.out.println("Stack");
}
StackOverflow Login
public class StackLogin
{
LaunchBrowser l = new LaunchBrowser();
@Test
public void f() throws InterruptedException
{
l.xpathClick("//a[@href='https://stackoverflow.com/users/login?
ssrc=head&returnurl=https%3a%2f%2fstackoverflow.com%2f']")).click();
Thread.sleep(3000);
}
}
The above code is not running in parallel exceution. So kindly help to resolve this scenario.