How to Close three different Browser Instances using 'driver.quit()' ?
Below code will open three browsers (IE,Firefox and Chrome) and will open URL and finally it closes all the three opened browsers by 'driver.quit()' function.
}
Below code will open three browsers (IE,Firefox and Chrome) and will open URL and finally it closes all the three opened browsers by 'driver.quit()' function.
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
public class Test
{
private List<WebDriver> drivers;
public Test( )
{
this.drivers = new ArrayList<WebDriver>();
}
public void CloseAll()
{
for(WebDriver d : drivers)
{
d.quit();
}
}
public static void main(String[] args)
{
Test1 sc = new Test1();
sc.IE("http://google.com");
sc.Firefox("http://google.com");
sc.Chrome("http://google.com");
sc.CloseAll();
}
//Internet Explorer driver
public void IE(String URL)
{
//Set you IEDriver path as per your System Path
System.setProperty("webdriver.ie.driver","S:\\IE Driver\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.get(URL);
this.drivers.add(driver);
}
//Firefox driver
public void Firefox(String URL)
{
WebDriver driver = new FirefoxDriver();
driver.get(URL);
this.drivers.add(driver);
}
//Chrome driver
public void Chrome(String URL)
{
//Set you ChromeDriver path as per your System Path
System.setProperty("webdriver.chrome.driver","S://Chrome Driver//chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get(URL);
this.drivers.add(driver);
}
}
}
No comments:
Post a Comment