Example usage for org.openqa.selenium WebDriver quit

List of usage examples for org.openqa.selenium WebDriver quit

Introduction

In this page you can find the example usage for org.openqa.selenium WebDriver quit.

Prototype

void quit();

Source Link

Document

Quits this driver, closing every associated window.

Usage

From source file:BallerinaEditorUITest.java

License:Open Source License

@Test(dataProvider = "getData")
public void openBallerinaFile(String fileName) throws IOException, InterruptedException,
        ParserConfigurationException, SAXException, TransformerException, URISyntaxException {

    //creating relevant browser webdriver
    //TODO make this generic for multiple browsers
    WebDriver driver = new FirefoxDriver();
    //opening base page - welcome page this case
    driver.get(TestConstants.SERVER_URL);
    //once the open button available click it
    waitAndGetElementByXpath(driver, TestConstants.WELCOME_PAGE_OPEN_BUTTON_XPATH).click();
    //fill the location of the ballerina file to be opened
    URL BallerinaResourceLocation = BallerinaEditorUITest.class
            .getResource(TestConstants.BALLERINA_RESOURCE_FOLDER + File.separator + fileName + ".bal");
    waitAndGetElementByXpath(driver, TestConstants.FILE_OPEN_POPUP_LOCATION_INPUT_XPATH)
            .sendKeys(BallerinaResourceLocation.getPath());
    //wait for the open button in the pop-up window
    waitAndGetElementByXpath(driver, TestConstants.FILE_OPEN_POPUP_LOCATION_OPEN_XPATH).click();
    //wait for the SVG element where the diagram is rendered
    WebElement domElement = waitAndGetElementByXpath(driver, TestConstants.SVG_XPATH);
    //Getting inner HTML of the SVG node
    String dom = TestUtils.preprocessDOMContent(domElement.getAttribute("innerHTML"));
    //TODO Add mechanism to generate DOM files
    //TestUtils.fileWriter(dom, fileName + "DOM.xml");
    URL DOMResourceLocation = BallerinaEditorUITest.class
            .getResource(TestConstants.DOM_RESOURCE_FOLDER + File.separator + fileName + "DOM.xml");
    //destroying browser instance
    driver.quit();
    //checking inner content of the DOM element
    assertEquals("Rendered diagram of " + fileName + "is not equal to the expected diagram",
            TestUtils.fileReader(DOMResourceLocation.getPath()), dom);
}

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;//  ww  w  .  j av  a2  s . c  om
    }

    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:IntegracaoIT.java

@Test
public void testSimple() throws Exception {
    // 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 NetBeans
    driver.get("http://www.netbeans.org");
    // Alternatively the same thing can be done like this
    // driver.navigate().to("http://www.netbeans.org");

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override//from   w  ww  .  ja  va  2 s  .  c  om
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:UnitTest1.java

public UnitTest1() throws InterruptedException {

    // Create a new instance of the Firefox driver

    String exePath = "C:\\Unit Testing\\Drivers\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    WebDriver driver = new ChromeDriver();

    //Launch the Online Store Website
    driver.get("http://www.store.demoqa.com");

    // Print a Log In message to the screen
    System.out.println("Successfully opened the website www.Store.Demoqa.com");

    //Wait for 5 Sec
    Thread.sleep(5);/*from   ww w.  java  2s .  c  om*/

    // Close the driver
    driver.quit();

}

From source file:UnitTest1.java

@Test
public void hello() {

    String exePath = "C:\\Unit Testing\\Drivers\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    WebDriver driver = new ChromeDriver();
    driver.get("http://www.store.demoqa.com");
    System.out.println("Successfully opened the website www.Store.Demoqa.com");
    driver.quit();

}

From source file:UnitTest1.java

@Test
public void comparisonfbTitle() throws InterruptedException {
    String exePath = "C:\\Unit Testing\\Drivers\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    WebDriver driver = new ChromeDriver();

    driver.get("https://www.facebook.com");

    String actualTitle = driver.getTitle();

    assertEquals("Facebook - Log In or Sign Up", actualTitle);

    Thread.sleep(5);/*from ww w  .  j  av  a2 s  .  c  om*/
    driver.quit();

}

From source file:UnitTest1.java

@Test
public void comparisonFBloginButton() throws InterruptedException {
    String exePath = "C:\\Unit Testing\\Drivers\\chromedriver.exe";
    System.setProperty("webdriver.chrome.driver", exePath);
    WebDriver driver = new ChromeDriver();

    driver.get("https://www.facebook.com");

    String actualTitle = "u_0_o";

    WebElement test = driver.findElement(By.id("u_0_o"));
    assertEquals(actualTitle, test.getAttribute("id"));
    Thread.sleep(5);/*from w  w w.  j av a 2  s.  c  o m*/
    driver.quit();

}

From source file:GeneralCookieDriver.java

License:Open Source License

public Integer conductTest(Browser browser, boolean privateBrowsing, int[] cookies, int numTrialsPerRun) {
    WebDriver driver = getWebDriver(browser, privateBrowsing);

    if (driver == null) {
        System.err.println("WebDriver could not be found for " + browser + " in "
                + (privateBrowsing ? "private" : "normal") + " mode.");
        return 0;
    }/*from ww w.  j a v a2 s.  co  m*/

    if (browser.equals(Browser.SAFARI) && privateBrowsing) {
        System.err.println("Pausing for 10 seconds...");
        try {
            Thread.sleep(10000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.err.println("Resuming from pause...");
    }

    for (int c = 0; c < cookies.length; c++) {

        for (int i = 0; i < numTrialsPerRun; i++) {

            driver.get(new String(cookieGeneratorLocation + "?numCookies=" + cookies[c] + "&browser="
                    + browser.toString() + "&mode=" + (privateBrowsing ? "private" : "normal")));

            try {
                new WebDriverWait(driver, 120).until(ExpectedConditions.titleContains("[ResultProvided]"));

            } catch (org.openqa.selenium.UnhandledAlertException e) {
                System.err.println("UnhandledAlertException");
                continue;
            } catch (Exception e) {
                e.printStackTrace();
                continue;
            }

            Integer result = new Integer(driver.getTitle().split(" ")[0]);

            System.out.println(
                    browser.toString() + (privateBrowsing ? ",P," : ",N,") + cookies[c] + "," + result);
        }
    }

    //Close the browser
    driver.quit();

    return 0;
}

From source file:NewSeleneseIT.java

@Test
public void testSimple() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.
    System.setProperty("webdriver.gecko.driver", "/home/klaudia/geckodriver");
    WebDriver driver = new FirefoxDriver();

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

    // Check the title of the page
    // Wait for the page to load, timeout after 10 seconds
    (new WebDriverWait(driver, 10)).until(new ExpectedCondition<Boolean>() {
        @Override//  w ww. j a va  2  s. c  om
        public Boolean apply(WebDriver d) {
            return d.getTitle().contains("NetBeans");
        }
    });

    //Close the browser
    driver.quit();
}

From source file:SmokeTester_UnitTest.java

public void executeSmokeTest() throws Exception {
    // Create a new instance of the Firefox driver
    // Notice that the remainder of the code relies on the interface, 
    // not the implementation.

    System.setProperty("webdriver.chrome.driver", "C:\\Nino\\ChromeWebDriver\\chromedriver.exe");
    WebDriver driver = new ChromeDriver();

    TestCaseReader tcreader = new TestCaseReader();
    List<TestScriptTemplate> tcl = tcreader.readExcel();

    List<TestScriptTemplate> validatedTestScript = new ArrayList();

    String log_execution = "";
    Iterator<TestScriptTemplate> i = tcl.iterator();
    while (i.hasNext()) {
        TestScriptTemplate testscript = i.next();
        //collect the results
        TestScriptTemplate testexecution = new TestScriptTemplate();

        testexecution.setAppCode(testscript.getAppCode());
        log_execution = log_execution + "\nStart smoke testing for application code: "
                + testexecution.getAppCode();

        //access the URL
        driver.get(testscript.getAppURL());

        //login if not yet
        if (driver.getCurrentUrl().contains("identity.safeway.com")) {
            //key in userid and password
            WebElement weusername = driver.findElement(By.id("username"));
            //System.out.println("tag:" + weusername.getTagName());
            weusername.sendKeys(testscript.getAppUserID());

            WebElement wepassword = driver.findElement(By.id("password"));
            //System.out.println("tag:" + wepassword.getTagName());
            wepassword.sendKeys(testscript.getAppPassword());

            WebElement weloginform = driver.findElement(By.name("loginData"));
            //System.out.println("tag:" + weloginform.getTagName());
            weloginform.submit();/* ww  w  . j av a 2  s.c o m*/
            log_execution = log_execution + " Login Successful";
        }

        //recoding URL; required so no need to check for nullity
        testexecution.setAppURL(driver.getCurrentUrl());
        log_execution = log_execution + " Current URL: " + driver.getCurrentUrl();
        //recoding title; required so no need to check for nullity
        testexecution.setHomePageTitle(driver.getTitle());
        log_execution = log_execution + " Page Title: " + driver.getTitle();

        if (isElementExist(testscript.getHomePageElementType(), testscript.getHomePageElement(), driver)) {
            System.out.println("Element match!" + testscript.getHomePageElement());
            log_execution = log_execution + " Home Page Element validation...";
            testexecution.setHomePageElement(testscript.getHomePageElement());
        } else {
            testexecution.setHomePageElement("not found");
        }

        //next page validation
        if (!testscript.getLevel1URL().isEmpty() || !testscript.getLevel1URL().equals("")) {
            //go to next level page
            driver.get(testscript.getLevel1URL());
            log_execution = log_execution + " Next Page validation URL: " + testscript.getLevel1URL();

            testexecution.setLevel1URL(driver.getCurrentUrl());
            System.out.println("execution log: current level 1 URL on set" + testexecution.getLevel1URL());

            if (!testscript.getLevel1PageTitle().isEmpty() || !testscript.getLevel1PageTitle().equals("")) {
                testexecution.setLevel1PageTitle(driver.getTitle());
                log_execution = log_execution + " Next Page title validation: " + driver.getTitle();
            }

            if (isElementExist(testscript.getLevel1ElementType(), testscript.getLevel1Element(), driver)) {
                testexecution.setLevel1Element(testscript.getLevel1Element());
                log_execution = log_execution + " Next Page element validation: "
                        + testscript.getLevel1Element();
            } else {
                testexecution.setLevel1Element("not found");
            }

        }
        testexecution.setLogs(log_execution);
        SmokeTestValidator_UnitTest testvalidator = new SmokeTestValidator_UnitTest(testscript);
        TestScriptTemplate testingresult = testvalidator.getTestResult(testexecution);
        validatedTestScript.add(testingresult);

    }

    tcreader.writetoExcel(validatedTestScript);
    //Close the browser
    driver.quit();
    //return log_execution;
}