Wednesday, January 3, 2024

Sample Web Browser configuration for selenium automation

package com.example.test.runner;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;

import java.io.IOException;

public class ChromeBrowserExecution {
public WebDriver getDriver() throws IOException {

System.setProperty("webdriver.chrome.driver", "C:\\Intel\\chrome\\chrome-win64\\chrome.exe");
//System.setProperty("webdriver.chrome.whitelistedIps", "*");

ChromeOptions ops = new ChromeOptions();
ops.addArguments("--remote-allow-origins=*");
//ops.addArguments("--headless");

// ----- Creating an object of ChromeDriver
WebDriver driver = new ChromeDriver(ops);
driver.manage().deleteAllCookies();
driver.manage().window().maximize();

return driver;
}

}

package com.example.test.runner;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.edge.EdgeOptions;

import java.io.IOException;

public class EdgeBrowserExecution {
public WebDriver getDriver() throws IOException {
System.setProperty("webdriver.edge.driver","C:\\Intel\\webDriver\\Edge\\msedgedriver.exe");

// ----- Creating an object of EdgeDriver
WebDriver driver = new EdgeDriver
(new EdgeOptions().addArguments("--remote-allow-origins=*"));
driver.manage().deleteAllCookies();
driver.manage().window().maximize();

return driver;
}

}

package com.example.test.runner;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

import java.io.IOException;

public class FirefoxBrowserExecution {
public WebDriver getDriver() throws IOException {
// Setting system properties of ChromeDriver
System.setProperty("webdriver.gecko.driver", "C:\\Intel\\Firefox Geckodriver 0.31.0\\geckodriver.exe");
// System.setProperty("webdriver.chrome.whitelistedIps", "*");
// C:\Intel\chromedriver_win32

// ChromeOptions ops = new ChromeOptions();
// ops.addArguments("--remote-allow-origins=*");
// ops.addArguments("--headless");

// ----- Creating an object of ChromeDriver
WebDriver driver3 = new FirefoxDriver();
driver3.manage().deleteAllCookies();
driver3.manage().window().maximize();
return driver3;
}
}

No comments:

Post a Comment