List of usage examples for org.openqa.selenium.firefox FirefoxDriver get
@Override public void get(String url)
From source file:com.vaadin.testbench.TestBenchDriverTest.java
@Test public void testTestBenchDriverActsAsProxy() { FirefoxDriver mockDriver = createMock(FirefoxDriver.class); mockDriver.close();//from w ww .j av a 2 s. c om expectLastCall().once(); WebElement mockElement = createNiceMock(WebElement.class); expect(mockDriver.findElement(isA(By.class))).andReturn(mockElement); List<WebElement> elements = Arrays.asList(mockElement); expect(mockDriver.findElements(isA(By.class))).andReturn(elements); mockDriver.get("foo"); expectLastCall().once(); expect(mockDriver.getCurrentUrl()).andReturn("foo"); expect(mockDriver.getPageSource()).andReturn("<html></html>"); expect(mockDriver.getTitle()).andReturn("bar"); expect(mockDriver.getWindowHandle()).andReturn("baz"); Set<String> handles = new HashSet<String>(); expect(mockDriver.getWindowHandles()).andReturn(handles); Options mockOptions = createNiceMock(Options.class); expect(mockDriver.manage()).andReturn(mockOptions); Navigation mockNavigation = createNiceMock(Navigation.class); expect(mockDriver.navigate()).andReturn(mockNavigation); mockDriver.quit(); expectLastCall().once(); expect(((JavascriptExecutor) mockDriver).executeScript(anyObject(String.class))).andStubReturn(true); TargetLocator mockTargetLocator = createNiceMock(TargetLocator.class); expect(mockDriver.switchTo()).andReturn(mockTargetLocator); replay(mockDriver); // TestBenchDriverProxy driver = new TestBenchDriverProxy(mockDriver); WebDriver driver = TestBench.createDriver(mockDriver); driver.close(); By mockBy = createNiceMock(By.class); assertTrue(driver.findElement(mockBy) instanceof TestBenchElementCommands); assertTrue(driver.findElements(mockBy).get(0) instanceof TestBenchElementCommands); driver.get("foo"); assertEquals("foo", driver.getCurrentUrl()); assertEquals("<html></html>", driver.getPageSource()); assertEquals("bar", driver.getTitle()); assertEquals("baz", driver.getWindowHandle()); assertEquals(handles, driver.getWindowHandles()); assertEquals(mockOptions, driver.manage()); assertEquals(mockNavigation, driver.navigate()); driver.quit(); assertEquals(mockTargetLocator, driver.switchTo()); verify(mockDriver); }
From source file:com.zhao.crawler.util.CookieUtil.java
License:Open Source License
/** * csdn??cookies?//from w ww.java 2 s .c o m * * @param username * ?? * @param password * ? * @param geckodriverpath * gecko?https://github.com/mozilla/geckodriver * @param savecookiepath * cookies? * @throws Exception */ public static void firfoxDriverGetCookies(String username, String password, String geckodriverpath, String savecookiepath) throws Exception { // ??? System.setProperty("webdriver.gecko.driver", geckodriverpath); FirefoxDriver driver = new FirefoxDriver(); String baseUrl = "http://kaixin65.com/member.php?mod=logging&action=login&infloat=yes&handlekey=login&inajax=1&ajaxtarget=fwin_content_login"; // url driver.get(baseUrl); // ? driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); // ?? WebElement elemUsername = driver.findElement(By.name("username")); WebElement elemPassword = driver.findElement(By.name("password")); WebElement btn = driver.findElement(By.className("logging")); WebElement rememberMe = driver.findElement(By.id("rememberMe")); // ?? elemUsername.sendKeys(username); elemPassword.sendKeys(password); rememberMe.click(); // ??? btn.submit(); Thread.sleep(5000); driver.get("http://msg.csdn.net/"); Thread.sleep(5000); // ?cookies driver.manage().getCookies(); Set<org.openqa.selenium.Cookie> cookies = driver.manage().getCookies(); System.out.println("Size: " + cookies.size()); Iterator<org.openqa.selenium.Cookie> itr = cookies.iterator(); CookieStore cookieStore = new BasicCookieStore(); while (itr.hasNext()) { Cookie cookie = itr.next(); BasicClientCookie bcco = new BasicClientCookie(cookie.getName(), cookie.getValue()); bcco.setDomain(cookie.getDomain()); bcco.setPath(cookie.getPath()); cookieStore.addCookie(bcco); } // ? ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(new File(savecookiepath))); oos.writeObject(cookieStore); oos.close(); }
From source file:edu.umd.cs.guitar.ripper.WebDriverTest.java
License:Open Source License
@Test public void testDriverBehaviors() { System.out.println("testDriverBehaviors"); FirefoxProfile profile = new FirefoxProfile(new File("/home/baonn/.mozilla/firefox")); profile.setPreference("network.http.phishy-userpass-length", 255); FirefoxDriver driver = new FirefoxDriver(profile); driver.get("https://www.google.com/analytics/web/"); }
From source file:org.ado.picasa.Main.java
License:Apache License
private static void loginIntoPicasa(String pin, FirefoxDriver driver) throws InterruptedException { driver.get("https://picasaweb.google.com"); driver.findElement(new By.ByName("Email")).sendKeys(System.getenv("GOOGLE_ACCOUNT"), Keys.ENTER); TimeUnit.SECONDS.sleep(1);// w w w. ja va 2 s. c o m driver.findElement(new By.ByName("Passwd")).sendKeys(System.getenv("GOOGLE_PASSWORD"), Keys.ENTER); TimeUnit.SECONDS.sleep(1); if (StringUtils.isNotBlank(pin)) { driver.findElement(new By.ByName("Pin")).sendKeys(pin, Keys.ENTER); TimeUnit.SECONDS.sleep(1); } }
From source file:org.richfaces.tests.archetypes.kitchensink.ftest.mobile.TestForm.java
License:Open Source License
@Test public void testPushFromDesktopToMobile() { FirefoxDriver firefoxDriver = new FirefoxDriver(); String url = getDeployedURL().toExternalForm().replace(ANDORID_LOOPBACK, "localhost") .concat(DESKTOP_MOBILE_NEW_MEMEBER); // opening mobile version of kitchensink on desktop browser as it is not possible to open two browsers on mobile device // or open two emulators firefoxDriver.get(url); FieldDecorator fd = new StaleReferenceAwareFieldDecorator(new DefaultElementLocatorFactory(firefoxDriver), 2);//from w w w.j a v a2 s .c o m RegisterForm registerFormDesktop = new RegisterForm(); PageFactory.initElements(fd, registerFormDesktop); menuPage.gotoListMembersPage(); registerFormDesktop.setCorrectName(); String emailToSet = "pushtomobile@ff.sf"; registerFormDesktop.setEmail(emailToSet); registerFormDesktop.setCorrectPhone(); registerFormDesktop.clickOnRegisterButton(); menuPage.waitFor(MenuPage.PAGE_TRANSITION_WAIT); String tableText = membersTable.getTable().getText(); assertTrue(tableText.contains(emailToSet), "Registration of new member desktop mobile version was not pushed to the mobile device!"); firefoxDriver.close(); }
From source file:org.richfaces.tests.archetypes.kitchensink.ftest.mobile.TestForm.java
License:Open Source License
@Test public void testPushFromMobileToDesktop() { FirefoxDriver firefoxDriver = new FirefoxDriver(); String url = getDeployedURL().toExternalForm().replace(ANDORID_LOOPBACK, "localhost") .concat(DESKTOP_MOBILE_LIST_MEMBERS); // opening mobile version of kitchensink on desktop browser as it is not possible to open two browsers on mobile device // or open two emulators firefoxDriver.get(url); FieldDecorator fd = new StaleReferenceAwareFieldDecorator(new DefaultElementLocatorFactory(firefoxDriver), 2);//from ww w . j av a 2 s. c o m MembersTable membersTableDesktop = new MembersTable(); PageFactory.initElements(fd, membersTableDesktop); menuPage.gotoAddMemberPage(); registerForm.setCorrectName(); String emailToSet = "pushfromdesktop@pushik.cz"; registerForm.setEmail(emailToSet); registerForm.setCorrectPhone(); registerForm.clickOnRegisterButton(); menuPage.waitFor(MenuPage.PAGE_TRANSITION_WAIT); String tableText = membersTableDesktop.getTable().getText(); assertTrue(tableText.contains(emailToSet), "Registration of new member on mobile device was not pushed to the desktop mobile version!"); firefoxDriver.close(); }
From source file:plugins.KerberosSsoTest.java
License:Open Source License
private void verifyTicketAuth(KerberosContainer kdc) throws IOException, InterruptedException { // Get TGT//from w w w .ja va 2 s.c o m String tokenCache = kdc.getClientTokenCache(); // Correctly negotiate in browser FirefoxDriver negotiatingDriver = getNegotiatingFirefox(kdc, tokenCache); negotiatingDriver.get(jenkins.url("/whoAmI").toExternalForm()); String out = negotiatingDriver.getPageSource(); assertThat(out, containsString(AUTHORIZED)); // Non-negotiating request should fail assertUnauthenticatedRequestIsRejected(getBadassHttpClient()); }
From source file:plugins.KerberosSsoTest.java
License:Open Source License
@Test public void explicitTicketAuth() throws Exception { setupRealmUser();//from w w w . j a v a2s. c o m KerberosContainer kdc = startKdc(); configureSso(kdc, true, true); String tokenCache = kdc.getClientTokenCache(); FirefoxDriver nego = getNegotiatingFirefox(kdc, tokenCache); nego.get(jenkins.url("/whoAmI").toExternalForm()); assertThat(nego.getPageSource(), not(containsString(AUTHORIZED))); nego.get(jenkins.url("/login").toExternalForm()); nego.get(jenkins.url("/whoAmI").toExternalForm()); assertThat(nego.getPageSource(), containsString(AUTHORIZED)); }
From source file:ru.tanyasun.delightex.ft.SeleniumUtils.java
License:Open Source License
public static WebDriver getFirefoxBrowser() { ResourceBundle bundle = ResourceBundle.getBundle(CHAT_PROPERTIES); String url = bundle.getString("chat.url"); FirefoxDriver driver = new FirefoxDriver(); driver.get(url); return driver; }
From source file:sf.wicklet.ext.test.arquillian.Test01.java
License:Apache License
@Test public void test01(@ArquillianResource final URL httpContext) throws Exception { final StepWatch timer = new StepWatch(true); final FirefoxProfile profile = new FirefoxProfile(new File("../opt/firefox/7x16slsr.default")); profile.setPreference("network.dns.disableIPv6", true); final FirefoxDriver driver = new FirefoxDriver(profile); try {// ww w. j ava 2 s. c o m if (Test01.DEBUG.isDebug()) { System.out.println(timer.toString("# Client start")); } driver.get(new URL(httpContext, TestAccordion01Page.MNT_PATH).toString()); final String title = driver.getTitle(); if (Test01.DEBUG.isDebug()) { System.out.println(timer.toString("Page title is: " + title)); System.out.println(driver.getPageSource()); } Assert.assertEquals("Test", driver.getTitle()); final List<WebElement> p1 = driver.findElementsByLinkText("Panel1"); final List<WebElement> p2 = driver.findElementsByLinkText("Panel2"); final List<WebElement> p3 = driver.findElementsByLinkText("Panel3"); final List<WebElement> c1 = driver.findElementsById("content1"); final List<WebElement> c2 = driver.findElementsById("content2"); final List<WebElement> c3 = driver.findElementsById("content3"); Assert.assertEquals(1, p1.size()); Assert.assertEquals(1, p2.size()); Assert.assertEquals(1, p3.size()); Assert.assertEquals(1, c1.size()); Assert.assertEquals(1, c2.size()); Assert.assertEquals(1, c3.size()); Assert.assertEquals("", c2.get(0).getAttribute("style")); // p2.get(0).click(); if (Test01.DEBUG.isDebug()) { System.out.println(driver.getPageSource()); } final List<WebElement> cc1 = driver.findElementsById("content1"); final List<WebElement> cc2 = driver.findElementsById("content2"); final List<WebElement> cc3 = driver.findElementsById("content3"); Assert.assertEquals(1, cc1.size()); Assert.assertEquals(1, cc2.size()); Assert.assertEquals(1, cc3.size()); Assert.assertEquals("display: none;", cc2.get(0).getAttribute("style")); // p2.get(0).click(); if (Test01.DEBUG.isDebug()) { System.out.println(driver.getPageSource()); } final List<WebElement> ccc2 = driver.findElementsById("content2"); Assert.assertEquals(1, ccc2.size()); Assert.assertEquals("display: block;", ccc2.get(0).getAttribute("style")); } finally { if (Test01.DEBUG.isDebug()) { final String text = driver.getPageSource(); FileUtil.writeFile(Test01.test01Html, false, text); SeleniumTestUtil.takeScreenshot(driver, Test01.test01Png); System.out.println(timer.toString("# Client done")); } if (Test01.DEBUG.isDebugServer()) { System.in.read(); } else { driver.quit(); } } }