@ParameterizedTest @MethodSource("testClassProvider") @SuppressWarnings("unchecked") void testFirefoxOptions(Class<?> testClass) throws Exception { Parameter parameter = testClass .getMethod("webrtcTest", FirefoxDriver.class) .getParameters()[0]; Optional<Object> testInstance = Optional.of(testClass.newInstance()); FirefoxOptions firefoxOptions = (FirefoxOptions) annotationsReader .getOptions(parameter, testInstance); Map<String, Map<String, Boolean>> options = (Map<String, Map<String, Boolean>>) firefoxOptions .asMap().get(FIREFOX_OPTIONS); assertTrue(options.get("prefs") .get("media.navigator.permission.disabled")); assertTrue(options.get("prefs").get("media.navigator.streams.fake")); }
public static WebDriver getDriver() { String browser = System.getenv("BROWSER"); if (browser == null) { ChromeDriverManager.getInstance().setup(); return new ChromeDriver(); } switch (browser) { case "IE": InternetExplorerDriverManager.getInstance().setup(); return new InternetExplorerDriver(); case "FIREFOX": FirefoxDriverManager.getInstance().setup(); return new FirefoxDriver(); default: ChromeDriverManager.getInstance().setup(); return new ChromeDriver(); } }
@Test public void startByWebDriver() { System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe"); WebDriver driver = new FirefoxDriver(); driver.navigate().to("http://localhost:8080/login"); driver.findElement(By.name("username")).clear(); driver.findElement(By.name("username")).sendKeys("TestAcc1"); driver.findElement(By.name("password")).clear(); driver.findElement(By.name("password")).sendKeys("12345678"); driver.findElement(By.xpath("//button[@type='submit']")).click(); driver.navigate().to("http://localhost:8080"); driver.findElement(By.linkText("Logout")).click(); }
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); FirefoxOptions firefoxOptions = (FirefoxOptions) getOptions( parameter, testInstance); if (capabilities.isPresent()) { firefoxOptions.merge(capabilities.get()); } object = new FirefoxDriver(firefoxOptions); } catch (Exception e) { handleException(e); } }
public static WebDriver getDriverUsingSwitch() { final String browser = System.getProperty("browser"); if (browser == null || browser.isEmpty()) { throw new IllegalStateException("'browser' property is missing!"); } switch (browser) { case CHROME: return new ChromeDriver(); case FIREFOX: return new FirefoxDriver(); default: throw new IllegalArgumentException(browser + " browser is not supported!"); } }
public static WebDriver getDriverUsingIf(DesiredCapabilities desiredCapabilities) { if (desiredCapabilities == null) { throw new IllegalStateException("DesiredCapabilities are missing!"); } final String browser = desiredCapabilities.getBrowserName(); if (CHROME.equalsIgnoreCase(browser)) { return new ChromeDriver(desiredCapabilities); } else if (FIREFOX.equalsIgnoreCase(browser)) { return new FirefoxDriver(desiredCapabilities); } else if (browser.isEmpty()) { throw new IllegalStateException("'browser' capability is missing!"); } throw new IllegalArgumentException(desiredCapabilities.getBrowserName() + " browser is not supported!"); }
/** * 本地初始化Firefox浏览器driver */ public Firefox() { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability("acceptSslCerts", false); FirefoxBrowserProfile firefoxProfile = new FirefoxBrowserProfile(); String sProfile = firefoxProfile.getDefaultProfile(); if (sProfile.equals("")) { this.driver = new FirefoxDriver(); } else { try { FirefoxProfile profile = new FirefoxProfile(new File(sProfile)); FirefoxBinary firefoxBinary = new FirefoxBinary(new File(firefoxProfile.getFirefoxBinInstallPath())); profile.setAcceptUntrustedCertificates(false); this.driver = new FirefoxDriver(firefoxBinary, profile); } catch (Exception e) { throw new RuntimeException("Failed to start firefox browser,please check!", e); } } }
public LoginSteps() { Referendum ref = new Referendum(); ref.setName("Ref"); ref.setStartDate(new Date()); Calendar c = Calendar.getInstance(); c.setTime(new Date()); c.add(Calendar.DATE, 1); ref.setExpiryDate(c.getTime()); ref.setNumChoices(1); ref.setQuestion("Question"); ref.setInstructions("Ins"); Repository.electionR.save(ref); driver = new FirefoxDriver(); }
public static WebDriver createWebDriver() throws Exception { DesiredCapabilities capability = DesiredCapabilities.chrome(); capability.setJavascriptEnabled(true); FirefoxProfile firefoxProfile = new FirefoxProfile(); // 鍘绘帀css // firefoxProfile.setPreference("permissions.default.stylesheet", 2); // 鍘绘帀鍥剧墖 // firefoxProfile.setPreference("permissions.default.image", 2); // 鍘绘帀flash firefoxProfile.setPreference("dom.ipc.plugins.enabled.libflashplayer.so", false); capability.setCapability("firefox_profile", firefoxProfile); WebDriver driver = new FirefoxDriver(capability); // WebDriver driver = new HtmlUnitDriver(); // WebDriver driver = new HtmlUnitDriver(); // 濡傛灉3s鍐呰繕瀹氫綅涓嶅埌鍒欐姏鍑哄紓甯? // driver.manage().timeouts().implicitlyWait(IMPLICITLYWAIT, // TimeUnit.SECONDS); // 椤甸潰鍔犺浇瓒呮椂鏃堕棿璁剧疆涓?5s // driver.manage().timeouts().pageLoadTimeout(PAGELOADTIMEOUT, // TimeUnit.SECONDS); // driver.manage().timeouts().setScriptTimeout(60,TimeUnit.SECONDS); return driver; }
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(); } }
/** * Methods that is bound to the INIT command. * * @param command Command to retrieve method parameters from. * @return <tt>true</tt> if the init command was correctly executed, <tt>false</tt> otherwise. */ public static CommandStatus init(final CommandLine command) { final String contest = command.getOptionValue(CONTEST); if (command.hasOption(INIT_METHOD)) { final String method = command.getOptionValue(INIT_METHOD).toLowerCase(); if (FIREFOX_METHOD.equals(method)) { return browserInit(FirefoxDriver::new, contest); } else if (TEXT_METHOD.equals(method)) { return textInit(contest); } err.println("-> Invalid method provided (only firefox or text supported"); return CommandStatus.INVALID_FORMAT; } return browserInit(FirefoxDriver::new, contest); }
@Test public void f() { WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://test.zyd.onlyou.com/login.htm"); driver.manage().window(); driver.findElement(By.name("username")).click(); driver.findElement(By.name("username")).sendKeys("pancs_qd"); driver.findElement(By.name("password")).click(); driver.findElement(By.name("password")).sendKeys("111111"); driver.findElement(By.className("btn-submit")).click(); WebDriverWait wait = new WebDriverWait(driver,10);//等待最长时间10s wait.until(new ExpectedCondition<WebElement>(){ @Override public WebElement apply(WebDriver d){ return d.findElement(By.id("")); } }).click(); driver.close(); }
@Before public void prepare() { testUrl = "https://leftstick.github.io/"; System.setProperty("webdriver.gecko.driver","webdriver/geckodriver"); // Create a new instance of the Chrome driver // Notice that the remainder of the code relies on the interface, // not the implementation. driver = new FirefoxDriver(); // And now use this to visit myBlog // Alternatively the same thing can be done like this // driver.navigate().to(testUrl); driver.get(testUrl); }
@NotNull private static WebDriver allocateFirefoxDriver(Locale lang) throws IOException { FirefoxOptions fo = new FirefoxOptions(); ////-- Set the XDG_CONFIG_HOME envvar; this is used by fontconfig as one of its locations //File dir = createFontConfigFile(); //FirefoxBinary ffb = new FirefoxBinary(); //ffb.setEnvironmentProperty("XDG_CONFIG_HOME", dir.getParentFile().getAbsolutePath()); //FirefoxOptions ffo = new FirefoxOptions(getFirefoxCapabilities(lang)); //ffo.setBinary(ffb); //FirefoxDriver wd = new FirefoxDriver(ffo); replaceDotFonts(); FirefoxDriver wd = new FirefoxDriver(getFirefoxCapabilities(lang)); String browserName = wd.getCapabilities().getBrowserName(); String version = wd.getCapabilities().getVersion(); System.out.println("wd: allocated " + browserName + " " + version); return wd; }
private WebDriver firefox(final Settings settings, DesiredCapabilities customDesiredCapabilities) { DesiredCapabilities desiredCapabilities = getFireFoxDesiredCapabilities(settings); if (!customDesiredCapabilities.asMap().isEmpty()) { desiredCapabilities.merge(customDesiredCapabilities); } return new FirefoxDriver(desiredCapabilities); }
private WebDriver gecko(DesiredCapabilities customDesiredCapabilities) { FirefoxDriverManager.getInstance().setup(); DesiredCapabilities desiredCapabilities = getGeckoDesiredCapabilities(); if (!customDesiredCapabilities.asMap().isEmpty()) { desiredCapabilities.merge(customDesiredCapabilities); } return new FirefoxDriver(desiredCapabilities); }
private DesiredCapabilities getFireFoxDesiredCapabilities(Settings settings) { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); setAlertBehaviorCapabilities(capabilities); capabilities.setCapability(FirefoxDriver.MARIONETTE, false); capabilities.setCapability(FirefoxDriver.PROFILE, getFirefoxProfile(settings)); capabilities.setPlatform(Platform.WINDOWS); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); setLoggingPrefs(capabilities); setProxy(capabilities); return capabilities; }
private DesiredCapabilities getGeckoDesiredCapabilities() { DesiredCapabilities capabilities = DesiredCapabilities.firefox(); setAlertBehaviorCapabilities(capabilities); capabilities.setCapability(FirefoxDriver.MARIONETTE, true); capabilities.setPlatform(Platform.WINDOWS); capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true); setLoggingPrefs(capabilities); setProxy(capabilities); return capabilities; }
public static WebDriver getFFDriver() { Settings ffSettings = new Settings(); BeanUtils.copyProperties(SELENIUM_SETTINGS, ffSettings); ffSettings.setDriverName("firefox"); driverHolder.set(new FramesTransparentWebDriver(new FirefoxDriver(getFireFoxDesiredCapabilities(ffSettings)))); return driverHolder.get(); }
@Override public FirefoxDriver getObject() throws BeansException { if (properties.getFirefox().isEnabled()) { try { return new FirefoxDriver(); } catch (WebDriverException e) { e.printStackTrace(); // swallow the exception } } return null; }
@Test public void testWithMockedFirefox() { load(new Class[]{MockFirefoxConfiguration.class}, "com.greglturnquist.webdriver.safari.enabled:false", "com.greglturnquist.webdriver.chrome.enabled:false"); WebDriver driver = context.getBean(WebDriver.class); assertThat(ClassUtils.isAssignable(TakesScreenshot.class, driver.getClass())).isTrue(); assertThat(ClassUtils.isAssignable(FirefoxDriver.class, driver.getClass())).isTrue(); }
@Bean FirefoxDriverFactory firefoxDriverFactory() { FirefoxDriverFactory factory = mock(FirefoxDriverFactory.class); given(factory.getObject()) .willReturn(mock(FirefoxDriver.class)); return factory; }
@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")); }
@Override public WebDriver getWebDriver() { System.setProperty("webdriver.gecko.driver", "src/test/resources/geckodriver.v0.11.1.mac"); DesiredCapabilities capabilities=DesiredCapabilities.firefox(); WebDriver driver = new FirefoxDriver(capabilities); return driver; }
@BeforeTest @Parameters({"url"}) public void setup(String url) { // Set the path to the geckodriver System.setProperty("webdriver.gecko.driver", "./drivers/geckodriver"); // Instantiate a new Page and navigate // to the url specified in the testng.xml page = new Page(new FirefoxDriver()); page.navigate(url); }
/** * Generates a firefox webdriver. * * @return * A firefox webdriver * @throws TechnicalException * if an error occured when Webdriver setExecutable to true. */ private WebDriver generateFirefoxDriver() throws TechnicalException { final String pathWebdriver = DriverFactory.getPath(Driver.FIREFOX); if (!new File(pathWebdriver).setExecutable(true)) { throw new TechnicalException(Messages.getMessage(TechnicalException.TECHNICAL_ERROR_MESSAGE_WEBDRIVER_SET_EXECUTABLE)); } logger.info("Generating Firefox driver ({}) ...", pathWebdriver); System.setProperty(Driver.FIREFOX.getDriverName(), pathWebdriver); final FirefoxOptions firefoxOptions = new FirefoxOptions(); final FirefoxBinary firefoxBinary = new FirefoxBinary(); final DesiredCapabilities capabilities = DesiredCapabilities.firefox(); capabilities.setCapability(CapabilityType.ForSeleniumServer.ENSURING_CLEAN_SESSION, true); capabilities.setCapability(CapabilityType.UNEXPECTED_ALERT_BEHAVIOUR, UnexpectedAlertBehaviour.ACCEPT); setLoggingLevel(capabilities); // Proxy configuration if (Context.getProxy().getProxyType() != ProxyType.UNSPECIFIED && Context.getProxy().getProxyType() != ProxyType.AUTODETECT) { capabilities.setCapability(CapabilityType.PROXY, Context.getProxy()); } if (Context.isHeadless()) { firefoxBinary.addCommandLineOptions("--headless"); firefoxOptions.setBinary(firefoxBinary); } firefoxOptions.setLogLevel(Level.OFF); capabilities.setCapability(FirefoxOptions.FIREFOX_OPTIONS, firefoxOptions); return new FirefoxDriver(capabilities); }
public static void main(String[] args) { WebDriver driver = new FirefoxDriver(); driver.get("http://cogenglab.csd.uwo.ca/rushdi.htm"); WebElement webElement = driver.findElement(By.xpath("//*[@id='content']")); System.out.println(webElement.getText()); }
@Before public void setUpTest(){ System.setProperty("webdriver.gecko.driver", "C:\\webdriver\\geckodriver-v0.11.1-win64\\geckodriver.exe"); driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://www.google.com"); }
@Before public void setUpTest(){ System.setProperty("webdriver.gecko.driver", "C:\\webdriver\\geckodriver-v0.11.1-win64\\geckodriver.exe"); DesiredCapabilities dc = DesiredCapabilities.firefox(); dc.setCapability("marionette", true); driver = new FirefoxDriver(); driver.manage().window().maximize(); driver.get("http://www.doqconsulting.com.br/#contact"); }
private static WebDriver getFirefoxDriver(){ /* Need to have an updated Firefox, but also need to download and put the geckodriver in your own home dir. See: https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver https://github.com/mozilla/geckodriver/releases However, drivers for FireFox have been often unstable. Therefore, I do recommend to use Chrome instead */ setupDriverExecutable("geckodriver", "webdriver.gecko.driver"); DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox(); desiredCapabilities.setCapability("marionette", true); desiredCapabilities.setJavascriptEnabled(true); return new FirefoxDriver(desiredCapabilities); }
protected RemoteWebDriver openFirefoxAtUrl(String url) { String geckoDriver = getGeckoDriver(); if (geckoDriver != null) System.setProperty("webdriver.gecko.driver", geckoDriver); driver = new FirefoxDriver(); driver.get(url); return driver; // driver = new ChromeDriver(); // driver.get(url); // return driver; }
@Test public void webrtcTest(FirefoxDriver driver) { driver.get( "https://webrtc.github.io/samples/src/content/devices/input-output/"); assertThat(driver.findElement(By.id("video")).getTagName(), equalTo("video")); }
@Test public void webrtcTest(@Arguments("-private") @Preferences({ "media.navigator.permission.disabled=true", "media.navigator.streams.fake=true" }) FirefoxDriver driver) { driver.get( "https://webrtc.github.io/samples/src/content/devices/input-output/"); assertThat(driver.findElement(By.id("video")).getTagName(), equalTo("video")); }
@Test public void testWithChromeAndFirefox(ChromeDriver driver1, FirefoxDriver driver2) { driver1.get("http://www.seleniumhq.org/"); driver2.get("http://junit.org/junit5/"); assertThat(driver1.getTitle(), startsWith("Selenium")); assertThat(driver2.getTitle(), equalTo("JUnit 5")); }
@Disabled("Redudant test for Travis CI suite") // tag::snippet-in-doc[] @Test public void testWithTwoFirefoxs(FirefoxDriver driver1, FirefoxDriver driver2) { driver1.get("http://www.seleniumhq.org/"); driver2.get("http://junit.org/junit5/"); assertThat(driver1.getTitle(), startsWith("Selenium")); assertThat(driver2.getTitle(), equalTo("JUnit 5")); }
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")); }
@Override public WebCapabilitiesBuilder addBrowserProfile(BrowserProfile browserProfile) throws CapabilityNotPresentException { String browser = capabilities.getBrowserName(); if (browser.equalsIgnoreCase("firefox")) { if (browserProfile instanceof FirefoxBrowserProfile) { capabilities.setCapability(FirefoxDriver.PROFILE, browserProfile.createProfile()); } } else if (browser.equalsIgnoreCase("ie")) { if (browserProfile instanceof IEBrowserProfile) { @SuppressWarnings("unchecked") Map<String, Boolean> ieCapabilities = (Map<String, Boolean>) browserProfile.createProfile(); Iterator<Map.Entry<String, Boolean>> it = ieCapabilities.entrySet().iterator(); while (it.hasNext()) { Map.Entry<String, Boolean> keyValuePair = it.next(); capabilities.setCapability(keyValuePair.getKey(), keyValuePair.getValue()); } } } else if (browser.equalsIgnoreCase("chrome")) { if (browserProfile instanceof ChromeBrowserProfile) { capabilities.setCapability(ChromeOptions.CAPABILITY, browserProfile.createProfile()); } } else { throw new CapabilityNotPresentException("Unable to create capability for adding browser profile!"); } return this; }
/** * {@inheritDoc} */ @Override public FirefoxDriver start(Capabilities other) { Capabilities capabilities = this.mergeCapabilities(other); if (capabilities == null) { return new FirefoxDriver(); } return new FirefoxDriver(capabilities); }