Example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

List of usage examples for org.openqa.selenium.support.ui WebDriverWait WebDriverWait

Introduction

In this page you can find the example usage for org.openqa.selenium.support.ui WebDriverWait WebDriverWait.

Prototype

public WebDriverWait(WebDriver driver, Duration timeout) 

Source Link

Document

Wait will ignore instances of NotFoundException that are encountered (thrown) by default in the 'until' condition, and immediately propagate all others.

Usage

From source file:TestWithSelenium.java

@Test
public void xTestEdit() {
    //searching for tbody
    List<WebElement> tableRows = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));

    WebElement editButton = null;//from   w  ww . ja v  a  2  s  .  c o m
    for (int i = 0; i < tableRows.size(); i++) {
        if (tableRows.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            editButton = tableRows.get(i);
            break;
        }
    }

    editButton.findElements(By.tagName("td")).get(7).findElements(By.tagName("a")).get(0).click();
    WebElement element = driver.findElement(By.id("description"));
    element.clear();
    element.sendKeys("Cool car");
    driver.findElement(By.id("save")).click();

    //searching for new tbody
    List<WebElement> tableRowsUpdated = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<WebElement>) (WebDriver d) -> {
                return d.findElement(By.tagName("tbody"));
            }).findElements(By.tagName("tr"));

    String descriptionNew = "";
    for (int i = 0; i < tableRowsUpdated.size(); i++) {
        if (tableRowsUpdated.get(i).findElements(By.tagName("td")).get(0).getText().equalsIgnoreCase("938")) {
            descriptionNew = tableRowsUpdated.get(i).findElements(By.tagName("td")).get(5).getText();
            break;
        }
    }
    assertThat(descriptionNew, is("Cool car"));
}

From source file:TestWithSelenium.java

@Test
public void yTestError() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("save")).click();

    String submiterrMessage = (new WebDriverWait(driver, MAX))
            .until((ExpectedCondition<String>) (WebDriver d) -> {
                return d.findElement(By.id("submiterr")).getText();
            });//from w w w  .j  ava2s .  c om

    assertThat(submiterrMessage, is("All fields are required"));

}

From source file:TestWithSelenium.java

@Test
public void zAddNew() {
    driver.findElement(By.id("new")).click();
    driver.findElement(By.id("year")).sendKeys("2008");
    driver.findElement(By.id("registered")).sendKeys("2002-5-5");
    driver.findElement(By.id("make")).sendKeys("Kia");
    driver.findElement(By.id("model")).sendKeys("Rio");
    driver.findElement(By.id("description")).sendKeys("As new");
    driver.findElement(By.id("price")).sendKeys("31000");
    driver.findElement(By.id("save")).click();

    WebElement table = (new WebDriverWait(driver, MAX)).until((ExpectedCondition<WebElement>) (WebDriver d) -> {
        return d.findElement(By.tagName("tbody"));
    });/*from ww  w.jav  a2 s.c om*/
    Assert.assertThat(table.findElements(By.tagName("tr")).size(), is(6));

}

From source file:$.SimpleTest.java

License:Apache License

@Test
    public void testSimple() throws Exception {
        this.driver.get(this.serverUrl + "index.html");

        String whoToSend = "foo";

        WebElement who = this.driver.findElement(By.id("who"));
        who.sendKeys(whoToSend);/* ww w. j ava  2 s  .c o m*/

        WebElement sendBtn = this.driver.findElement(By.id("send-btn"));
        sendBtn.click();

        // wait 5 secs for ajax response
        new WebDriverWait(this.driver, 5)
                .until(ExpectedConditions.textToBePresentInElement(By.id("response"), whoToSend));

        WebElement response = this.driver.findElement(By.id("response"));
        String text = response.getText();

        Assert.assertEquals("Hello " + whoToSend, text);

    }

From source file:administrationedit.addCompany.java

public static void main(String[] args) {

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, 3);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    Random r = new Random();

    Faker faker = new Faker();

    driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/user/updateCompanySettings");

    adminLogin login = new adminLogin(driver);
    login.loginToAdmin("demo", "demo");

    // Input name
    String nameComp = faker.company().name();
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys(nameComp);

    // Input address
    String addressComp = faker.address().fullAddress();
    driver.findElement(By.id("address")).clear();
    driver.findElement(By.id("address")).sendKeys(addressComp);

    // Input city
    String cityComp = faker.address().city();
    driver.findElement(By.id("city")).clear();
    driver.findElement(By.id("city")).sendKeys(cityComp);

    // Input postal code
    String postalCodeComp = faker.address().zipCode();
    driver.findElement(By.id("postalCode")).clear();
    driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp);

    // Country// ww  w  .  ja  v  a2  s  .co  m
    Select countryComp = new Select(driver.findElement(By.id("country")));
    int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1;
    countryComp.selectByIndex(coutryCompInt);

    // Email
    String emailComp = faker.internet().emailAddress();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys(emailComp);

    // Phone
    String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("phone")).clear();
    driver.findElement(By.id("phone")).sendKeys(phoneComp);

    // Mobile
    String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", "");
    driver.findElement(By.id("mobilePhone")).clear();
    driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp);

    // Fax
    String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("fax")).clear();
    driver.findElement(By.id("fax")).sendKeys(faxComp);

    // OIB
    String oibComp = faker.idNumber().validSvSeSsn();
    driver.findElement(By.id("oib")).clear();
    driver.findElement(By.id("oib")).sendKeys(oibComp);

    // VatID
    String vatComp = faker.idNumber().validSvSeSsn();
    driver.findElement(By.id("vatId")).clear();
    driver.findElement(By.id("vatId")).sendKeys(vatComp);

    // Id code
    String idCodeComp = faker.idNumber().valid();
    driver.findElement(By.id("idCode")).clear();
    driver.findElement(By.id("idCode")).sendKeys(idCodeComp);

    // MBS
    String mbsComp = faker.number().digits(15);
    driver.findElement(By.id("mbs")).clear();
    driver.findElement(By.id("mbs")).sendKeys(mbsComp);

    // ID number
    String idNumComp = faker.number().digits(15);
    driver.findElement(By.id("identificationNumber")).clear();
    driver.findElement(By.id("identificationNumber")).sendKeys(idNumComp);

    // IBAN
    String ibanComp = faker.finance().iban();
    driver.findElement(By.id("iban")).clear();
    driver.findElement(By.id("iban")).sendKeys(ibanComp);

    // Swift 
    String swiftComp = faker.finance().bic();
    driver.findElement(By.id("swift")).clear();
    driver.findElement(By.id("swift")).sendKeys(swiftComp);

    //Bank name
    String bankNameComp = faker.name().name();
    driver.findElement(By.id("bankName")).clear();
    driver.findElement(By.id("bankName")).sendKeys(bankNameComp);

    // Bank address
    String bankAddressComp = faker.address().fullAddress();
    driver.findElement(By.id("bankAddress")).clear();
    driver.findElement(By.id("bankAddress")).sendKeys(bankAddressComp);

    // Bank city
    String bankCityComp = faker.address().city();
    driver.findElement(By.id("bankCity")).clear();
    driver.findElement(By.id("bankCity")).sendKeys(bankCityComp);

    // Bank postal code
    String bankPostalCodeComp = faker.address().zipCode();
    driver.findElement(By.id("bankPostalCode")).clear();
    driver.findElement(By.id("bankPostalCode")).sendKeys(bankPostalCodeComp);

    // Bank country
    Select bankCountryComp = new Select(driver.findElement(By.id("bankCountry")));
    int bankCoutryCompInt = r.nextInt(bankCountryComp.getOptions().size()) + 1;
    bankCountryComp.selectByIndex(bankCoutryCompInt);

    // Social 
    String socialTW = faker.internet().url();
    String socialFB = faker.internet().url();
    driver.findElement(By.id("twitterUsername")).clear();
    driver.findElement(By.id("facebookID")).clear();
    driver.findElement(By.id("twitterUsername")).sendKeys(socialTW);
    driver.findElement(By.id("facebookID")).sendKeys(socialFB);

    // SAVE
    driver.findElement(
            By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[26]/div/button"))
            .click();

}

From source file:administrationedit.addOffice.java

public static void main(String[] args) throws InterruptedException {

    System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
    driver = new ChromeDriver();
    WebDriverWait wait = new WebDriverWait(driver, 3);
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

    String[] city = { "Rijeka", "Pula", "Pore?", "Rovinj", "Umag", "Novigrad", "Vrsar", "Pazin", "Motovun",
            "Medulin", "Faana", "Vodnjan", "Opatija", "Krk", "Punat", "Baka", "Njivice", "Labin", "Rabac",
            "Plomin", "I?ii", "Ika", "Malinska", "Njivice", "Omialj", "Dramalj", "Crikvenica", "Selce",
            "Cres", "Rab", "Novi Vinodolski", "Povile", "iii", "Vodice", "Pinezii", "Lovran", "Medveja",
            "shanghai", "sao paulo", "kinshasa", "cairo", "peking", "london", "bogota", "dhaka",
            "rio de janeiro", "santiago", "toronto", "sydney", "wuhan", "chongqing", "xian", "chengdu",
            "alexandria", "tianjin", "melbourne", "abidjan", "shenyang", "berlin", "montreal", "harbin",
            "guangzhou", "madrid", "nanjing", "kabul", "luanda", "addis abeba", "taiyuan", "salvador",
            "changchun", "gizeh", "fortaleza", "cali", "belo horizonte", "brasilia", "santo domingo", "paris",
            "jinan", "tangshan", "dalian", "medellin", "algiers", "accra", "guayaquil", "jilin", "hangzhou",
            "nanchang", "conakry", "brisbane", "vancouver", "minsk", "hamburg", "curitiba", "qingdao", "manaus",
            "xinyang", "barcelona", "vienna", "urumqi", "recife", "kumasi", "perth", "cordoba", "lanzhou",
            "belem", "fushun", "quito", "luoyang", "hefei", "barranquilla", "lubumbashi", "porto alegre",
            "handan", "suzhou", "khulna", "douala", "yaounde", "munich", "rosario", "anshan", "xuzhou",
            "fuzhou", "guiyang", "goiania", "guarulhos", "prague", "dubai", "baku", "brazzaville", "wuxi",
            "yerevan", "copenhagen", "adelaide", "sofia", "datong", "tbilisi", "xianyang", "campinas",
            "ouagadougou", "huainan", "kunming", "brussels", "shenzhen", "nova iguacu", "rongcheng", "baoding",
            "benxi", "birmingham", "mendoza", "cologne", "calgary", "maceio", "cartagena", "changzhou",
            "sao goncalo", "sao luis", "huaibei", "cochabamba", "pingdingshan", "qiqihar", "mbuji-mayi",
            "ottawa", "wenzhou", "tucuman", "edmonton", "duque de caxias", "la paz", "nanning", "marseille",
            "anyang", "hohhot", "valencia", "xining", "liuzhou", "natal", "qinhuangdao", "hengyang", "taian",
            "teresina", "xinxiang", "sao bernardo do campo", "hegang", "campo grande", "athens", "cucuta",
            "langfang", "ningbo", "yantai", "zhuzhou", "jaboatao", "rajshahi", "sarajevo", "zhangjiakou",
            "cotonou", "zigong", "fuxin", "liaoyang", "sevilla", "la plata", "bangui", "osasco", "zhangdian",
            "puyang", "nantong", "mudanjiang", "santo andre", "hamilton", "joao pessoa", "shaoyang", "guilin",
            "frankfurt", "wahran", "mar del plata", "quebec", "zhanjiang", "zaragoza", "zhenjiang", "winnipeg",
            "dandong", "shaoguan", "yancheng", "foshan", "contagem", "jibuti", "haikou", "sao jose dos campos",
            "taizhou", "xingtai", "glasgow", "jinzhou", "abu dhabi", "luancheng", "dortmund", "stuttgart",
            "yingkou", "zhangzhou", "belfast" };

    Random r = new Random();

    Faker faker = new Faker();

    driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/office/add");

    adminLogin login = new adminLogin(driver);
    login.loginToAdmin("demo", "demo");

    // Input name
    String nameComp = faker.company().name();
    driver.findElement(By.id("name")).clear();
    driver.findElement(By.id("name")).sendKeys(nameComp);

    // Input address
    String addressComp = faker.address().fullAddress();
    driver.findElement(By.id("address")).clear();
    driver.findElement(By.id("address")).sendKeys(addressComp);

    // Input city
    String cityComp = faker.address().city();
    driver.findElement(By.id("city")).clear();
    driver.findElement(By.id("city")).sendKeys(cityComp);

    // Input postal code
    String postalCodeComp = faker.address().zipCode();
    driver.findElement(By.id("postalCode")).clear();
    driver.findElement(By.id("postalCode")).sendKeys(postalCodeComp);

    // Country//from   w  ww  .j  av  a2  s . com
    Select countryComp = new Select(driver.findElement(By.id("country")));
    int coutryCompInt = r.nextInt(countryComp.getOptions().size()) + 1;
    countryComp.selectByIndex(coutryCompInt);

    // Email
    String emailComp = faker.internet().emailAddress();
    driver.findElement(By.id("email")).clear();
    driver.findElement(By.id("email")).sendKeys(emailComp);

    // Phone
    String phoneComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("phone")).clear();
    driver.findElement(By.id("phone")).sendKeys(phoneComp);

    // Mobile
    String mobileComp = faker.phoneNumber().cellPhone().replaceAll("\\D", "");
    driver.findElement(By.id("mobilePhone")).clear();
    driver.findElement(By.id("mobilePhone")).sendKeys(mobileComp);

    // Fax
    String faxComp = faker.phoneNumber().phoneNumber().replaceAll("\\D", "");
    driver.findElement(By.id("fax")).clear();
    driver.findElement(By.id("fax")).sendKeys(faxComp);

    // Geolocation
    int cityN = r.nextInt(city.length);
    driver.findElement(By
            .xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/input"))
            .sendKeys(city[cityN]);
    driver.findElement(
            By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[10]/div[1]/div[1]/a"))
            .click();
    Thread.sleep(3000);
    // SAVE
    driver.findElement(
            By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[2]/div[12]/div/button"))
            .click();

}

From source file:administrationedit.setSeasonTemplate.java

public static void main(String[] args) throws InterruptedException {

    for (int y = 0; y < 2; y++) {

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
        driver = new ChromeDriver();
        WebDriverWait wait = new WebDriverWait(driver, 3);
        driver.manage().window().maximize();

        Random r = new Random();

        Faker faker = new Faker();

        driver.get("https://goldfish.dev.hexis.hr/demo/en/administration/accommodation/seasonTemplateAdd");

        adminLogin login = new adminLogin(driver);
        login.loginToAdmin("demo", "demo");

        int currentYear = Calendar.getInstance().get(Calendar.YEAR) + y;
        String curYear = String.valueOf(currentYear);

        // Input name of template
        driver.findElement(By.id("name")).sendKeys("Season-" + curYear);

        // Choose year
        Select year = new Select(driver.findElement(By.id("year")));
        year.selectByVisibleText(curYear);

        // Now select seasons
        WebElement tableId = driver.findElement(By.xpath("//*[@class='ui-calendar hasDatepicker']"));
        if (year.getFirstSelectedOption().getText().equals(curYear)) {
            String id = tableId.getAttribute("id");

            for (int i = 1; i <= 12; i++) {
                Thread.sleep(1000);
                for (int j = 1; j <= 7; j++) {
                    if (!driver.findElements(By.xpath(
                            "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a"))
                            .isEmpty()) {
                        driver.findElement(By.xpath(
                                "//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr[1]/td[" + j + "]/a"))
                                .click();
                        break;
                    }//www .j a v  a 2  s.  co m
                }
                i++;
                int weeks = driver
                        .findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr"))
                        .size();

                int test = 0;
                for (int j = 7; j >= 1; j--) {
                    if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i + "]/table/tbody/tr["
                            + weeks + "]/td[" + j + "]/a")).isEmpty()) {
                        test = 1;
                        break;
                    } else
                        test = 2;
                }
                switch (test) {
                case 1:
                    for (int j = 7; j >= 1; j--) {
                        if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).isEmpty()) {
                            driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                    + "]/table/tbody/tr[" + weeks + "]/td[" + j + "]/a")).click();
                            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            Select season1 = new Select(driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            int season1int = r.nextInt(season1.getOptions().size() - 1) + 1;
                            season1.selectByIndex(season1int);
                            driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]"))
                                    .click();
                            break;
                        }
                    }
                    break;
                case 2:
                    for (int j = 7; j >= 1; j--) {
                        if (!driver.findElements(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).isEmpty()) {
                            driver.findElement(By.xpath("//*[@id='" + id + "']/div/div[" + i
                                    + "]/table/tbody/tr[" + (weeks - 1) + "]/td[" + j + "]/a")).click();
                            wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            Select season2 = new Select(driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[3]/div/select")));
                            int season2int = r.nextInt(season2.getOptions().size() - 1) + 1;
                            season2.selectByIndex(season2int);
                            driver.findElement(By.xpath(
                                    "//*[@id='tab-basic']/div[3]/div[1]/div/div[2]/div/div/div/div/div/div[4]/div/a[2]"))
                                    .click();
                            break;
                        }
                    }
                }
            }
        }

        // SAVE
        wait.until(ExpectedConditions.visibilityOfElementLocated(
                By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input")));
        driver.findElement(By.xpath("//*[@id='page-wrapper']/div[2]/form/div[2]/div/div/div/div[3]/div/input"))
                .click();
        if (driver.getTitle().equals("Accommodation season templates administration")) {
            driver.close();
        }
    }
}

From source file:applango.common.dashboardTests.java

@Test
@Ignore//from  w  ww . j  a v  a2s  . c o  m
public void testEnteringValidOAuthenticationCredentials()
        throws ParserConfigurationException, SAXException, IOException, InterruptedException {
    //Make sure customer and user for applango created
    //Set application  java -jar tools.jar -caimgr -dc automationCustomer,salesforce
    driver1 = getRemoteWebDriver(DesiredCapabilities.chrome());
    Applango applango = getApplangoConfigurationXML();
    //        FirefoxDriver driver1 = getFirefoxDriver();
    WebDriverWait wait1 = new WebDriverWait(driver1, 55);
    Salesforce sf = genericSalesforceWebsiteActions.getSalesforceConfigurationXML();
    final String connection = dbTables.OAuth2Credentials.getValue().toString();

    try {

        DBCollection coll = db.getCollection(connection);
        DBObject dbObjectRecordQuery = mongoDB.removeRecordsFromDB(applango, coll);

        genericApplangoWebsiteActions.openDashboardAndLogin(applango, driver1, wait1, true, true);
        genericApplangoWebsiteActions.clickOnApplicationSettings(driver1, wait1);
        genericApplangoWebsiteActions.enterAuthentication(driver1, sf.getAccessToken(), sf.getClientSecret());
        genericApplangoWebsiteActions.clickOnAuthenticationSubmit(driver1, wait1);
        genericApplangoWebsiteActions.clickOnAuthenticationLink(driver1, wait1);

        String mainWinID = controlAndSwitchWindow(driver1);

        genericSalesforceWebsiteActions.waitForLoginPageToLoad(wait1);
        genericSalesforceWebsiteActions.enterCredentials(driver1, sf.getUsername(), sf.getPassword());
        genericSalesforceWebsiteActions.clickOnSubmitCredentials(driver1);
        genericApplangoWebsiteActions.waitForSuccessfulAuthenticatedMessage(driver1, wait1);
        driver1.close(); //Closes new window that opened (sf)

        driver1.switchTo().window(mainWinID); //Switch back to applango
        clickOnVerifyAuthentication(driver1);
        genericApplangoWebsiteActions.waitForSuccessfulAccountAuthenticatedMessage(wait1);

        mongoDB.checkRecordCreatedInDB(applango, connection, coll, dbObjectRecordQuery);
    }

    catch (Exception ex) {
        logger.error(ex.getMessage());
        fail("Failed due to : " + ex.getMessage());
    } finally {
        driver1.close();
    }
}

From source file:applango.common.dashboardTests.java

@Test
public void testDashboardLogin() throws Exception {
    Applango applango = getApplangoConfigurationXML();
    logger.info("********************************************* Running  "
            + Thread.currentThread().getStackTrace()[1].getMethodName()
            + "*********************************************");
    driver1 = getRemoteWebDriver(DesiredCapabilities.firefox());

    WebDriverWait wait = new WebDriverWait(driver1, getTimeout());

    String validUsername = applango.getUsername();
    String validPassword = applango.getPassword();
    String invalidUsername = "notRealUsername";
    String invalidPassword = "notRealPassword";
    String empty = "";
    try {/* w w w. j a va2 s  .c om*/
        DBCollection applangoUserLoginHistoryCollection = db
                .getCollection(dbTables.applangoUserLoginHistory.getValue().toString());
        int failureLogins = countFailureLogins(applango, applangoUserLoginHistoryCollection);
        int successfulLogins = countSuccessfulLogins(applango, applangoUserLoginHistoryCollection);

        launchingWebsite(driver1, applango.getUrl());
        waitForDashboardLoginPageToLoad(wait);

        logger.info("Enter invalid credentials and check login failed error message appears");
        genericApplangoWebsiteActions.enterCredentials(driver1, invalidUsername, invalidPassword);
        genericApplangoWebsiteActions.clickOnLoginButtonAndWaitForErrorMessage(driver1, wait);
        logger.info("Check no change in amount of successful, failure login");
        checkSuccessfulAndFailureLoginsCounts(applango, applangoUserLoginHistoryCollection, failureLogins,
                successfulLogins);

        logger.info("Enter invalid password and check login failed error message appears");
        genericApplangoWebsiteActions.enterCredentials(driver1, validUsername, invalidPassword);
        genericApplangoWebsiteActions.clickOnLoginButtonAndWaitForErrorMessage(driver1, wait);
        logger.info("Check no change in amount of successful logins, failure login added");
        failureLogins++;
        checkSuccessfulAndFailureLoginsCounts(applango, applangoUserLoginHistoryCollection, failureLogins,
                successfulLogins);

        logger.info("Enter empty credentials and check login failed error message appears");
        genericApplangoWebsiteActions.enterCredentials(driver1, empty, empty);
        genericApplangoWebsiteActions.clickOnLoginButtonAndWaitForPleaseEnterUsernameErrorMessage(driver1,
                wait);
        logger.info("Check no change in amount of successful, failure login");
        checkSuccessfulAndFailureLoginsCounts(applango, applangoUserLoginHistoryCollection, failureLogins,
                successfulLogins);

        logger.info("empty password and check login failed error message appears");
        genericApplangoWebsiteActions.enterCredentials(driver1, validUsername, empty);
        genericApplangoWebsiteActions.clickOnLoginButtonAndWaitForPleaseEnterPasswordErrorMessage(driver1,
                wait);
        logger.info("Check no change in amount of successful logins, failure login added");
        checkSuccessfulAndFailureLoginsCounts(applango, applangoUserLoginHistoryCollection, failureLogins,
                successfulLogins);

        logger.info("Valid password and check login successes (Remember username checked)");
        genericApplangoWebsiteActions.enterCredentials(driver1, validUsername.toLowerCase(), validPassword);
        selectRememberUsernameCheckbox(driver1);
        genericApplangoWebsiteActions.clickOnLoginButtonAndWaitForUserListToLoad(driver1, wait);
        logger.info("Check no change in amount of failure logins, successful login added");
        successfulLogins++;
        genericApplangoWebsiteActions.logout(driver1, wait);
        checkSuccessfulAndFailureLoginsCounts(applango, applangoUserLoginHistoryCollection, failureLogins,
                successfulLogins);

        logger.info("Valid password and check login successes (Remember username un-checked)");
        genericApplangoWebsiteActions.enterCredentials(driver1, validUsername.toLowerCase(), validPassword);
        unselectRememberUsernameCheckbox(driver1);
        genericApplangoWebsiteActions.clickOnLoginButtonAndWaitForUserListToLoad(driver1, wait);
        logger.info("Check no change in amount of failure log-ins, successful login added");
        successfulLogins++;
        genericApplangoWebsiteActions.logout(driver1, wait);
        checkSuccessfulAndFailureLoginsCounts(applango, applangoUserLoginHistoryCollection, failureLogins,
                successfulLogins);
    } catch (Exception ex) {
        fail("");
        logger.error(ex.getMessage());
    }

    finally {
        driver1.close();
    }
}

From source file:applango.common.dashboardTests.java

@Test
public void testExcludeUsers() throws ParserConfigurationException, SAXException, IOException {
    driver1 = getRemoteWebDriver(DesiredCapabilities.firefox());
    WebDriverWait wait = new WebDriverWait(driver1, timeOutInSeconds());
    Applango applango = getApplangoConfigurationXML();
    Salesforce sf = genericSalesforceWebsiteActions.getSalesforceConfigurationXML();
    final String connection = dbTables.excludedUser.getValue().toString();
    DBCollection coll = db.getCollection(connection);

    try {//from   www.j a  va 2 s.c  o m
        BasicDBObject documentBuilder = new BasicDBObject("appName", "salesforce")
                .append("customerId", "automationCustomer").append("externalId", "005b0000000w0ytAAA");
        //userId : zzzzchatteruser2888@applangoqa.com
        String lastName = "excludedUser";

        logger.info("Check that user is in [excludedUser] table");
        if (coll.count(documentBuilder) != 0) {
            genericApplangoWebsiteActions.openDashboardAndLogin(applango, driver1, wait);
            genericApplangoWebsiteActions.enterValueInSearchLastName(driver1, lastName);
            logger.info("Check that user not exist in usertable");
            assertFalse(driver1.findElement(By.id(applangoObject.USERTABLE.getValue().toString())).getText()
                    .contains(lastName));
        }
    } catch (Exception ex) {
        ex.getMessage();
    } finally {
        driver1.close();
    }
}