We all know testNG is very rich in features and one of best thing is , it allow you to do your test parallel. The parallel testing features to run your test in diff browser in same time without wasting the time. we can run same test same time in diff browsers. Let's see how we can achieve this:
We will create a testNG class e.g. "parallelTesting.java" and the xml file name say it is again "paralleltesting.xml"
Here the xml:
in this xml we have two test : 1- Test in Firefox and other is 2- Test in Chrome
and in both test we use same class "parallelTesting" .
what is noticable here is tag parameter which has name as browser and value is Firefox and Chrome for test1 and test2 respectively.
Lets take a look in to jave file.
package practiceTestNG;here we have one class with @Test annotation and another class with
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class parallelTesting
{
WebDriver driver= null;
@BeforeTest
@Parameters({"browser"})
public void sendbrowser(String browser)
{
if(browser.equals("Firefox"))
{
driver = new FirefoxDriver();
}
else if(browser.equals("Chrome"))
{
System.setProperty("webdriver.chrome.driver","C:\\chromedriver.exe");
driver = new ChromeDriver();
}
}
@Test
public void blogTitle()
{
driver.get("http://www.vishalsachan.blogspot.in");
String title = driver.getTitle();
Assert.assertEquals("Simplifying the test", title);
driver.quit();
}
}
@Beforetest which will take parameter as browser which will have values as Firefox and Chrome (in our scenarios).
Now run ur testsuit and u will observe that your test is run in both browser parallel. We can code change the code if we want to include more browsers. so its all. enjoy cross browser testing without much pain.
Stay tuned for more fruitful post.
No comments :
Post a Comment