예제 #1
0
  @Ignore
  @Test
  public void TestCase_002() throws Exception {

    LogGenerator.addLog(Level.INFO, "Starting Test Case_002");

    driver.get("http://www.google.com");
    String name = (new Exception().getStackTrace()[0].getMethodName());
    CaptureScreenshot.takeScreenshot(driver, name);

    // Find the text input element by its name
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("Junit");
    element.submit();

    synchronized (driver) {
      driver.wait(12000);
    }

    LogGenerator.addLog(Level.INFO, "my info message in test case 002");

    CaptureScreenshot.takeScreenshot(driver, name);
    // assertEquals("junit - Google Search", driver.getTitle());

    LogGenerator.addLog(Level.INFO, "Completing Test Case_002");
  }
예제 #2
0
  @Test
  public void testLogin() {
    driver.get(appUrl + "/#/login");

    WebDriverWait wait = new WebDriverWait(driver, 10);

    WebElement user =
        wait.until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector("input[type=\"text\"]")));
    user.sendKeys("demo");

    WebElement password =
        wait.until(
            ExpectedConditions.presenceOfElementLocated(
                By.cssSelector("input[type=\"password\"]")));
    password.sendKeys("demo");

    WebElement submit =
        wait.until(
            ExpectedConditions.presenceOfElementLocated(By.cssSelector("button[type=\"submit\"]")));
    submit.submit();

    boolean found =
        wait.until(
            ExpectedConditions.textToBePresentInElement(By.cssSelector("td"), "Assign Approver"));
  }
 @BeforeClass
 public static void setUpBeforeClass() throws Exception {
   Settings.init();
   WebElement chooseFile = Settings.driver.findElement(By.id("chooseFile"));
   chooseFile.sendKeys(UIUtils.pathUI + "plan.xml");
   chooseFile.submit();
 }
  @Test
  public void testGoogleTitle() throws Exception {
    WebDriver driver = new FirefoxDriver();
    driver.get("http://www.google.com");
    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("Cheese!");
    element.submit();
    System.out.println("Page title is: " + driver.getTitle());

    String expected = "Google";
    String actual = driver.getTitle();
    Assert.assertEquals(actual, expected);

    (new WebDriverWait(driver, 10))
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
              }
            });

    System.out.println("Page title is: " + driver.getTitle());

    expected = "Cheese! - Google Search";
    actual = driver.getTitle();
    Assert.assertEquals(actual, expected);

    driver.quit();
  }
 public static void main(String[] args) {
   WebDriver driver = new FirefoxDriver();
   driver.get("http://www.google.com");
   WebElement searchBox = driver.findElement(By.className("gsfi"));
   searchBox.sendKeys("Packt Publishing");
   searchBox.submit();
 }
예제 #6
0
  private void accept(WebDriver driver, String message) {
    StopWatch stopWatch = new Log4JStopWatch();
    stopWatch.start();

    WebElement img = driver.findElement(By.xpath("//img[@alt='Click to sign']"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
    img.click();

    List<WebElement> signed_imgs = driver.findElements(By.xpath("//img[@alt='Signed']"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);

    if (signed_imgs.size() != 0) {
      stopWatch.stop("accept", message);
    } else {
      randomDelay();
      stopWatch.start();
      WebElement awsForm = driver.findElement(By.name("awsForm"));

      driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
      awsForm.submit();

      signed_imgs = driver.findElements(By.xpath("//img[@alt='Signed']"));
      driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
      stopWatch.stop("accept'", message);
    }
  }
  private void executeLogin(String email, String userid, String pseudonym) {

    EmailField.sendKeys(email);
    UserIdField.sendKeys(userid);
    PseudonymField.sendKeys(pseudonym);
    SubmitBtn.submit();
    System.out.println("debug: credentials SENT");
  }
예제 #8
0
파일: Testii.java 프로젝트: rase-/wad
 /** @param args the command line arguments */
 public static void main(String[] args) {
   WebDriver driver = new HtmlUnitDriver();
   driver.get("http://t-avihavai.users.cs.helsinki.fi/lets/Chat");
   WebElement element = driver.findElement(By.name("tunnus"));
   element.sendKeys("tunnus");
   element.submit();
   System.out.println(driver.getPageSource());
 }
예제 #9
0
 /** This method is to click on the submit button */
 public void submit() throws Exception {
   log.info("ENTERING SUBMIT OPERATION");
   try {
     element.submit();
   } catch (Throwable t) {
     log.info("THROWABLE EXCEPTION IN SUBMIT" + t.getMessage());
   }
 }
예제 #10
0
 /**
  * @param username
  * @param password
  * @throws TimeoutException
  * @throws NoSuchElementException
  */
 public void login(String username, String password)
     throws NoSuchElementException, TimeoutException {
   //		WebElement userName_editbox = driver.findElement(By.name("loginName"));
   WebElement userName_editbox = fluentWait(By.name("loginName"));
   WebElement password_editbox = driver.findElement(By.name("password"));
   userName_editbox.sendKeys(username);
   password_editbox.sendKeys(password);
   password_editbox.submit();
 }
예제 #11
0
  public void loginWithCredentials(String username, String password) {
    final WebElement usernameField = driver.findElement(By.name("username"));
    final WebElement passwordField = driver.findElement(By.name("password"));
    final WebElement loginForm = driver.findElement(By.tagName("form"));

    usernameField.sendKeys(username);
    passwordField.sendKeys(password);
    loginForm.submit();
  }
예제 #12
0
  public void logout() {
    // TODO: check than we not authenticated and do nothing

    WebElement logoutButton = getElementByXPath(LOGOUT_BUTTON_LOCATOR);
    logoutButton.submit();

    // return to current page
    open();
    // TODO: test for presence link with text "Sign in" to ensure than all right?
  }
 // UTILITIES //
 // Attempts to login with user name and password.
 // Returns true is successful and false if not.
 private boolean login() {
   driver.findElement(By.linkText("login")).click();
   WebElement usernameBox =
       wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("UserName")));
   usernameBox.sendKeys(username);
   WebElement passwordBox = driver.findElement(By.id("Password"));
   passwordBox.sendKeys(password);
   passwordBox.submit();
   return isElementPresent(By.linkText("cs1632"));
 }
예제 #14
0
 public HomePage loginAs(String username, String password) throws IOException {
   testWebDriver.waitForElementToAppear(userNameField);
   testWebDriver.waitForElementToAppear(passwordField);
   userNameField.clear();
   userNameField.sendKeys(username);
   passwordField.sendKeys(password);
   testWebDriver.sleep(500);
   userNameField.submit();
   return new HomePage(testWebDriver);
 }
예제 #15
0
  public void preenche(String login, String senha) {

    WebElement txtLogin = driver.findElement(By.id("login_field"));
    WebElement txtSenha = driver.findElement(By.id("password"));

    txtLogin.sendKeys(login);
    txtSenha.sendKeys(senha);

    txtLogin.submit();
  }
예제 #16
0
  private void submit(WebDriver driver) {
    WebElement submitButton = driver.findElement(By.name("button"));
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);

    submitButton.click();

    WebElement awsForm = driver.findElement(By.name("awsForm"));
    //		System.out.println(awsForm.toString());
    driver.manage().timeouts().implicitlyWait(waitTimeout, TimeUnit.SECONDS);
    awsForm.submit();
  }
  public void login(String username, String password) {
    driver.navigate().to(getLoginPageUrl(siteUrl));
    WebElement usernameInput = driver.findElement(By.id(getUsernameFieldId()));
    usernameInput.sendKeys(username);

    WebElement passwordInput = driver.findElement(By.id(getPasswordFieldId()));
    passwordInput.sendKeys(password);

    WebElement submitButton = driver.findElement(By.id(getSubmitButtonId()));
    submitButton.submit();
  }
예제 #18
0
  public void login(User user) {
    driver.get("https://www.academicwork.se/login");

    WebElement emailField = driver.findElement(By.id("LoginViewModel_LoginName"));
    WebElement passwordField = driver.findElement(By.id("LoginViewModel_Password"));

    emailField.sendKeys(user.email);
    passwordField.sendKeys(user.password);
    emailField.submit();

    new WebDriverWait(driver, 5).until(ExpectedConditions.urlContains("my-profile"));
  }
예제 #19
0
파일: Bot.java 프로젝트: byde/dogame
  public void login() {
    // loginBtn
    WebElement btn_entrar = driver.findElement(By.id("loginBtn"));
    btn_entrar.click();
    try {
      (new WebDriverWait(driver, 30))
          .until(
              new ExpectedCondition<Boolean>() {

                public Boolean apply(WebDriver d) {
                  return d.findElement(By.id("loginSubmit")).isDisplayed();
                }
              });
    } catch (Exception e) {
      consola("Error: Login: "******"usernameLogin"));
    WebElement txt_pass = driver.findElement(By.id("passwordLogin"));
    WebElement btn_subm = driver.findElement(By.id("loginSubmit"));
    // WebElement opt_univ = new Select(driver.findElement(By.id("serverLogin")));
    Select opt_univ = new Select(driver.findElement(By.id("serverLogin")));

    // Enter something to search for passwordLogin
    // inputUsername.sendKeys("ulises");
    txt_user.sendKeys(Model.Config.getUsuario());
    txt_pass.sendKeys(Model.Config.getPass());
    opt_univ.selectByValue("uni106.ogame.com.es");

    // Now submit the form. WebDriver will Botfind the form for us from the element
    btn_subm.submit();

    // Check the title of the page
    // System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    try {
      (new WebDriverWait(driver, 30))
          .until(
              new ExpectedCondition<Boolean>() {

                public Boolean apply(WebDriver d) {
                  return d.getTitle().startsWith("Fornax");
                }
              });
      driver.switchTo().defaultContent();
      consola("Log: Login: Ingreso correctamente");
    } catch (Exception e) {
      consola("Error: Login: " + e.getMessage());
    }
  }
예제 #20
0
  @Test
  public void deve_buscar_no_google() throws Exception {
    driver = new HtmlUnitDriver();

    driver.get("http://www.google.com");

    WebElement element = driver.findElement(By.name("q"));
    element.sendKeys("high tech cursos");

    element.submit();

    assertEquals("high tech cursos - Pesquisa Google", driver.getTitle());
  }
예제 #21
0
  public void edit(User user) {

    driver.get("https://www.academicwork.se/my-profile");

    WebElement partTime = driver.findElement(By.id("t1"));
    WebElement fullTime = driver.findElement(By.id("t2"));
    WebElement consultant = driver.findElement(By.id("t3"));
    WebElement recruitment = driver.findElement(By.id("t4"));

    WebElement jobOptionList =
        driver.findElement(
            By.xpath("//form[@id='create-subscription-form']/fieldset/div[3]/div[1]/div[2]/ul"));
    List<WebElement> allJobOptions = jobOptionList.findElements(By.className("filter"));

    if (!user.jobOptions[0]) {
      partTime.click();
    }
    if (!user.jobOptions[1]) {
      fullTime.click();
    }
    if (!user.jobOptions[2]) {
      consultant.click();
    }
    if (!user.jobOptions[3]) {
      recruitment.click();
    }

    int i = 0;
    for (boolean j : user.jobs) {
      if (j) {
        allJobOptions.get(jobs[i]).click();
      }
      i++;
    }

    WebElement locationOptionList =
        driver.findElement(
            By.xpath("//form[@id='create-subscription-form']/fieldset/div[4]/div[1]/div[2]/ul"));
    List<WebElement> allLocationOptions = locationOptionList.findElements(By.className("filter"));

    i = 0;
    for (boolean j : user.locations) {
      if (j) {
        allLocationOptions.get(locations[i]).click();
      }
      i++;
    }
    partTime.submit();
    user.isDone = true;
  }
예제 #22
0
  @Test
  public void test() {
    long startTime = System.nanoTime();
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface,
    // not the implementation.
    WebDriver driver = new FirefoxDriver();

    // And now use this to visit Google
    driver.get("http://www.google.com");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.google.com");

    // Find the text input element by its name
    // WebElement element = driver.findElement(By.name("q"));
    WebElement element = driver.findElement(By.cssSelector("[name=q]"));
    // JavascriptExecutor js = (JavascriptExecutor) driver;

    // WebElement element = (WebElement) js.executeScript("return
    // document.getElementsByName('q')[0]");

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the
    // element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());

    // Google's search is rendered dynamically with JavaScript.
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10))
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!");
              }
            });

    // Should see: "cheese! - Google Search"
    System.out.println("Page title is: " + driver.getTitle());

    // Close the browser
    driver.quit();
    long endTime = System.nanoTime();
    System.out.println("Took " + (endTime - startTime) + " ns");
  }
  // Given that a user is logging in
  // And the user does not provide a correct username and password,
  // When the user submits his/her login credentials,
  // Then a message will display noting the incorrect credentials.
  @Test
  public void testIncorrectLogin() {
    Random r = new Random();

    driver.findElement(By.linkText("login")).click();
    WebElement usernameBox =
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("UserName")));
    usernameBox.sendKeys("invalid" + r.nextInt(10000));
    WebElement passwordBox = driver.findElement(By.id("Password"));
    passwordBox.sendKeys("notavalidpassword");
    passwordBox.submit();

    String error = driver.findElement(By.cssSelector("div.validation-summary-errors")).getText();
    assertEquals("Invalid username or password.", error);
  }
예제 #24
0
 @Test
 public void googleForCheeseTest() {
   final FirefoxDriver driver = new FirefoxDriver();
   driver.get("http://www.google.com/");
   final WebElement element = driver.findElement(By.name("q"));
   element.sendKeys("Cheese!");
   element.submit();
   System.out.println("Page title is: " + driver.getTitle());
   (new WebDriverWait(driver, 10))
       .until(
           (WebDriver d) -> {
             return d.getTitle().toLowerCase().startsWith("cheese!");
           });
   System.out.println("Page title is: " + driver.getTitle());
   driver.quit();
 }
  @Test // Not applicable for Liferay Portal 6.0
  @RunAsClient
  @InSequence(0)
  public void testSetupActivateUser() throws Exception {
    browser.manage().window().maximize();
    signIn(browser);
    (new Actions(browser)).click(dropdownTestSetup);

    if (!controlPanelTestSetup.isDisplayed()) {
      dropdownTestSetup.click();
    }

    controlPanelTestSetup.click();
    waitForElement(browser, usersLinkTestSetupXpath);
    usersLinkTestSetup.click();
    waitForElement(browser, searchAllUsersLinkTestSetupXpath);

    if (!isThere(browser, johnAdamsTestSetupXpath) || !johnAdamsTestSetup.isDisplayed()) {

      searchAllUsersLinkTestSetup.click();
      waitForElement(browser, backLinkTestSetupXpath);

      if (isThere(browser, advancedSearchLinkTestSetupXpath)
          && advancedSearchLinkTestSetup.isDisplayed()) {
        advancedSearchLinkTestSetup.click();
      }

      waitForElement(browser, selectStatusTestSetupXpath);
      selectStatusTestSetup.click();
      (new Actions(browser)).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.TAB).perform();
      Thread.sleep(250);

      if (isThere(browser, johnAdamsTestSetupXpath)) {
        // no-op
      } else {
        selectStatusTestSetup.submit();
        Thread.sleep(250);
      }

      if (isThere(browser, johnAdamsTestSetupXpath)) {
        johnAdamsMenuTestSetup.click();
        activateJohnAdamsTestSetup.click();
      }

      waitForElement(browser, usersLinkTestSetupXpath);
    }
  }
예제 #26
0
  /**
   * Test the login for admin user and that they have SysAd role
   *
   * @throws Exception
   */
  public void testLogin() throws Exception {
    this.driver.get("http://localhost:8080/CallFailureEnterprise");

    WebElement username = driver.findElement(By.name("username"));
    WebElement password = driver.findElement(By.name("password"));

    username.sendKeys("admin");
    password.sendKeys("admin");

    username.submit();

    driver.get("http://localhost:8080/CallFailureEnterprise/rest/users/currentUser");

    String user = driver.getPageSource();

    assert (user.contains("System Administrator"));
  }
예제 #27
0
  @Test
  public void SubmittingFormShouldFireOnSubmitForThatForm() {
    WebDriver d = getDriver();

    d.get("http://ci.seleniumhq.org:2310/common/javascriptPage.html");
    WebElement formElement = d.findElement(By.id("submitListeningForm"));
    formElement.submit();

    WebDriverWait wait = new WebDriverWait(d, 30);
    wait.until(ExpectedConditions.textToBePresentInElement(By.id("result"), "form-onsubmit"));

    WebElement result = d.findElement(By.id("result"));
    String text = result.getText();
    boolean conditionMet = text.contains("form-onsubmit");

    assertTrue(conditionMet);
  }
  @Test
  public void googleSearchTest() {
    // And now use this to visit Google
    webdriver.get("http://www.google.com");

    // Find the text input element by its name
    WebElement element = webdriver.findElement(By.name("q"));

    // Enter something to search for
    element.sendKeys("Cheese!");

    // Now submit the form. WebDriver will find the form for us from the element
    element.submit();

    // Check the title of the page
    System.out.println("Page title is: " + webdriver.getTitle());
  }
예제 #29
0
  public static long runTest(int port)
      throws MalformedURLException, IOException, InterruptedException {
    long totalTime;

    // Start the clock
    Date start = new Date();

    // Ask for a JavaScript-enabled browser
    DesiredCapabilities capabilities = new DesiredCapabilities();
    capabilities.setJavascriptEnabled(true);

    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:" + port), capabilities);
    Capabilities actualCapabilities = ((RemoteWebDriver) driver).getCapabilities();

    // And now use this to visit Google
    System.out.println("Loading 'http://www.google.com'...");
    driver.get("http://www.google.com");
    System.out.println("Loaded. Current URL is: '" + driver.getCurrentUrl() + "'");

    // Find the text input element by its name
    System.out.println("Finding an Element via [name='q']...");
    WebElement element = driver.findElement(By.name("q"));
    System.out.println("Found.");

    // Enter something to search for
    System.out.println("Sending keys 'Cheese!...'");
    element.sendKeys("Cheese!");
    System.out.println("Sent.");

    // Now submit the form. WebDriver will find the form for us from the element
    System.out.println("Submitting Element...");
    element.submit();
    System.out.println("Submitted.");

    // Check the title of the page
    System.out.println("Page title is: " + driver.getTitle());
    driver.close();

    totalTime = new Date().getTime() - start.getTime();
    System.out.println("Time elapsed (ms): " + totalTime);

    return totalTime;
  }
예제 #30
0
파일: Tes.java 프로젝트: niifeehi/test
  public static void main(String[] args) throws Exception {

    DesiredCapabilities capabillities = DesiredCapabilities.firefox();
    capabillities.setCapability("version", "8");
    capabillities.setCapability("platform", Platform.WINDOWS);

    WebDriver driver =
        new RemoteWebDriver(
            new URL(
                "http://*****:*****@hub.testingbot.com:4444/wd/hub"),
            capabillities);

    driver.get("http://www.google.com");
    WebElement search = driver.findElement(By.name("q"));
    search.sendKeys("Hello, WebDriver");
    search.submit();
    System.out.println(driver.getTitle());
    driver.quit();
  }