Search in sources :

Example 11 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project SeleniumMaven by jagadeeshshetty.

the class Base method setup.

@BeforeMethod
public void setup(ITestContext context) {
    step("Start time: " + getDateTime("d MMM uuuu HH:mm:ss"));
    step("Running Test on '" + System.getProperty("os.name") + "' OS.");
    step("JVM Version: " + System.getProperty("java.version"));
    step("Browser: " + browser.toUpperCase());
    switch(browser) {
        case "firefox":
            WebDriverManager.firefoxdriver().setup();
            driver.set(new FirefoxDriver());
            break;
        case "chromeHeadless":
            WebDriverManager.chromedriver().setup();
            chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--no-sandbox");
            chromeOptions.addArguments("--disable-dev-shm-usage");
            chromeOptions.addArguments("--headless");
            driver.set(new ChromeDriver(chromeOptions));
            break;
        case "chrome":
            WebDriverManager.chromedriver().setup();
            chromeOptions = new ChromeOptions();
            chromeOptions.addArguments("--no-sandbox");
            chromeOptions.addArguments("--disable-dev-shm-usage");
            driver.set(new ChromeDriver(chromeOptions));
            break;
        case "edge":
            WebDriverManager.edgedriver().setup();
            driver.set(new EdgeDriver());
            break;
        case "ie":
            WebDriverManager.iedriver().setup();
            driver.set(new InternetExplorerDriver());
            break;
        case "opera":
            WebDriverManager.operadriver().setup();
            driver.set(new OperaDriver());
            break;
        case "safari":
            driver.set(new SafariDriver());
            break;
        default:
            step("No proper browser specified.");
            logger.info("No proper browser specified.");
    }
    if (driver != null) {
        step("Driver instance: " + getDriver().toString());
        getDriver().manage().timeouts().pageLoadTimeout(GlobalConfig.pageLoadTimeoutInSec, TimeUnit.SECONDS);
        context.setAttribute("WebDriver", getDriver());
        context.setAttribute("logger", logger);
    }
}
Also used : EdgeDriver(org.openqa.selenium.edge.EdgeDriver) OperaDriver(org.openqa.selenium.opera.OperaDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) SafariDriver(org.openqa.selenium.safari.SafariDriver) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 12 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project Selenium_April_2022 by TestLeafPages.

the class ProjectSpecificMethods method startBrowser.

@Parameters({ "browserName", "URL" })
@BeforeMethod
public void startBrowser(String browserName, String url) {
    if (browserName.equals("Chrome")) {
        WebDriverManager.chromedriver().setup();
        driver = new ChromeDriver();
    } else if (browserName.equals("Edge")) {
        WebDriverManager.edgedriver().setup();
        driver = new EdgeDriver();
    }
    driver.manage().window().maximize();
    driver.get(url);
    driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(5));
}
Also used : EdgeDriver(org.openqa.selenium.edge.EdgeDriver) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) Parameters(org.testng.annotations.Parameters) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 13 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project testbench by vaadin.

the class LocalDriver method createDriver.

/**
 * Creates a {@link WebDriver} instance used for running the test locally
 * for debug purposes.
 */
public static WebDriver createDriver(DesiredCapabilities desiredCapabilities) {
    WebDriver driver;
    if (BrowserUtil.isFirefox(desiredCapabilities)) {
        String firefoxPath = System.getProperty("firefox.path");
        String profilePath = System.getProperty("firefox.profile.path");
        FirefoxOptions options = new FirefoxOptions();
        if (firefoxPath != null) {
            options.setBinary(new FirefoxBinary(new File(firefoxPath)));
        }
        if (profilePath != null) {
            File profileDir = new File(profilePath);
            FirefoxProfile profile = new FirefoxProfile(profileDir);
            options.setProfile(profile);
        }
        options.setHeadless(Parameters.isHeadless());
        driver = new FirefoxDriver(options);
    } else if (BrowserUtil.isChrome(desiredCapabilities)) {
        // Tells chrome not to show warning
        // "You are using an unsupported command-line flag:
        // --ignore-certifcate-errors".
        // #14319
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--test-type ");
        options.setHeadless(Parameters.isHeadless());
        driver = new ChromeDriver(options);
    } else if (BrowserUtil.isSafari(desiredCapabilities)) {
        driver = new SafariDriver();
    } else if (BrowserUtil.isEdge(desiredCapabilities)) {
        driver = new EdgeDriver();
    } else if (BrowserUtil.isIE(desiredCapabilities)) {
        driver = new InternetExplorerDriver();
    } else {
        throw new RuntimeException("Not implemented support for running locally on " + desiredCapabilities.getBrowserName());
    }
    return TestBench.createDriver(driver);
}
Also used : WebDriver(org.openqa.selenium.WebDriver) InternetExplorerDriver(org.openqa.selenium.ie.InternetExplorerDriver) FirefoxProfile(org.openqa.selenium.firefox.FirefoxProfile) SafariDriver(org.openqa.selenium.safari.SafariDriver) FirefoxOptions(org.openqa.selenium.firefox.FirefoxOptions) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) FirefoxDriver(org.openqa.selenium.firefox.FirefoxDriver) FirefoxBinary(org.openqa.selenium.firefox.FirefoxBinary) ChromeOptions(org.openqa.selenium.chrome.ChromeOptions) ChromeDriver(org.openqa.selenium.chrome.ChromeDriver) File(java.io.File)

Example 14 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project selenium-webdriver-java by bonigarcia.

the class ConsoleEventsEdgeSelJupTest method testConsoleEvents.

@Test
void testConsoleEvents(EdgeDriver driver) throws InterruptedException {
    HasLogEvents logger = (HasLogEvents) driver;
    CountDownLatch latch = new CountDownLatch(4);
    logger.onLogEvent(CdpEventTypes.consoleEvent(consoleEvent -> {
        log.debug("{} {}: {}", consoleEvent.getTimestamp(), consoleEvent.getType(), consoleEvent.getMessages());
        latch.countDown();
    }));
    driver.get("https://bonigarcia.dev/selenium-webdriver-java/console-logs.html");
    assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
}
Also used : TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) HasLogEvents(org.openqa.selenium.logging.HasLogEvents) CountDownLatch(java.util.concurrent.CountDownLatch) EdgeDriver(org.openqa.selenium.edge.EdgeDriver) Logger(org.slf4j.Logger) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) SeleniumJupiter(io.github.bonigarcia.seljup.SeleniumJupiter) CdpEventTypes(org.openqa.selenium.devtools.events.CdpEventTypes) MethodHandles.lookup(java.lang.invoke.MethodHandles.lookup) CountDownLatch(java.util.concurrent.CountDownLatch) HasLogEvents(org.openqa.selenium.logging.HasLogEvents) Test(org.junit.jupiter.api.Test)

Example 15 with EdgeDriver

use of org.openqa.selenium.edge.EdgeDriver in project selenium-webdriver-java by bonigarcia.

the class DomMutationEdgeSelJupTest method testDomMutation.

@Test
void testDomMutation(EdgeDriver driver) throws InterruptedException {
    driver.get("https://bonigarcia.dev/selenium-webdriver-java/");
    HasLogEvents logger = (HasLogEvents) driver;
    JavascriptExecutor js = (JavascriptExecutor) driver;
    AtomicReference<DomMutationEvent> seen = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    logger.onLogEvent(CdpEventTypes.domMutation(mutation -> {
        seen.set(mutation);
        latch.countDown();
    }));
    WebElement img = driver.findElement(By.tagName("img"));
    String newSrc = "img/award.png";
    String script = String.format("arguments[0].src = '%s';", newSrc);
    js.executeScript(script, img);
    assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
    assertThat(seen.get().getElement().getAttribute("src")).endsWith(newSrc);
}
Also used : EdgeDriver(org.openqa.selenium.edge.EdgeDriver) Logger(org.slf4j.Logger) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) By(org.openqa.selenium.By) WebElement(org.openqa.selenium.WebElement) SeleniumJupiter(io.github.bonigarcia.seljup.SeleniumJupiter) CdpEventTypes(org.openqa.selenium.devtools.events.CdpEventTypes) MethodHandles.lookup(java.lang.invoke.MethodHandles.lookup) AtomicReference(java.util.concurrent.atomic.AtomicReference) TimeUnit(java.util.concurrent.TimeUnit) Test(org.junit.jupiter.api.Test) HasLogEvents(org.openqa.selenium.logging.HasLogEvents) CountDownLatch(java.util.concurrent.CountDownLatch) DomMutationEvent(org.openqa.selenium.devtools.events.DomMutationEvent) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) LoggerFactory.getLogger(org.slf4j.LoggerFactory.getLogger) JavascriptExecutor(org.openqa.selenium.JavascriptExecutor) DomMutationEvent(org.openqa.selenium.devtools.events.DomMutationEvent) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) WebElement(org.openqa.selenium.WebElement) HasLogEvents(org.openqa.selenium.logging.HasLogEvents) Test(org.junit.jupiter.api.Test)

Aggregations

EdgeDriver (org.openqa.selenium.edge.EdgeDriver)49 ChromeDriver (org.openqa.selenium.chrome.ChromeDriver)28 FirefoxDriver (org.openqa.selenium.firefox.FirefoxDriver)22 ChromeOptions (org.openqa.selenium.chrome.ChromeOptions)17 InternetExplorerDriver (org.openqa.selenium.ie.InternetExplorerDriver)15 WebDriver (org.openqa.selenium.WebDriver)14 EdgeOptions (org.openqa.selenium.edge.EdgeOptions)12 SafariDriver (org.openqa.selenium.safari.SafariDriver)10 FirefoxOptions (org.openqa.selenium.firefox.FirefoxOptions)9 InternetExplorerOptions (org.openqa.selenium.ie.InternetExplorerOptions)7 OperaDriver (org.openqa.selenium.opera.OperaDriver)7 WebElement (org.openqa.selenium.WebElement)6 File (java.io.File)5 URL (java.net.URL)5 HtmlUnitDriver (org.openqa.selenium.htmlunit.HtmlUnitDriver)5 Test (org.junit.jupiter.api.Test)4 DesiredCapabilities (org.openqa.selenium.remote.DesiredCapabilities)4 RemoteWebDriver (org.openqa.selenium.remote.RemoteWebDriver)4 SeleniumJupiter (io.github.bonigarcia.seljup.SeleniumJupiter)3 MethodHandles.lookup (java.lang.invoke.MethodHandles.lookup)3