Пример #1
0
  public static void extractnews(String symbol, String path)
      throws InterruptedException, IOException {
    // WebDriver driver = new HtmlUnitDriver();
    WebDriver driver = new FirefoxDriver();

    driver.get("http://www.otcmarkets.com/stock/" + symbol + "/insider-transactions");

    Thread.sleep(3000);

    boolean next = true;
    int count = -1;

    while (next) {
      next = false;
      count++;

      // grab the whole page and the link

      File file = new File(path + driver.getCurrentUrl().replaceAll("/", "_") + '_' + count);
      if (!file.exists()) {
        file.createNewFile();
      }
      FileWriter fw = new FileWriter(file);
      fw.write(driver.getPageSource());
      fw.flush();
      fw.close();

      System.out.println(driver.getCurrentUrl() + '/' + count);
      // System.out.println(driver.getPageSource());

      // check for the next button, if found then click set the flag to true
      WebElement pagination = null;
      try {
        pagination =
            driver.findElement(By.id("shortInterestTable")).findElement(By.className("pageList"));
      } catch (Exception e) {
        continue;
      }
      List<WebElement> paginationli = pagination.findElements(By.tagName("li"));

      for (WebElement ele : paginationli) {

        try {
          ele.findElement(By.tagName("a")).getText();
        } catch (Exception e) {
          continue;
        }

        if (ele.findElement(By.tagName("a")).getText().equals("next >")) {
          // System.out.println("HI");
          WebElement nextpage = ele.findElement(By.tagName("a"));
          nextpage.click();
          next = true;
          Thread.sleep(3000);
        }
      }
    }

    driver.quit();
  }
Пример #2
0
  @Test
  public void testRedirectSignedLoginLogoutFront() {
    // visit 1st app an logg in
    System.out.println("visit 1st app ");
    driver.navigate().to("http://localhost:8081/employee-sig/");
    assertAtLoginPageRedirectBinding();
    System.out.println("login to form");
    loginPage.login("bburke", "password");
    Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee-sig/");
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // visit 2nd app
    System.out.println("visit 2nd app ");
    driver.navigate().to("http://localhost:8081/employee-sig-front/");
    Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee-sig-front/");
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // visit 3rd app
    System.out.println("visit 3rd app ");
    driver.navigate().to("http://localhost:8081/sales-post-sig/");
    Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-sig/");
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // logout of first app
    System.out.println("GLO");
    driver.navigate().to("http://localhost:8081/employee-sig?GLO=true");
    checkLoggedOut("http://localhost:8081/employee-sig/", false);
    driver.navigate().to("http://localhost:8081/employee-sig-front/");
    assertAtLoginPageRedirectBinding();
    driver.navigate().to("http://localhost:8081/sales-post-sig/");
    assertAtLoginPagePostBinding();
  }
  public void testRedirectSignedLoginLogoutFront() {
    // visit 1st app an logg in
    System.out.println("visit 1st app ");
    driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig/");
    assertAtLoginPageRedirectBinding();
    System.out.println("login to form");
    loginPage.login("bburke", "password");
    assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee-sig/");
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // visit 2nd app
    System.out.println("visit 2nd app ");
    driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front/");
    assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee-sig-front/");
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // visit 3rd app
    System.out.println("visit 3rd app ");
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig/");
    assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-sig/");
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // logout of first app
    System.out.println("GLO");
    driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig?GLO=true");
    checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig/", false);
    driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front/");
    String currentUrl = driver.getCurrentUrl();
    Assert.assertTrue(currentUrl.startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml"));
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig/");
    assertAtLoginPagePostBinding();
  }
  public void testPostPassiveLoginLogout(boolean forbiddenIfNotauthenticated) {
    // first request on passive app - no login page shown, user not logged in as we are in passive
    // mode.
    // Shown page depends on used authentication mechanism, some may return forbidden error, some
    // return requested page with anonymous user (not logged in)
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-passive/");
    assertEquals(APP_SERVER_BASE_URL + "/sales-post-passive/saml", driver.getCurrentUrl());
    System.out.println(driver.getPageSource());
    if (forbiddenIfNotauthenticated) {
      Assert.assertTrue(driver.getPageSource().contains("HTTP status code: 403"));
    } else {
      Assert.assertTrue(driver.getPageSource().contains("principal=null"));
    }

    // login user by asking login from other app
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post/");
    loginPage.login("bburke", "password");

    // navigate to the passive app again, we have to be logged in now
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-passive/");
    assertEquals(APP_SERVER_BASE_URL + "/sales-post-passive/", driver.getCurrentUrl());
    System.out.println(driver.getPageSource());
    Assert.assertTrue(driver.getPageSource().contains("bburke"));

    // logout from both app
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-passive?GLO=true");
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post?GLO=true");

    // refresh passive app page, not logged in again as we are in passive mode
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-passive/");
    assertEquals(APP_SERVER_BASE_URL + "/sales-post-passive/saml", driver.getCurrentUrl());
    Assert.assertFalse(driver.getPageSource().contains("bburke"));
  }
Пример #5
0
  @Test
  public void tagRSS_ie() throws InterruptedException {
    driver.get(
        "https://"
            + Constants.Alertname
            + ":"
            + Constants.Alertpass
            + "@www-qa.petfinder.com/user/login/");
    Thread.sleep(3000);
    Login page = new Login(driver);
    page.logIn();
    Thread.sleep(3000);
    driver.get(sURL);
    String URL = driver.getCurrentUrl();
    try {
      Assert.assertEquals(URL, sURL);
    } catch (Throwable t) {
      driver.get(sURL);
    }

    Thread.sleep(1320000);
    String newURL = driver.getCurrentUrl();
    try {
      Assert.assertEquals(newURL, eURL);
      System.out.println("Right page for...");
      System.out.println(sURL);
      System.out.println("Page redirected to " + newURL);
      System.out.println("");
    } catch (Throwable t) {
      System.out.println("Wrong page for...");
      System.out.println(sURL);
      System.out.println("Page redirected to " + newURL);
      System.out.println("");
    }
  }
 public void testPostBadClientSignature() {
   driver.navigate().to(APP_SERVER_BASE_URL + "/bad-client-sales-post-sig/");
   System.out.println(driver.getCurrentUrl());
   Assert.assertTrue(
       driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml"));
   assertEquals(driver.getTitle(), "We're sorry...");
 }
  public DeviceAllocatedPage(final WebDriver driver) {
    this.driver = driver;

    if (!driver.getCurrentUrl().endsWith("/allocateDevice.htm")
        || !driver.getTitle().equals("HafTrust Allocate Mobile Device - Confirmation Page")) {
      throw new IllegalStateException("Incorrect page " + driver.getCurrentUrl());
    }
  }
Пример #8
0
 public void testPostSimpleUnauthorized(CheckAuthError error) {
   driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post/");
   assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml");
   loginPage.login("unauthorized", "password");
   assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post/");
   System.out.println(driver.getPageSource());
   error.check(driver);
 }
Пример #9
0
 @Test
 public void testPostBadRealmSignature() {
   driver.navigate().to("http://localhost:8081/bad-realm-sales-post-sig/");
   Assert.assertEquals(
       driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml");
   loginPage.login("bburke", "password");
   Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/bad-realm-sales-post-sig/");
   Assert.assertTrue(driver.getPageSource().contains("null"));
 }
 public ConfirmationPage(final WebDriver driver) {
   if (!driver.getCurrentUrl().endsWith("registerVerifier.htm")
       || !driver
           .findElement(By.cssSelector("body p"))
           .getText()
           .equals("Registration of the Verifier Candidate has been successful")) {
     throw new IllegalStateException("Incorrect page " + driver.getCurrentUrl());
   }
 }
Пример #11
0
 public void testPostEncryptedLoginLogout() {
   driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-enc/");
   assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml");
   loginPage.login("bburke", "password");
   assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-enc/");
   Assert.assertTrue(driver.getPageSource().contains("bburke"));
   driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-enc?GLO=true");
   checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-enc/");
 }
Пример #12
0
 protected void checkLoggedOut(String mainUrl) {
   String pageSource = driver.getPageSource();
   System.out.println("*** logout pagesource ***");
   System.out.println(pageSource);
   System.out.println("driver url: " + driver.getCurrentUrl());
   Assert.assertTrue(pageSource.contains("request-path: /logout.jsp"));
   driver.navigate().to(mainUrl);
   Assert.assertTrue(
       driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml"));
 }
Пример #13
0
 public void testRedirectSignedLoginLogoutFrontNoSSO() {
   driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front/");
   Assert.assertTrue(
       driver.getCurrentUrl().startsWith(AUTH_SERVER_URL + "/realms/demo/protocol/saml"));
   loginPage.login("bburke", "password");
   assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee-sig-front/");
   Assert.assertTrue(driver.getPageSource().contains("bburke"));
   driver.navigate().to(APP_SERVER_BASE_URL + "/employee-sig-front?GLO=true");
   checkLoggedOut(APP_SERVER_BASE_URL + "/employee-sig-front/");
 }
Пример #14
0
 public void testPostSignedLoginLogoutEmailNameID() {
   driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-email/");
   assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml");
   loginPage.login("bburke", "password");
   assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-post-sig-email/");
   System.out.println(driver.getPageSource());
   Assert.assertTrue(driver.getPageSource().contains("[email protected]"));
   driver.navigate().to(APP_SERVER_BASE_URL + "/sales-post-sig-email?GLO=true");
   checkLoggedOut(APP_SERVER_BASE_URL + "/sales-post-sig-email/");
 }
Пример #15
0
  public void testMetadataPostSignedLoginLogout() throws Exception {

    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-metadata/");
    assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml");
    loginPage.login("bburke", "password");
    assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/sales-metadata/");
    String pageSource = driver.getPageSource();
    Assert.assertTrue(pageSource.contains("bburke"));
    driver.navigate().to(APP_SERVER_BASE_URL + "/sales-metadata?GLO=true");
    checkLoggedOut(APP_SERVER_BASE_URL + "/sales-metadata/");
  }
Пример #16
0
 @Test
 public void testRedirectSignedLoginLogout() {
   driver.navigate().to("http://localhost:8081/employee-sig/");
   Assert.assertTrue(
       driver.getCurrentUrl().startsWith("http://localhost:8081/auth/realms/demo/protocol/saml"));
   loginPage.login("bburke", "password");
   Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/employee-sig/");
   Assert.assertTrue(driver.getPageSource().contains("bburke"));
   driver.navigate().to("http://localhost:8081/employee-sig?GLO=true");
   checkLoggedOut();
 }
Пример #17
0
 @Test
 public void testPostEncryptedLoginLogout() {
   driver.navigate().to("http://localhost:8081/sales-post-enc/");
   Assert.assertEquals(
       driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml");
   loginPage.login("bburke", "password");
   Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-post-enc/");
   Assert.assertTrue(driver.getPageSource().contains("bburke"));
   driver.navigate().to("http://localhost:8081/sales-post-enc?GLO=true");
   checkLoggedOut();
 }
Пример #18
0
 @Test
 public void testPostSignedLoginLogoutEmailNameID() {
   driver.navigate().to("http://*****:*****@redhat.com"));
   driver.navigate().to("http://localhost:8081/sales-post-sig-email?GLO=true");
   checkLoggedOut();
 }
Пример #19
0
 public void testPostBadRealmSignature() {
   ErrorServlet.authError = null;
   driver.navigate().to(APP_SERVER_BASE_URL + "/bad-realm-sales-post-sig/");
   assertEquals(driver.getCurrentUrl(), AUTH_SERVER_URL + "/realms/demo/protocol/saml");
   loginPage.login("bburke", "password");
   assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/bad-realm-sales-post-sig/");
   System.out.println(driver.getPageSource());
   Assert.assertNotNull(ErrorServlet.authError);
   SamlAuthenticationError error = (SamlAuthenticationError) ErrorServlet.authError;
   Assert.assertEquals(SamlAuthenticationError.Reason.INVALID_SIGNATURE, error.getReason());
   ErrorServlet.authError = null;
 }
Пример #20
0
  @Test
  public void testCloneDriver() {
    WebDriver newDriver = cloneDriver(driver, context);
    System.out.println("==================================");
    for (Cookie cookie : newDriver.manage().getCookies()) {
      System.out.println(cookie);
    }

    String link = "/memberaccount/memberaccount";
    goToLink(newDriver, link);

    assertTrue(newDriver.getCurrentUrl(), newDriver.getCurrentUrl().endsWith(link));
  }
Пример #21
0
  @Test
  public void testMetadataPostSignedLoginLogout() throws Exception {

    driver.navigate().to("http://localhost:8081/sales-metadata/");
    Assert.assertEquals(
        driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml");
    loginPage.login("bburke", "password");
    Assert.assertEquals(driver.getCurrentUrl(), "http://localhost:8081/sales-metadata/");
    String pageSource = driver.getPageSource();
    Assert.assertTrue(pageSource.contains("bburke"));
    driver.navigate().to("http://localhost:8081/sales-metadata?GLO=true");
    checkLoggedOut();
  }
Пример #22
0
 public void testRelayStateEncoding() throws Exception {
   // this test has a hardcoded SAMLRequest and we hack a SP face servlet to get the SAMLResponse
   // so we can look
   // at the relay state
   SamlSPFacade.samlResponse = null;
   driver.navigate().to(APP_SERVER_BASE_URL + "/employee/");
   assertAtLoginPageRedirectBinding();
   System.out.println(driver.getCurrentUrl());
   loginPage.login("bburke", "password");
   assertEquals(driver.getCurrentUrl(), APP_SERVER_BASE_URL + "/employee/");
   assertEquals(SamlSPFacade.sentRelayState, SamlSPFacade.RELAY_STATE);
   Assert.assertNotNull(SamlSPFacade.samlResponse);
 }
  @Test(
      priority = 1,
      groups = {"loginlogout"})
  public void LogoutAndSessionExpiresOnBackButtonClick()
      throws BiffException, IOException, InterruptedException {
    WebDriver d = getBrowser();
    loginLogout = PageFactory.initElements(d, LoginLogoutMethods.class);
    general =
        PageFactory.initElements(
            d,
            WebCommonMethods
                .class); // initiating the driver and the .class file (the pageObject script)

    WebCommonMethods.openURL();

    System.out.println("Checking for LogoutAndSessionExpiresOnBackButton test...");
    LoginLogoutMethods.login("admin");
    Thread.sleep(4000);
    LoginLogoutMethods.logout();

    // session expiry check
    d.navigate().back();
    // System.out.println("Current URL: " + d.getCurrentUrl());
    Assert.assertEquals(
        d.getCurrentUrl(),
        "http://localhost/orangehrm-3.1.2/orangehrm-3.1.2/symfony/web/index.php/pim/viewEmployeeList");

    Cell[] loginPageLabels =
        WebCommonMethods.readExcelNextRowOfUniqueValue("webTabsWithSubheading", "#loginPage");
    Assert.assertEquals(
        LoginLogoutMethods.loginPanelHeadingLabel.getText(), loginPageLabels[1].getContents());
  }
Пример #24
0
 /**
  * Workaround for Webdriver issue 1438 (http://code.google.com/p/selenium/issues/detail?id=1438)
  */
 private void ensureValidDriver() {
   try {
     proxiedWebDriver.getCurrentUrl();
   } catch (WebDriverException e) {
     proxiedWebDriver.switchTo().defaultContent();
   }
 }
Пример #25
0
 @Test
 public void testPostBadClientSignature() {
   driver.navigate().to("http://localhost:8081/bad-client-sales-post-sig/");
   Assert.assertEquals(
       driver.getCurrentUrl(), "http://localhost:8081/auth/realms/demo/protocol/saml");
   Assert.assertEquals(driver.getTitle(), "We're sorry...");
 }
Пример #26
0
  public void Test1() {
    WebDriver dr = new FirefoxDriver();
    dr.manage().timeouts().pageLoadTimeout(15, TimeUnit.SECONDS);

    try {
      dr.get("http://www.w3schools.com/xsl/xsl_functions.asp");
    } catch (Exception e) {
      // ignore page load time out
      // e.printStackTrace();
    }
    System.out.println(dr.getCurrentUrl());
    WebDriverWait wait = new WebDriverWait(dr, 10);
    wait.until(
        ExpectedConditions.visibilityOfElementLocated(
            By.xpath("//h3[contains(.,'Accessor Functions')]")));
    System.out.println("page loaded");
    WebElement eTable =
        dr.findElement(
            By.xpath("//h3[contains(.,'Accessor Functions')]/following-sibling::table[1]"));

    Table tTable = new Table(eTable);

    System.out.println(tTable.getCellText(1, 1)); // row 1, column 1
    System.out.println(tTable.getCellText("fn,nilled", 1)); // row 2, column 1
    System.out.println(tTable.getCellText(1, "Name")); // row 1, column 1
    System.out.println(tTable.getCellText("fn,nilled", "Description")); // row 2, column 2

    dr.quit();
  }
Пример #27
0
  @Test
  public void returnToAppFromQueryParam() {
    driver.navigate().to(AccountUpdateProfilePage.PATH + "?referrer=test-app");
    loginPage.login("test-user@localhost", "password");
    Assert.assertTrue(profilePage.isCurrent());
    profilePage.backToApplication();

    Assert.assertTrue(appPage.isCurrent());

    driver
        .navigate()
        .to(
            AccountUpdateProfilePage.PATH
                + "?referrer=test-app&referrer_uri=http://localhost:8081/app?test");
    Assert.assertTrue(profilePage.isCurrent());
    profilePage.backToApplication();

    Assert.assertTrue(appPage.isCurrent());
    Assert.assertEquals(appPage.baseUrl + "?test", driver.getCurrentUrl());

    driver.navigate().to(AccountUpdateProfilePage.PATH + "?referrer=test-app");
    Assert.assertTrue(profilePage.isCurrent());

    driver.findElement(By.linkText("Authenticator")).click();
    Assert.assertTrue(totpPage.isCurrent());

    driver.findElement(By.linkText("Account")).click();
    Assert.assertTrue(profilePage.isCurrent());

    profilePage.backToApplication();

    Assert.assertTrue(appPage.isCurrent());

    events.clear();
  }
Пример #28
0
  @Test
  public void maintest() throws Exception {
    for (int i = 1; i < xRows; i++) {
      sUrl = xData[i][0];
      sExecute = xData[i][5];
      sResult = "Pass";
      sErrorMsg = "No Error";
      if (sExecute.equalsIgnoreCase("y")) {

        driver.get(sUrl);
        Thread.sleep(3000);
        String stitle = driver.getTitle();
        String sURL = driver.getCurrentUrl(); // sTitle,	sElement,sResult,sErrorMsg
        sTitle = xData[i][1];
        sElement = xData[i][2];
      }
      /*xData[i][1] = sTitle;
      xData[i][2] = sElement;*/

      /*String sError = e.getMessage();
      sErrorMsg = sError;
      sResult = "Fail";	*/

      sResult = xData[i][3];
      sErrorMsg = xData[i][4];
    }
  }
 /**
  * This method returns the current url of the browser
  *
  * @return returns current url
  */
 public String getCurrentUrl() {
   try {
     return _driver.getCurrentUrl();
   } catch (Exception e) {
     e.printStackTrace();
     return null;
   }
 }
  @Test(expected = WrongPageError.class)
  public void
      the_pages_object_throws_a_wrong_page_error_when_the_page_object_doesnt_have_a_webdriver_constructor() {

    when(driver.getCurrentUrl()).thenReturn("http://www.google.com");
    final Pages pages = new Pages(driver, configuration);
    pages.currentPageAt(PageObjectWithNoDriverConstructor.class);
  }