Clients can execute contents in different programs at the same time. For show, we will utilize a similar situation that we had taken for Selenium Grid. In the Selenium Grid model, we had executed the contents remotely; here we will execute the contents locally.
Above all else, guarantee that you have proper drivers downloaded. It would be ideal if you allude the part "Selenium Grid" for downloading IE and Chrome drivers.
Example
For showing, we will perform percent adding machine in all the programs at the same time.
package TestNG;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.*;
import org.testng.annotations.*;
public class TestNGClass {
private WebDriver driver;
private String URL = "http://www.calculator.net";
@Parameters("browser")
@BeforeTest
public void launchapp(String browser) {
if (browser.equalsIgnoreCase("firefox")) {
System.out.println(" Executing on FireFox");
driver = new FirefoxDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
} else if (browser.equalsIgnoreCase("chrome")) {
System.out.println(" Executing on CHROME");
System.out.println("Executing on IE");
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
} else if (browser.equalsIgnoreCase("ie")) {
System.out.println("Executing on IE");
System.setProperty("webdriver.ie.driver", "D:\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.get(URL);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
} else {
throw new IllegalArgumentException("The Browser Type is Undefined");
}
}
@Test
public void calculatepercent() {
// Click on Math Calculators
driver.findElement(By.xpath(".//*[@id = 'menu']/div[3]/a")).click();
// Click on Percent Calculators
driver.findElement(By.xpath(".//*[@id = 'menu']/div[4]/div[3]/a")).click();
// Enter value 10 in the first number of the percent Calculator
driver.findElement(By.id("cpar1")).sendKeys("10");
// Enter value 50 in the second number of the percent Calculator
driver.findElement(By.id("cpar2")).sendKeys("50");
// Click Calculate Button
driver.findElement(By.xpath(".//*[@id = 'content']/table/tbody/tr/td[2]/input")).click();
// Get the Result Text based on its xpath
String result =
driver.findElement(By.xpath(".//*[@id = 'content']/p[2]/span/font/b")).getText();
// Print a Log In message to the screen
System.out.println(" The Result is " + result);
if(result.equals("5")) {
System.out.println(" The Result is Pass");
} else {
System.out.println(" The Result is Fail");
}
}
@AfterTest
public void closeBrowser() {
driver.close();
}
}
Make a XML which will help us in parameterizing the program name and remember to make reference to parallel="tests" so as to execute in all the programs at the same time.
Execute the content by performing right-click on the XML record and select 'Run As' >> 'TestNG' Suite as demonstrated as follows.
Output
All the program would be propelled at the same time and the outcome would be imprinted in the comfort.
Note − To execute on IE effectively, guarantee that the check box 'Empower Protected Mode' under the security Tab of 'IE Option' is either checked or unchecked over all zones.
TestNG results can be seen in HTML design for point by point investigation.