It is very important to test your web application across multiple browser. Each browser as different way of processing the code and hence user experience might differ from browser to browser as a tester it is our responsibility to make sure our application works fine on most commonly used browsers such as firefox, chrome and IE.
TestNG allows us to automate the multi-browser testing using TestNG parameters. In this post we will see in detail how we can achieve this withe simple example.
Example.
1. Create a simple test script.
2. Configure it to pass Browser Type as a parameter.
package test; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; import org.openqa.selenium.ie.InternetExplorerDriver; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Parameters; import org.testng.annotations.Test; public class MultiBrowserTest { public WebDriver driver; @Parameters("browser") @BeforeClass // Passing Browser parameter from TestNG xml public void beforeTest(String browser) { // If the browser is Chrome, then do this if(browser.equalsIgnoreCase("chrome")) { System.setProperty("webdriver.ie.driver", "C:\\Softwares\\chromedriver_win32\\chromedriver.exe"); driver = new InternetExplorerDriver();; // If browser is IE, then do this }else if (browser.equalsIgnoreCase("ie")) { // Here I am setting up the path for my IEDriver System.setProperty("webdriver.ie.driver", "D:\\QA\\drivers\\IEDriverServer.exe"); driver = new InternetExplorerDriver(); } // Doesn't the browser type, lauch the Website driver.get("http://www.qaautomated.com"); } // Once Before method is completed, Test method will start @Test public void search() throws Exception { Thread.sleep(5000); driver.findElement(By.xpath("*//input[@class='search-field']")).sendKeys("appium"); driver.findElement(By.xpath("*//input[@class='search-submit']")).click(); driver.quit(); } @AfterClass public void afterTest() { driver.quit(); } }
3. Mention browser type details in testng.xml
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite"> <test name="ChromeTest"> <parameter name="browser" value="chrome" /> <classes> <class name="test.MultiBrowserTest" /> </classes> </test> <test name="IETest"> <parameter name="browser" value="ie" /> <classes> <class name="test.MultiBrowserTest" /> </classes> </test> <!-- Test --> </suite> <!-- Suite -->
4. Run it as TestNG Suit.
Parallel Execution - Consider you want to execute your tests in parallel on multiple browser then with a small change to your testng.xml you achieve this
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> <suite name="Suite" parallel="tests"> <test name="ChromeTest"> <parameter name="browser" value="chrome" /> <classes> <class name="test.MultiBrowserTest" /> </classes> </test> <test name="IETest"> <parameter name="browser" value="ie" /> <classes> <class name="test.MultiBrowserTest" /> </classes> </test> <!-- Test --> </suite> <!-- Suite -->
.
Click Here Best RPA Online Training to go to RPA Online Training Institute Details .
ReplyDeletemyTectra Placement Portal is a Web based portal brings Potentials Employers and myTectra Candidates on a common platform for placement assistance
ReplyDeleteNice post..
ReplyDeleteDOT NET training in btm
dot net training institute in btm
dot net course in btm
best dot net training institute in btm
Awesome blog
ReplyDeletesalesforce training in Marathahalli
salesforce admin training in Marathahalli
salesforce developer training in Marathahalli
Nice Article Thanks for sharing this post
ReplyDeleteselenium training centers in Bangalore
best software testing training institutes in Bangalore with placements
automation testing courses in Bangalore
selenium testing course in Bangalore
software testing institutes in Bangalore
selenium training in Bangalore
best selenium training in Bangalore
selenium course in Bangalore
Your Blog is awsem. I also find a blog Gk Questions and Answers which is also awsem
ReplyDeletenice post
ReplyDeleteaws training center in chennai
aws training in chennai
aws training institute in chennai
best angularjs training in chennai
angular js training in sholinganallur
angularjs training in chennai
azure training in chennai
Attend The Analytics Course in Bangalore From ExcelR. Practical Analytics Course in Bangalore Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The Analytics Course in Bangalore.
ReplyDeleteExcelR Analytics Course in Bangalore
Such a very useful article. Very interesting to read this article.I would like to thank you for the efforts you had made for writing this awesome article.
ReplyDeleteExcelR Business Analytics Course
Attend The PMP Certification in Abu Dhabi From ExcelR. Practical PMP Certification in Abu Dhabi Sessions With Assured Placement Support From Experienced Faculty. ExcelR Offers The PMP Certification in Abu Dhabi.
ReplyDeleteExcelR PMP Certification in Abu Dhabi
Nice Content! Useful Informtion...
ReplyDeleteBest Real Estate company in Hyderabad
Best Real Estate agency in Hyderabad
Nice Content! Useful Informtion...
ReplyDeleteBest Real Estate company in Hyderabad
Best Real Estate agency in Hyderabad
I am sure that this is going to help a lot of individuals. Keep up the good work. It is highly convincing and I enjoyed going through the entire blog.
ReplyDeleteData Science Training
I am always searching online for articles that can help me. There is obviously a lot to know about this. I think you made some good points in Features also. Keep working, great job ExcelR Business Analytics Courses
ReplyDelete