package com.web;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
public class ParallelRunning {
private WebDriver driver=null;
@BeforeTest
@Parameters ({"BROWSER"})
public void setup(String BROWSER){
System.out.println("Browser: " + BROWSER);
if (BROWSER.equals("FF")) {
System.out.println("FF is selected");
driver = new FirefoxDriver();
} else if (BROWSER.equals("IE")) {
System.out.println("IE is selected");
driver = new InternetExplorerDriver();
} else if (BROWSER.equals("HU")) {
System.out.println("HU is selected");
driver = new HtmlUnitDriver();
} else if (BROWSER.equals("CH")){
System.out.println("Google chrome is selected");
driver = new ChromeDriver();
}
}
@Test
public void testParallel()throws Exception{
driver.get("http://www.google.com");
Thread.sleep(5000);
WebElement search = driver.findElement(By.name("q"));
search.sendKeys("automation blog by niraj");
search.submit();
Thread.sleep(5000);
Assert.assertTrue(driver.getPageSource().contains("automationtricks.blogspot.com"));
driver.findElement(By.xpath("//a[contains(@href,'automationtricks.blogspot.com')]")).click();
Thread.sleep(15000);
Assert.assertTrue(driver.getPageSource().contains("working as Associate Manager @CSC"));
driver.quit();
}
}
In the above sample program BROWSER is a variable which value would be passed from TestNG.xml and TestNG.xml will run the test multiple time each time BROWSER value would be set with different browser name and test will check the BROWSER value and decide which browser test will run.TestNG.xml
<?xml version="1.0" encoding="UTF-8"?>
<suite name="webDriver" parallel="tests">
<test name="WebDriverDemo Witn FF" preserve-order="true">
<parameter name="BROWSER" value="FF" />
<classes>
<class name="com.web.ParallelRunning" />
</classes>
</test>
<test name="WebDriverDemo with IE" preserve-order="ture">
<parameter name="BROWSER" value="IE"></parameter>
<classes>
<class name="com.web.ParallelRunning"></class>
</classes>
</test>
<test name="WebDriverDemo with HTML unit" preserve-order="true">
<parameter name="BROWSER" value="HU"></parameter>
<classes>
<class name="com.web.ParallelRunning"></class>
</classes>
</test>
<test name="WebDriverDemo with HTML unit" preserve-order="true">
<parameter name="BROWSER" value="CH"></parameter>
<classes>
<class name="com.web.ParallelRunning"></class>
</classes>
</test>
</suite>
Title is misleading... you are not running tests simultaneously. You should write on handling multiple drivers.
ReplyDeletesaadas
ReplyDeleteyes, how to handle multiple drivers for same browser and need to start test in parallel...
ReplyDelete[TestNG] Running:
ReplyDeleteC:\Documents and Settings\lokesh_chandra\Local Settings\Temp\testng-eclipse--1980791299\testng-customsuite.xml
FAILED CONFIGURATION: @BeforeTest setup
org.testng.TestNGException:
Parameter 'BROWSER' is required by @Configuration on method setup but has not been marked @Optional or defined
in C:\Documents and Settings\lokesh_chandra\Local Settings\Temp\testng-eclipse--1980791299\testng-customsuite.xml
I am getting this error again and again.
Please solve this issue ASAP. Also, please let me know where exactly the testng.xml files is to be placed.
Thanks
Lokesh
test is not running one by one not parrallel
ReplyDeleteIt was so nice article.I was really satisified by seeing this article and we are
ReplyDeletealso giving QA online training.The QA online Training is one of the best QA online training institute in worldwide.
http://online-training-qa.com/
Deletethis article is useful for beginners to learn Automation Testing
ReplyDeleteAdvanced Selenium Framework Training in Chennai by Vishwa
ReplyDeleteHi, Reach Mr.Vishwa for Best Selenium and Coded UI Training in Chennai with real time project assistance. This people will teach everything from the basics up to advanced level scenarios from frameworks.
I learned from Mr.Vishwa and Raj they are very good automation people for Selenium Frameworks. After joined with them I learned many things and now I am writing automation scripts in own project. Vishwa 9003085882
selenium training in chennai
Good Post! Thank you so much for sharing this pretty post, it was so good to read and useful to improve my knowledge as updated one, keep blogging.
ReplyDeletePython Training in electronic city
DataScience with Python Training in electronic city
AWS Training in electronic city
Big Data Hadoop Training in electronic city
Devops Training in electronic city
Thanks for this post.
ReplyDeleteSelenium Training in Chennai | Selenium Training Institute in Chennai | Selenium Training Center in Chennai | Best Selenium Training in Chennai | Selenium Training
Thanks for this post.
ReplyDeleteSoftware Testing Training in Chennai | Software Testing Training Institute in Chennai | Software Testing Training Center in Chennai | Best Software Testing Training in Chennai | Software Testing Training