public static WebDriver selectLocalBrowser() { switch (browser) { case Chrome: return new ChromeDriver(); case Firefox: return new FirefoxDriver(); case IE: return new InternetExplorerDriver(); case Opera: return new OperaDriver(); case Safari: return new SafariDriver(); default: throw new WebDriverException("No browser specified"); } }
public SeleniumExtension() { handlerMap.put(ChromeDriver.class, ChromeDriverHandler.class); handlerMap.put(FirefoxDriver.class, FirefoxDriverHandler.class); handlerMap.put(EdgeDriver.class, EdgeDriverHandler.class); handlerMap.put(OperaDriver.class, OperaDriverHandler.class); handlerMap.put(SafariDriver.class, SafariDriverHandler.class); handlerMap.put(RemoteWebDriver.class, RemoteDriverHandler.class); handlerMap.put(AppiumDriver.class, AppiumDriverHandler.class); handlerMap.put(List.class, ListDriverHandler.class); handlerMap.put(PhantomJSDriver.class, OtherDriverHandler.class); templateHandlerMap.put("chrome", ChromeDriver.class); templateHandlerMap.put("firefox", FirefoxDriver.class); templateHandlerMap.put("edge", EdgeDriver.class); templateHandlerMap.put("opera", OperaDriver.class); templateHandlerMap.put("safari", SafariDriver.class); templateHandlerMap.put("appium", AppiumDriver.class); templateHandlerMap.put("phantomjs", PhantomJSDriver.class); templateHandlerMap.put("chrome-in-docker", RemoteWebDriver.class); templateHandlerMap.put("firefox-in-docker", RemoteWebDriver.class); templateHandlerMap.put("opera-in-docker", RemoteWebDriver.class); }
@Override public void resolve() { try { Optional<Object> testInstance = context.getTestInstance(); Optional<Capabilities> capabilities = annotationsReader .getCapabilities(parameter, testInstance); OperaOptions operaOptions = (OperaOptions) getOptions(parameter, testInstance); if (capabilities.isPresent()) { operaOptions.merge(capabilities.get()); } object = new OperaDriver(operaOptions); } catch (Exception e) { handleException(e); } }
public WebDriver createInstance(Type type) { switch (type) { case CHROME: return new ChromeDriver(); case CHROME_HEADLESS: ChromeOptions options = new ChromeOptions(); options.addArguments("--headless", "--disable-gpu"); ChromeDriver chromeDriver = new ChromeDriver(options); return chromeDriver; case OPERA: return new OperaDriver(getOperaCapabilities()); case FIREFOX: default: return new FirefoxDriver(); } }
@Before public void setupTest() { File operaBinary = IS_OS_WINDOWS ? new File("C:\\Program Files\\Opera\\launcher.exe") : new File("/usr/bin/opera"); assumeTrue(operaBinary.exists()); OperaOptions options = new OperaOptions(); options.setBinary(operaBinary); driver = new OperaDriver(options); }
@Test public void testWithFirefoxAndOpera(FirefoxDriver firefox, OperaDriver opera) { firefox.get("http://www.seleniumhq.org/"); opera.get("http://junit.org/junit5/"); assertTrue(firefox.getTitle().startsWith("Selenium")); assertTrue(opera.getTitle().equals("JUnit 5")); }
@Test void operaExtensionTest( @Binary("/usr/bin/opera") @Extensions("atomizer.crx") OperaDriver driver) { driver.get("https://bonigarcia.github.io/selenium-jupiter/"); assertThat(driver.getTitle(), containsString("A JUnit 5 extension for Selenium WebDriver")); }
@Test public void operaTest( @Binary("/usr/bin/opera") @Arguments("private") OperaDriver driver) { driver.get("https://bonigarcia.github.io/selenium-jupiter/"); assertThat(driver.getTitle(), containsString("A JUnit 5 extension for Selenium WebDriver")); }
static Stream<Arguments> forcedTestProvider() { return Stream.of( Arguments.of(AppiumDriverHandler.class, ForcedAppiumJupiterTest.class, AppiumDriver.class, "appiumNoCapabilitiesTest"), Arguments.of(AppiumDriverHandler.class, ForcedAppiumJupiterTest.class, AppiumDriver.class, "appiumWithCapabilitiesTest"), Arguments.of(ChromeDriverHandler.class, ForcedBadChromeJupiterTest.class, ChromeDriver.class, "chromeTest"), Arguments.of(FirefoxDriverHandler.class, ForcedBadFirefoxJupiterTest.class, FirefoxDriver.class, "firefoxTest"), Arguments.of(RemoteDriverHandler.class, ForcedBadRemoteJupiterTest.class, RemoteWebDriver.class, "remoteTest"), Arguments.of(EdgeDriverHandler.class, ForcedEdgeJupiterTest.class, EdgeDriver.class, "edgeTest"), Arguments.of(OperaDriverHandler.class, ForcedOperaJupiterTest.class, OperaDriver.class, "operaTest"), Arguments.of(SafariDriverHandler.class, ForcedSafariJupiterTest.class, SafariDriver.class, "safariTest")); }
@Test void testOperaOptions() throws Exception { Parameter parameter = OperaWithOptionsJupiterTest.class .getMethod("operaTest", OperaDriver.class).getParameters()[0]; OperaOptions operaOptions = (OperaOptions) annotationsReader .getOptions(parameter, empty()); assertThat(operaOptions.asMap().get("operaOptions").toString(), containsString("binary")); }
/** * {@inheritDoc} */ @Override public OperaDriver start(Capabilities other) { Capabilities capabilities = this.mergeCapabilities(other); if (capabilities == null) { return new OperaDriver(); } return new OperaDriver(capabilities); }
protected void setupOperaDriver() { DesiredCapabilities capabilities = DesiredCapabilities.operaBlink(); OperaOptions options = new OperaOptions(); options.setBinary(new File("/usr/bin/opera")); capabilities.setCapability(OperaOptions.CAPABILITY, options); setDriver(new OperaDriver(capabilities)); getDriver().manage().window().setSize( new Dimension(1366, 768)); }
@Override public WebDriver createDriver(Capabilities capabilities) { String driverVersion = (String) capabilities.getCapability(CAPABILITY_DRIVER_VERSION); OperaDriverManager.getInstance().version(driverVersion).setup(); return new OperaDriver((OperaOptions) capabilities); }
@Test public void operaTest(OperaDriver driver) { assertThat(driver, nullValue()); }
@Test public void operaTest(OperaDriver driver) { driver.get("https://bonigarcia.github.io/selenium-jupiter/"); assertThat(driver.getTitle(), containsString("A JUnit 5 extension for Selenium WebDriver")); }
@Test public void test(OperaDriver driver) { driver.get("https://bonigarcia.github.io/selenium-jupiter/"); assertThat(driver.getTitle(), containsString("A JUnit 5 extension for Selenium WebDriver")); }
private static WebDriver getOperaDriverLinux32(){ System.setProperty("webdriver.Opera.driver",dir+"Linux32Operadriver"); WebDriver driver = new OperaDriver(); return driver; }
private static WebDriver getOperaDriverWindows32(){ System.setProperty("webdriver.Opera.driver",dir+"Windows32Operadriver.exe"); WebDriver driver = new OperaDriver(); return driver; }
private static WebDriver getOperaDriverLinux64(){ System.setProperty("webdriver.Opera.driver",dir+"Linux64Operadriver"); WebDriver driver = new OperaDriver(); return driver; }
private static WebDriver getOperaDriverWindows64(){ System.setProperty("webdriver.Opera.driver",dir+"Windows64Operadriver.exe"); WebDriver driver = new OperaDriver(); return driver; }
private static WebDriver getOperaDriverMac(){ System.setProperty("webdriver.Opera.driver",dir+"MacOperadriver"); WebDriver driver = new OperaDriver(); return driver; }
@Override public WebDriver getWebDriver(Capabilities capabilities) { return new OperaDriver(capabilities); }
private static WebDriver getOperaDriver(String language) { return new OperaDriver(getOperaCapabilities(language)); }
/** * Get the default {@link OperaDriver} configuration. * * @return The default {@link OperaDriver} configuration. */ public OperaConfiguration opera() { return (OperaConfiguration) this.getConfiguration().get(OperaDriver.class); }
/** * Set the default {@link InternetExplorerDriver} configuration. * * @param configuration * The {@link InternetExplorerDriver} configuration. * * @return Itself. */ public SeleniumConfiguration opera(OperaConfiguration configuration) { return this.setDriverConfiguration(OperaDriver.class, configuration, new OperaConfiguration()); }