Example usage for org.openqa.selenium By name

List of usage examples for org.openqa.selenium By name

Introduction

In this page you can find the example usage for org.openqa.selenium By name.

Prototype

public static By name(String name) 

Source Link

Usage

From source file:ParametrizedSearchTest.java

@Test
public void test() throws InterruptedException {
    driver.get(baseUrl + "/samplecenter/faces/index.xhtml");
    driver.findElement(By.id("j_idt11:searchbar")).clear();
    Thread.sleep(1000);/*from  w w w  .  j  av a2  s .c  om*/
    driver.findElement(By.id("j_idt11:searchbar")).sendKeys(pattern);
    Thread.sleep(1000);
    driver.findElement(By.name("j_idt11:j_idt12")).click();
    Thread.sleep(1000);
    // ne fonctionne pas avec test paramtrs
    //assertEquals(result, driver.findElement(By.id("resultcount")).getText());
    System.out.println("search pattern: " + pattern + ", result: " + result);
    if (result.equals(driver.findElement(By.id("resultcount")).getText())) {
        System.out.println("Test passed");
    } else {
        System.err.println("!!! Test failed !!!");
    }
}

From source file:CarTest1.java

@Test
public void test5() throws Exception {

    WebElement row = driver.findElement(By.xpath("//tbody/tr[td='938']"));
    WebElement a = row.findElements(By.tagName("a")).get(0);
    a.click();/*from   w ww.  jav  a2  s  .  c  o  m*/
    WebElement desc = driver.findElement(By.name("description"));
    desc.clear();
    desc.sendKeys("Cool car");

    WebElement submit = driver.findElement(By.id("save"));
    submit.click();

    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement newRow = d.findElement(By.xpath("//tbody/tr[td = '938']"));
        String b = newRow.findElements(By.tagName("td")).get(5).getText();
        Assert.assertEquals("Cool car", b);
        return true;
    });
}

From source file:CarTest1.java

@Test
public void test7() throws Exception {
    WebElement newCar = driver.findElement(By.id("new"));
    newCar.click();//www.  java2  s.  c o  m

    WebElement year = driver.findElement(By.name("year"));
    WebElement reg = driver.findElement(By.name("registered"));
    WebElement make = driver.findElement(By.name("make"));
    WebElement model = driver.findElement(By.name("model"));
    WebElement desc = driver.findElement(By.name("description"));
    WebElement price = driver.findElement(By.name("price"));
    WebElement submit = driver.findElement(By.id("save"));

    year.sendKeys("2008");
    reg.sendKeys("2002-5-5");
    make.sendKeys("Kia");
    model.sendKeys("Rio");
    desc.sendKeys("As new");
    price.sendKeys("31000");

    submit.click();

    (new WebDriverWait(driver, WAIT_MAX)).until((ExpectedCondition<Boolean>) (WebDriver d) -> {
        WebElement e = d.findElement(By.tagName("tbody"));
        List<WebElement> rows = e.findElements(By.tagName("tr"));
        Assert.assertThat(rows.size(), is(6));
        return true;
    });
}

From source file:ForumTestSelenium.java

@Test
public void testForumselenium() throws Exception {
    driver.get(baseUrl + "/forum/");
    driver.findElement(By.id("btToCadastro")).click();
    driver.findElement(By.name("nome")).clear();
    driver.findElement(By.name("nome")).sendKeys("Julio Valsesia");
    driver.findElement(By.name("login")).clear();
    driver.findElement(By.name("login")).sendKeys("jvalsesia");
    driver.findElement(By.name("email")).clear();
    driver.findElement(By.name("email")).sendKeys("jvalsesia@email.com");
    driver.findElement(By.name("senha")).clear();
    driver.findElement(By.name("senha")).sendKeys("1234");
    driver.findElement(By.id("btCadastrar")).click();
    driver.findElement(By.name("login")).clear();
    driver.findElement(By.name("login")).sendKeys("jvalsesia");
    driver.findElement(By.name("senha")).clear();
    driver.findElement(By.name("senha")).sendKeys("1234");
    driver.findElement(By.id("btLogin")).click();
    driver.findElement(By.id("btInserirTopico")).click();
    driver.findElement(By.name("titulo")).clear();
    driver.findElement(By.name("titulo")).sendKeys("topico 01");
    driver.findElement(By.name("conteudo")).clear();
    driver.findElement(By.name("conteudo")).sendKeys("conteudo 01");
    driver.findElement(By.id("btNewTopico")).click();
    driver.findElement(By.id("btExibir")).click();
    driver.findElement(By.name("comentario")).clear();
    driver.findElement(By.name("comentario")).sendKeys("comentario 01");
    driver.findElement(By.id("btNovoComentario")).click();
    driver.findElement(By.id("btVoltaTopicos")).click();
    driver.findElement(By.id("btExibir")).click();
    driver.findElement(By.id("btVoltaTopicos")).click();
    driver.findElement(By.id("btExibirRanking")).click();
    driver.findElement(By.id("btVoltaTopicos")).click();
}

From source file:JUnitTestClass.java

@Test
public void Enter_Text_Using_Name_Locator() throws Exception {
    driver.findElement(By.name("firstname")).sendKeys("Testing Selenium");
    driver.findElement(By.name("lastname")).sendKeys("Name Locator");
}

From source file:FormFiller.java

private static void pseudoMain(String[] args) throws IOException {
    if (args.length < 3 || args.length > 5)
        throw new IllegalArgumentException("Usage: lastName bankName deliveryDate [firstName] [print]\n"
                + "e.g. Hakim Ally 01/01/2016 OR Hakim Chase 1/1/2016 William print\n");

    if (args[args.length - 1].equals("print")) {
        print = true;/*from www  .ja va2 s.co  m*/
    }

    WebDriver driver = getNewFirefoxDriver();

    driver.get("https://www.dealertrack.com/default1.aspx?RefreshBy=SM");

    HashMap dealerTrackData = new HashMap();

    try {

        WebElement username = driver.findElement(By.name("username"));
        username.sendKeys("whakim");
        WebElement pwd = driver.findElement(By.name("password"));
        pwd.sendKeys("keepbeepin23");
        driver.findElement(By.name("login")).submit();

        JavascriptExecutor jse = (JavascriptExecutor) driver;

        jse.executeScript("var script = document.createElement('script');\n"
                + "script.src = \"https://ajax.googleapis.com/ajax/libs/jquery/2.1.4/jquery.min.js\";\n"
                + "document.getElementsByTagName('head')[0].appendChild(script);");

        jse.executeScript("document.getElementById('iFrm').contentWindow.document.body."
                + "firstElementChild.contentDocument.getElementById('AppStatus').click()");

        int attempts = 0;
        while (attempts++ < 15) {
            Thread.sleep(500);
            try {
                jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                        + "contentDocument.getElementById('txtSearchValue').value = '" + args[0] + "'");
                jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                        + "contentDocument.getElementById('btnSearch').click();");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 15)
                    e.printStackTrace();
            }
        }

        jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                + "contentDocument.getElementById('btnSearch').click();");

        attempts = 0;
        String firstLenderName = null;
        int boxNum = -1;

        while (attempts++ < 10) {
            Thread.sleep(750);
            try {
                String boxName = (String) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                + "body.childNodes[2].contentDocument.getElementById('applications_ctrl"
                                + ++boxNum + "_Tapplications_ctrl" + boxNum + "_TR').innerHTML");
                int comma = boxName.indexOf(',');

                if (comma == -1 || !(boxName.substring(0, comma).contains(args[0]))) {
                    boxNum--;
                    continue;
                }

                else if (args.length > 3 && !args[3].equals("print")
                        && !boxName.substring(comma, boxName.length()).contains(args[3]))
                    continue;

                long numApplications = (long) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                + "body.childNodes[2].contentDocument.getElementsByClassName('lender_decisions')["
                                + boxNum + "]." + "childNodes[0].childElementCount");
                String firstLenderResult = (String) jse.executeScript("return document.getElementById('iFrm')."
                        + "contentWindow.document.body.childNodes[2].contentDocument.getElementsByClassName"
                        + "('lender_decisions')[" + boxNum + "].childNodes[0].childNodes[0].className");

                firstLenderName = (String) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow."
                                + "document.body.childNodes[2].contentDocument.getElementsByClassName('lender_decisions')["
                                + boxNum + "]." + "childNodes[0].childNodes[0].childNodes[0].innerHTML");

                if (!firstLenderName.equals(args[1]) && numApplications == 1)
                    continue;

                String secondLenderResult = null;

                if (numApplications > 1) {
                    secondLenderResult = (String) jse.executeScript("return document.getElementById('iFrm')."
                            + "contentWindow.document.body.childNodes[2].contentDocument.getElementsByClassName"
                            + "('lender_decisions')[" + boxNum + "].childNodes[0].childNodes[1].className");
                }

                if (firstLenderResult.contains("declined")
                        && ((numApplications > 1) ? secondLenderResult.contains("declined")
                                : secondLenderResult == null))
                    continue;

                break;

            } catch (WebDriverException e) {
                boxNum--;
                if (attempts >= 10)
                    e.printStackTrace();
            }
        }

        attempts = 0;
        String apr = null;

        if (args[1].equals("Chase")) {

            if (firstLenderName.equals("Chase"))
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[0].childNodes[0].click()");

            else
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[1].childNodes[0].click()");

            // APR
            while (attempts++ < 10) {
                Thread.sleep(1500);
                try {
                    apr = (String) jse
                            .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                    + "body.childNodes[2].contentDocument.getElementById('appDetails').contentDocument."
                                    + "getElementById('divHtml').childNodes[1].childNodes[1].childNodes[4].childNodes[1]."
                                    + "childNodes[5].firstElementChild.childNodes[0].childNodes[3].childNodes[3].childNodes[1]."
                                    + "childNodes[10].childNodes[3].childNodes[0].nodeValue");
                    break;
                } catch (WebDriverException e) {
                    if (attempts >= 10)
                        e.printStackTrace();
                }
            }

            dealerTrackData.put("Text201", "JPMorgan Chase Bk");
            dealerTrackData.put("fullBankName", "JPMorgan Chase Bk\nPO Box 901098\nFort Worth, TX 76101-2098");

        }

        else if (args[1].equals("Ally")) {

            if (firstLenderName.equals("Ally"))
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[0].childNodes[0].click()");

            else
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementsByClassName('lender_decisions')[" + boxNum
                                + "].childNodes[0].childNodes[1].childNodes[0].click()");

            // APR
            while (attempts++ < 10) {
                Thread.sleep(1500);
                try {
                    apr = (String) jse
                            .executeScript("return document.getElementById('iFrm').contentWindow.document."
                                    + "body.childNodes[2].contentDocument.getElementById('appDetails').contentDocument."
                                    + "getElementById('divHtml').childNodes[1].childNodes[1].childNodes[4].childNodes[1].childNodes[3]."
                                    + "childNodes[1].childNodes[2].childNodes[1].childNodes[2].childNodes[3].childNodes[1]."
                                    + "lastElementChild.childNodes[3].childNodes[0].data");
                    break;
                } catch (WebDriverException e) {
                    if (attempts >= 10)
                        e.printStackTrace();
                }

            }

            // Lienholder Name
            String lienName = null;
            attempts = 0;

            for (int i = 6; lienName == null
                    || !(lienName.contains(";") && lienName.contains("Ally")); i += 2, attempts++) {
                try {
                    lienName = tryAllyBox(jse, i);
                } catch (WebDriverException e) {
                    if (attempts >= 10)
                        e.printStackTrace();
                    Thread.sleep(50);
                }
            }

            dealerTrackData.put("Text201", lienName.substring(1, lienName.indexOf(";")));

            dealerTrackData.put("fullBankName", "Ally Bank\nP.O. Box 8128\nCockeysville, MD 21030");
        }

        else
            throw new IOException("Unsupported bank: " + args[1] + ". Choose Chase or Ally.");

        dealerTrackData.put("Text15", apr.substring(0, apr.length() - 2));

        Thread.sleep(1200);

        // Navigate to Application Info
        attempts = 0;
        while (attempts++ < 10) {
            Thread.sleep(50);
            try {
                jse.executeScript(
                        "document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                                + "getElementById('appDetails').contentDocument.getElementById('divBtn').childNodes[4].childNodes[1].click()");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 10)
                    e.printStackTrace();
            }
        }

        attempts = 0;
        while (attempts++ < 15) {
            Thread.sleep(500);
            try {
                try {
                    jse.executeScript("document.getElementById('iFrm').contentWindow.document.body."
                            + "childNodes[2].contentDocument.getElementById('optAction_0').checked = true");
                    break;
                } catch (WebDriverException e) {
                    jse.executeScript("document.getElementById('iFrm').contentWindow.document.body."
                            + "childNodes[2].contentDocument.getElementById('optAction_copy_0').checked = true");
                    break;
                }
            } catch (WebDriverException e) {
                if (attempts >= 15) {
                    e.printStackTrace();
                }
            }
        }

        attempts = 0;
        while (attempts++ < 10) {
            Thread.sleep(250);
            try {
                jse.executeScript("document.getElementById('iFrm').contentWindow.document.body.childNodes[2]."
                        + "contentDocument.getElementById('btncontinue').click()");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 10) {
                    e.printStackTrace();
                }
            }
        }

        // Sale ID
        attempts = 0;
        String sid = null;

        while (attempts++ < 20) {
            Thread.sleep(750);
            try {
                sid = (String) jse
                        .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                                + "childNodes[2].contentDocument.getElementById('app_stock_num').value");
                break;
            } catch (WebDriverException e) {
                if (attempts >= 20) {
                    e.printStackTrace();
                }
            }
        }

        dealerTrackData.put("Text3", sid);

        // Figure out what state the buyer is in
        dealerTrackData.put("buyerState", (String) jse.executeScript("return document.getElementById('iFrm')."
                + "contentWindow.document.body.childNodes[2].contentDocument.getElementById('app_state').value"));

        // Buyer Name and Address
        String firstName = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_first_name').value");

        String lastName = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_last_name').value");

        // Store applicant's name for PDF naming
        String fullName = firstName + " " + lastName;
        dealerTrackData.put("fullName", fullName);

        String address0 = (String) jse.executeScript("return ((document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_street_num').value).concat(' '))."
                + "concat(document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                + "getElementById('app_street_name').value)");

        String aptNum = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_apt_num').value");

        if (!aptNum.equals(""))
            address0 = address0 + " " + aptNum;

        String city = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_city').value");

        String state = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_state').value");

        String zipCode = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_zip_code').value");

        dealerTrackData.put("Text5", fullName + "\n" + address0 + "\n" + city + ", " + state + " " + zipCode);

        // Fill Name/Address Lines in Ally Credit App + Confirmation of Insurance, if applicable

        if (args[1].equals("Ally") || dealerTrackData.get("buyerState").equals("TX")) {
            dealerTrackData.put("Last Name (or trade name of business)", lastName);
            dealerTrackData.put("First", firstName);
            dealerTrackData.put("Present Address", address0);
            dealerTrackData.put("Zip Code", zipCode);
            dealerTrackData.put("City", city);
            dealerTrackData.put("State", state);
        }

        dealerTrackData.put("addressLine", address0 + ", " + city + ", " + state + " " + zipCode);

        boolean cosigner = false;

        // Co-Signer Name and Address (if applicable)
        try {
            String coAppFirstName = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_first_name').value");

            String coAppLastName = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_last_name').value");

            String coAppFullName = coAppFirstName + ' ' + coAppLastName;

            // Store Co-App Full Name (for TX Contract)
            dealerTrackData.put("coAppFullName", coAppFullName);

            String coAppAddress0 = (String) jse
                    .executeScript("return ((document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_street_num').value).concat(' '))."
                            + "concat(document.getElementById('iFrm').contentWindow.document.body.childNodes[2].contentDocument."
                            + "getElementById('app_co_street_name').value)");

            String coAppAptNum = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_apt_num').value");

            if (!coAppAptNum.equals(""))
                coAppAddress0 = coAppAddress0 + " " + coAppAptNum;

            String coAppCity = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_city').value");

            String coAppState = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_state').value");

            String coAppZipCode = (String) jse
                    .executeScript("return document.getElementById('iFrm').contentWindow."
                            + "document.body.childNodes[2].contentDocument.getElementById('app_co_zip_code').value");

            dealerTrackData.put("Text6", coAppFullName + "\n" + coAppAddress0 + "\n" + coAppCity + ", "
                    + coAppState + " " + coAppZipCode);

            if (args[1].equals("Ally") || dealerTrackData.get("buyerState").equals("TX")) {
                dealerTrackData.put("First2", coAppFirstName);
                dealerTrackData.put("Last Name (or trade nameof business)2", coAppLastName);
                dealerTrackData.put("Present Address2", coAppAddress0);
                dealerTrackData.put("Zip Code2", coAppZipCode);
                dealerTrackData.put("City2", coAppCity);
                dealerTrackData.put("State2", coAppState);
            }

            cosigner = true;

        } catch (WebDriverException e) {
            dealerTrackData.put("cosignerNullField", "N/A");
        }

        // Car Year
        String carYear = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementById('app_auto_yearList').value");
        dealerTrackData.put("Text9", carYear);

        // Car Make and Model
        String carMake = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_auto_makeList').value");

        String carModel = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_auto_modelList').value");

        dealerTrackData.put("Text10", carMake + ' ' + carModel);

        dealerTrackData.put("Make", carMake);
        dealerTrackData.put("Model", carModel);

        // Style/Trim
        String carStyleTrim = (String) jse.executeScript("return document.getElementById('iFrm').contentWindow."
                + "document.body.childNodes[2].contentDocument.getElementById('app_auto_trimList').value");
        dealerTrackData.put("StylefTrim", carStyleTrim);

        // VIN
        String vin = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementById('app_vin_num').value");
        dealerTrackData.put("Text12", vin);

        // Amount Financed
        if (args[1].equals("Chase"))
            recalculateChaseStructure(jse);

        String amountFinanced = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_est_amt_financed')[0].value");
        double amountFinancedDouble = Double.parseDouble(amountFinanced);
        String amountFinancedFormatted = moneyFormatter.format(amountFinancedDouble);
        dealerTrackData.put("Text17", amountFinancedFormatted);

        // Term
        String loanTerm = (jse
                .executeScript("return (document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_terms')[0].value - 1)")
                .toString());
        dealerTrackData.put("Number Payments 4", dealerTrackData.get("buyerState").equals("CA") ? loanTerm
                : Integer.toString(Integer.parseInt(loanTerm) + 1));

        // Meaty Loan Calculations
        double aprDouble = (Double.parseDouble((String) dealerTrackData.get("Text15")) / (Double) 100.);
        int loanTermInt = Integer.parseInt(loanTerm) + 1;

        double monthlyPayment = Double.parseDouble(moneyFormatter.format(amountFinancedDouble
                * (aprDouble / 12.) / (1. - Math.pow(1. + aprDouble / 12., -loanTermInt))));
        String roundMonthlyPayment = moneyFormatter.format(monthlyPayment);

        double totalOfPayments = monthlyPayment * loanTermInt;
        String roundTotalOfPayments = moneyFormatter.format(totalOfPayments);

        // Total of Payments
        dealerTrackData.put("Text18", roundTotalOfPayments);

        // Finance Charge (take care of down payment later)
        dealerTrackData.put("Text16", moneyFormatter.format(totalOfPayments - amountFinancedDouble));

        // Monthly Payments
        dealerTrackData.put("Text26", roundMonthlyPayment);
        dealerTrackData.put("Text31", roundMonthlyPayment);

        // First and Last Payment Date
        DateTimeFormatter ddFormat = DateTimeFormatter.ofPattern("M/d/yyyy");
        LocalDate dd = LocalDate.parse(args[2], ddFormat);
        int plusDays = (args[1].equals("Chase")) ? 45 : 30;

        LocalDate firstPayment = dd.plusDays(plusDays);
        LocalDate lastPayment = firstPayment.plusMonths(loanTermInt - 1);

        String firstPaymentFormatted = firstPayment.format(ddFormat);
        String lastPaymentFormatted = lastPayment.format(ddFormat);

        dealerTrackData.put("Text27", firstPaymentFormatted);
        dealerTrackData.put("Text32", lastPaymentFormatted);

        // Car Base Price
        String carBasePrice = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_price')[0].value");
        double carBasePriceDouble = Double.parseDouble(carBasePrice);
        String carBasePriceFormatted = moneyFormatter.format(carBasePriceDouble);

        dealerTrackData.put("Text33", carBasePriceFormatted);
        dealerTrackData.put("Text34", carBasePriceFormatted);

        // Sales Tax
        String carTaxes = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_sales_tax')[0].value");
        double carTaxesDouble = Double.parseDouble(carTaxes);
        String carTaxesFormatted = moneyFormatter.format(carTaxesDouble);

        dealerTrackData.put("Text49", carTaxesFormatted);

        // Extended Peace of Mind
        String serviceContract = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_warranty')[0].value");
        Double serviceContractDouble = 0.;

        if (!serviceContract.equals("")) {
            serviceContractDouble = Double.parseDouble(serviceContract);

            dealerTrackData.put("Text51", moneyFormatter.format(serviceContractDouble));
            // For California Contract
            dealerTrackData.put("Text94", "Beepi Peace of Mind");
            dealerTrackData.put("7/13_1LCompany", "Beepi Peace of Mind");
            // For Arizona or Texas Contract
            dealerTrackData.put("Beepi", "Beepi");
            dealerTrackData.put("na5", "Extended Peace of Mind");

        }

        // Documentary Service Fees
        String documentFee = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_other_finance_fees')[0].value");
        Double documentFeeDouble = 0.;

        if (!documentFee.equals("")) {
            documentFeeDouble = Double.parseDouble(documentFee);
            dealerTrackData.put("Text42", moneyFormatter.format(documentFeeDouble));
        }

        // Registration Fees
        String regFees = (String) jse
                .executeScript("return document.getElementById('iFrm').contentWindow.document.body."
                        + "childNodes[2].contentDocument.getElementsByName('app_ttl')[0].value");
        double regFeesDouble = Double.parseDouble(regFees);
        String regFeesFormatted = moneyFormatter.format(regFeesDouble);

        dealerTrackData.put("Text62", regFeesFormatted);
        dealerTrackData.put("Text65", regFeesFormatted);

        // Calculate Contract Based on State
        switch ((String) dealerTrackData.get("buyerState")) {
        case "CA":
            californiaContract(args, jse, dealerTrackData, carBasePriceDouble, carTaxesDouble,
                    serviceContractDouble, regFeesDouble, documentFeeDouble, totalOfPayments);
            break;
        case "AZ":
        case "TX":
        case "WA":
            arizonaTexasWashingtonContract(args, jse, dealerTrackData, carBasePriceDouble, carTaxesDouble,
                    serviceContractDouble, regFeesDouble, documentFeeDouble, totalOfPayments);
            break;
        }

        // Amount Financed
        dealerTrackData.put("Text77", amountFinancedFormatted);

        // Delivery Date (Signatures)
        String ddFormatted = dd.format(ddFormat);

        dealerTrackData.put("Text159", ddFormatted);
        dealerTrackData.put("Text165", ddFormatted);

        if (cosigner)
            dealerTrackData.put("Text160", ddFormatted);

        // Populate Credit Applications
        if (args[1].equals("Ally"))
            getAllyCreditInfo(jse, dealerTrackData, cosigner);
        else
            getChaseCreditInfo(jse, dealerTrackData, driver);

    } catch (Exception e) {
        e.printStackTrace();
    }

    driver.quit();

    String contractDir = "DO NOT EDIT - AutoFill Contracts/";

    try {

        if (args[1].equals("Ally")) {
            outputDir = makeOutputDir(dealerTrackData);
            fillPdf(dealerTrackData, contractDir + "Blank Ally Credit Application.pdf", outputDir,
                    "Ally Credit Application");
            fillPdf(dealerTrackData, contractDir + "Blank Ally Odometer Disclosure.pdf", outputDir,
                    "Ally Odometer Disclosure");
            fillPdf(dealerTrackData, contractDir + "Blank Ally Insurance Form.pdf", outputDir,
                    "Ally Insurance Form");
            fillPdf(dealerTrackData, contractDir + "Ally Title Guarantee.pdf", outputDir, "Guarantee of Title");
        }

        else {
            fillPdf(dealerTrackData, contractDir + "Blank Agreement to Furnish Insurance.pdf", outputDir,
                    "Chase Insurance Form");
            fillPdf(dealerTrackData, contractDir + "Chase Title Guarantee.pdf", outputDir,
                    "Guarantee of Title");
        }

        switch ((String) dealerTrackData.get("buyerState")) {
        case "CA":
            fillPdf(dealerTrackData, contractDir + "Blank Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        case "AZ":
            fillPdf(dealerTrackData, contractDir + "Blank AZ Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        case "TX":
            fillPdf(dealerTrackData, contractDir + "Blank TX Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        case "WA":
            fillPdf(dealerTrackData, contractDir + "Blank WA Purchase Contract-N-A'd out.pdf", outputDir,
                    "Purchase Contract");
            break;
        }

    } catch (NullPointerException e) {
        e.printStackTrace();
    }
}

From source file:LoginAcceptanceTests.java

License:Open Source License

@Test
public void testLogin() throws Exception {

    // Test failed login
    webDriver.get(baseUrl + "/login");

    webDriver.findElement(By.name("username")).sendKeys(userName);
    webDriver.findElement(By.name("password")).sendKeys("invalidpassword");
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();

    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Welcome!"));

    // Test successful login
    webDriver.findElement(By.name("username")).sendKeys(userName);
    webDriver.findElement(By.name("password")).sendKeys("password");
    webDriver.findElement(By.xpath("//input[@value='Sign in']")).click();

    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));

    // Test logout
    webDriver.get(baseUrl + "/logout.do");

    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Welcome!"));
}

From source file:SearchTest.java

@Test
public void test() throws InterruptedException {
    driver.get(baseUrl + "/samplecenter/faces/index.xhtml");
    driver.findElement(By.id("j_idt11:searchbar")).clear();
    driver.findElement(By.id("j_idt11:searchbar")).sendKeys("yolo");
    Thread.sleep(1000);//from ww  w.  ja v  a 2  s.c o m
    driver.findElement(By.name("j_idt11:j_idt12")).click();
    Thread.sleep(1000);
    assertEquals("1 results", driver.findElement(By.id("resultcount")).getText());

}

From source file:LoginScreenGrapheneTest.java

@Test
@RunAsClient/*  w  w w  .  j a  va2 s  . com*/
public void ShouldBePosibleToSearchTestowkaAtGoogle() throws InterruptedException {
    browser.get("http://google.pl");
    WebElement searchField = browser.findElement(By.name("q"));
    searchField.sendKeys("testowka.pl");
    WebElement searchButton = browser.findElement(By.id("sblsbb"));
    searchButton.click();
    for (int second = 0;; second++) {
        if (second >= 60)
            fail("timeout");
        try {
            if (browser.findElement(By.linkText("Testowka.pl")).isDisplayed()) {
                break;
            }
        } catch (Exception e) {
        }
        Thread.sleep(1000);
    }
    WebElement linkToTestowka = browser.findElement(By.linkText("Testowka.pl"));
    linkToTestowka.click();
}

From source file:SamlLoginAcceptanceTests.java

License:Open Source License

private void samlPhpLogin(String linkText) {
    webDriver.get(baseUrl + "/login");
    Assert.assertEquals("Cloud Foundry", webDriver.getTitle());
    webDriver.findElement(By.xpath("//a[text()='" + linkText + "']")).click();
    webDriver.findElement(By.xpath("//h2[contains(text(), 'Enter your username and password')]"));
    webDriver.findElement(By.name("username")).clear();
    webDriver.findElement(By.name("username")).sendKeys("marissa");
    webDriver.findElement(By.name("password")).sendKeys("koala");
    webDriver.findElement(By.xpath("//input[@value='Login']")).click();
    assertEquals("marissa@test.org",
            webDriver.findElement(By.xpath("//div[@class='dropdown-trigger']")).getText());
    assertThat(webDriver.findElement(By.cssSelector("h1")).getText(), Matchers.containsString("Where to?"));
}