Example usage for org.openqa.selenium WebDriver manage

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

Introduction

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

Prototype

Options manage();

Source Link

Document

Gets the Option interface

Usage

From source file:com.java.AppTestType_18_11_2015.java

public void APPROVEUSER(WebDriver driver, String fieldText, String value) {
    //To Handle Approve User Popup 
    //FieldText---The User's FullName   and Value-----OK or Cancel
    try {/*from  ww w . j a va  2 s . co  m*/
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.findElement(By.linkText(fieldText)).click();
        Thread.sleep(2000);
        String parentwindow = driver.getWindowHandle();
        if (value.equalsIgnoreCase("OK")) {
            driver.findElement(By.linkText("Approve User")).click();
            Thread.sleep(2000);

            driver.switchTo().alert().accept();

            for (String win : driver.getWindowHandles()) {
                driver.switchTo().window(win);
                try {
                    driver.switchTo().alert().accept();
                } catch (NoAlertPresentException e) {
                    Robot robot = new Robot();
                    robot.keyPress(KeyEvent.VK_SPACE);
                    Thread.sleep(3000);
                }

            }
            Thread.sleep(20000);
            driver.switchTo().window(parentwindow);
            WebDriverWait wait = new WebDriverWait(driver, 20);
            wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("id_frm_Email_Address")));
            String Email = driver.findElement(By.id("id_frm_Email_Address")).getText();
            driver.findElement(By.name("email")).sendKeys(EMAIL);
            driver.findElement(By.xpath("//input[@value='Search']")).click();

            String Type = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();
            String Active_Status = driver
                    .findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]")).getText();
            String BStatus = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();
            String SStatus = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[6]"))
                    .getText();

            if (Type.equalsIgnoreCase("L") && Active_Status.equalsIgnoreCase("Active")
                    && BStatus.equalsIgnoreCase("Approved") && SStatus.equalsIgnoreCase("Approved")) {
                resultDetails.setFlag(true);
            }
        } else if (value.equalsIgnoreCase("CANCEL")) {
            driver.findElement(By.linkText("Approve User")).click();
            Thread.sleep(2000);
            //Robot robot = new Robot();
            // Simulate SPACE KEY press to click on OK button
            //robot.keyPress(KeyEvent.VK_ESCAPE);
            driver.switchTo().alert().dismiss();
            resultDetails.setFlag(true);

        }

    }

    catch (Exception e) {

        e.printStackTrace();
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void ADDINGTOWATCHLIST(WebDriver driver) {

    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    try {//from  ww w .j  a va 2s  . co  m
        if (driver.findElements(By.xpath(
                "(//i[@class='fa fa-binoculars fa-watchstack jswatchtitle' and contains(@data-original-title,'Click to remove from')])[1]"))
                .size() > 0)
            System.out.println("already there are some lots in watchlist section");
        else
            driver.findElement(By.xpath(
                    "(//i[@class='fa fa-binoculars fa-watchstack jswatchtitle' and contains(@data-original-title,'Click to add to')])[1]"))
                    .click();
        resultDetails.setFlag(true);
    }

    catch (Exception e) {

        e.printStackTrace();
        resultDetails.setErrorMessage("Element is checked");
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void SUBCATEGORYSELECTION(WebDriver driver, String fieldText, String value) {
    try {//  ww  w.java  2  s . c  o  m
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        String category = fieldText.substring(3, fieldText.length());
        String subcat = value.substring(3, value.length());
        new Actions(driver).moveToElement(driver.findElement(By.xpath(category))).perform();
        Thread.sleep(1500);
        try {
            driver.findElement(By.xpath(subcat)).click();
        } catch (Exception e1) {
            driver.findElement(By.xpath(category)).click();
            Thread.sleep(3000);
            new Actions(driver).moveToElement(driver.findElement(By.xpath(category))).perform();
            Thread.sleep(3000);
            driver.findElement(By.xpath(subcat)).click();
        }
        resultDetails.setFlag(true);
    } catch (Exception e2) {

        e2.printStackTrace();
        resultDetails.setErrorMessage("Unable to click on sub category");
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void BIDONOWNLOT(WebDriver driver, String fieldText, String value) {
    try {/*  w w  w.  ja v a 2s .co  m*/
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        AMPLOGIN(driver, value);
        driver.findElement(By.linkText("Lots")).click();
        Thread.sleep(4000);
        new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                .selectByVisibleText("EquipmentOne");
        new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                .selectByVisibleText("Approved");
        driver.findElement(By.xpath("//input[@name='find_button']")).click();
        driver.findElement(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a"))
                .click();
        String EQID = driver
                .findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]"))
                .getText();
        System.out.println("EQID is: " + EQID);
        driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Seller:']/../td[2]/a")).click();
        Thread.sleep(5000);
        String SellerMailID = driver.findElement(By.id("id_frm_Email_Address")).getAttribute("value");
        System.out.println("SellerMailID is: " + SellerMailID);
        AMPLOGOUT(driver);
        driver.get(fieldText);
        WebDriverWait wait = new WebDriverWait(driver, 30);

        driver.findElement(By.name("josso_username")).clear();
        driver.findElement(By.name("josso_username")).sendKeys(SellerMailID);
        driver.findElement(By.name("josso_password")).clear();
        driver.findElement(By.name("josso_password")).sendKeys("Equipment1$");
        driver.findElement(By.xpath("//*[@value='SIGN IN']")).click();
        Thread.sleep(4000);
        driver.findElement(By.id("search")).sendKeys(EQID);
        driver.findElement(By.xpath("//*[@id='main_search']/button")).click();
        Thread.sleep(4000);
        //driver.findElement(By.xpath("(//*[@name='makeoffer'])[2]")).click();

        driver.findElement(By.xpath("(//*[@name='makeoffer'])[2]")).sendKeys("99999999999");
        driver.findElement(By.xpath("(//*[contains(@value,'PLACE A BID')])[2]")).click();
        Thread.sleep(4000);
        driver.findElement(By.xpath("(//input[@class='form-control jsOfferInput e1ConfirmInput'])[2]"))
                .sendKeys("99999999999");
        driver.findElement(By.xpath("(//input[@class='btn btn-primary jsConfirmOffer'])[2]")).click();
        Thread.sleep(4000);
        if (driver.findElement(By.tagName("html")).getText()
                .contains("You are attempting to place a bid on a lot you own, this is not allowed."))
            resultDetails.setFlag(true);

    } catch (Exception e2) {

        e2.printStackTrace();
        resultDetails.setErrorMessage("something went wrong");
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void ALLEQUIPMENTPAGE(WebDriver driver) {
    try {/*  w  w  w. j ava2  s .c om*/
        try {
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.findElement(By.xpath(
                    "//*[contains(@class,'dropdown mega navBarText')]/a[starts-with(text(),'All Equipment')]"))
                    .click();
            System.out.println("clicked on All Equipment Link");
            resultDetails.setFlag(true);
        } catch (Exception e) {
            driver.navigate().to("http://e1.dev.assetnation.com/all-equipment");
            resultDetails.setFlag(true);
        }

    } catch (Exception e) {
        resultDetails.setFlag(false);
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public String FINDLOTID(WebDriver driver, String value) throws Exception {
    String EQID = null;/*from w  ww  .  j  a  va  2s  .  c  o m*/
    // try{
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    AMPLOGIN(driver, value);
    driver.findElement(By.linkText("Lots")).click();
    Thread.sleep(4000);
    new Select(driver.findElement(By.xpath("//select[@name='venueID']"))).selectByVisibleText("EquipmentOne");
    new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
            .selectByVisibleText("Approved");
    driver.findElement(By.xpath("//input[@name='find_button']")).click();
    driver.findElement(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a"))
            .click();
    EQID = driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]"))
            .getText();
    System.out.println("EQID is: " + EQID);
    driver.findElement(By.xpath("//*[@name='search_string']")).sendKeys(EQID);
    driver.findElement(By.xpath("//button[text()='Search']")).click();

    /*}
     catch(Exception e)
     {
        e.printStackTrace();
     }*/
    return EQID;

}

From source file:com.java.AppTestType_18_11_2015.java

public void SEARCHLOTINAMP(WebDriver driver, String fieldText, String value) {
    String EQID = null;/*from   w ww .  j  a v a  2s  . co m*/
    try {
        String AMPUrl = fieldText;
        String AMPPage = value.toUpperCase();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

        switch (AMPPage) {

        case "LOTS2":

            EQID = FINDLOTID(driver, AMPUrl);
            Thread.sleep(4000);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//*[text()='Lot Number:']/../td[2]/input")).sendKeys(EQID);
            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            if (driver
                    .findElement(
                            By.xpath("//*[@id='renderView']/table[2]/tbody/tr[1]/td[2]/table/tbody/tr[1]/td/a"))
                    .getText().contains(EQID))
                resultDetails.setFlag(true);
            break;

        case "HOME":
        case "LOTS":

            EQID = FINDLOTID(driver, AMPUrl);
            Thread.sleep(4000);
            driver.findElement(By.linkText(value)).click();
            Thread.sleep(2000);
            driver.findElement(By.xpath("//*[@name='search_string']")).sendKeys(EQID);
            driver.findElement(By.xpath("//button[text()='Search']")).click();
            if (driver.findElement(By.xpath("//td[@class='listdatabold' and text()='Lot Number:']/../td[4]"))
                    .getText().equalsIgnoreCase(EQID))
                resultDetails.setFlag(true);
            break;

        case "VENUE":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            int size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            for (int i = 1; i <= size; i++) {

                if (driver.findElement(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).getText()
                        .contains("(EQ"))
                    resultDetails.setFlag(true);

                else {
                    resultDetails.setFlag(false);
                    break;
                }
            }
            break;

        case "STATUS":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                    .selectByVisibleText("Approved");

            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            for (int i = 1; i < size * 2; i++) {

                if (driver.findElement(By
                        .xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i + "]/td[1]/table/tbody/tr[3]/td"))
                        .getText().equalsIgnoreCase("Approved")) {
                    resultDetails.setFlag(true);
                    i++;//because, there is one more empry row in table after each and every lot row. So we are skipping that empty row
                }

                else {
                    resultDetails.setFlag(false);
                    break;
                }
            }
            break;

        case "WITHOUTBUYITNOW":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                    .selectByVisibleText("Approved");
            System.out.println("is buy it now selected currently: "
                    + driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).isSelected());
            if (driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).isSelected())
                driver.findElement(By.xpath("(//*[@name='offerSrhBuyItNowAllowed'])[2]")).click();

            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
            for (int i = 1; i < size * 2; i++) {

                if (driver.findElements(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i
                        + "]/td[1]/table/tbody/tr[2]/td/img[contains(@src,'buyitnow')]")).size() == 0) {
                    resultDetails.setFlag(true);
                    i++; //because, there is one more empry row in table after each and every lot row. So we are skipping that empty row
                }

                else {
                    System.out.println("Lot displayed with BIN");
                    resultDetails.setFlag(false);
                    break;
                }
            }
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            break;

        case "WITHBUYITNOW":

            AMPLOGIN(driver, AMPUrl);
            driver.findElement(By.linkText("Lots")).click();
            Thread.sleep(4000);
            new Select(driver.findElement(By.xpath("//select[@name='venueID']")))
                    .selectByVisibleText("EquipmentOne");
            new Select(driver.findElement(By.xpath("//select[@name='offerSrhListingStatus']")))
                    .selectByVisibleText("Approved");
            if (driver.findElement(By.xpath("//*[@name='offerSrhBuyItNowAllowed']")).isSelected())
                driver.findElement(By.xpath("//*[@name='offerSrhBuyItNowAllowed']")).click();

            driver.findElement(By.xpath("//input[@name='find_button']")).click();
            size = driver.findElements(By.xpath("//a[contains(@href,'/o_details.cfm?id=')]")).size();
            for (int i = 1; i < size * 2; i++) {

                if (driver.findElements(By.xpath("//*[@id='renderView']/table[2]/tbody/tr[" + i
                        + "]/td[1]/table/tbody/tr[2]/td/img[contains(@src,'buyitnow')]")).size() == 1) {
                    resultDetails.setFlag(true);
                    i++; //because, there is one more empry row in table after each and every lot row. So we are skipping that empty row
                }

                else {
                    System.out.println("Lot displayed without BIN");
                    resultDetails.setFlag(false);
                    break;
                }
            }
            break;

        }
    } catch (Exception e) {
        System.out.println(e);
        resultDetails.setFlag(false);
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void SEARCHLOTINEQWITHEQID(WebDriver driver, String pagename) {
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
    try {/*from  ww  w. j a v  a 2s.c om*/

        Thread.sleep(5000);
        if (pagename.equalsIgnoreCase("LotDetailsPage"))
            eqid_1 = driver.findElement(By.xpath("//*[contains(text(),'Lot ID:')]/span")).getText();
        else if (pagename.equalsIgnoreCase("SEARCHRESULTPAGE"))
            eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText();
        else if (pagename.equalsIgnoreCase("HOMEPAGE")) {
            eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText();
            //moving to home page
            driver.findElement(By.xpath("//a/img[@class='logo-img img-responsive']")).click();
        } else if (pagename.equalsIgnoreCase("MYONEPAGE")) {
            eqid_1 = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]")).getText();
            //moving to home page
            driver.findElement(By.xpath("(//a[contains(text(),'MyONE')])[2]")).click();
        }
        Thread.sleep(5000);
        //searching with above lot id
        driver.findElement(By.id("search")).sendKeys(eqid_1);
        driver.findElement(By.xpath("//*[@id='main_search']/button")).click();
        WebDriverWait wait = new WebDriverWait(driver, 30);
        wait.until(ExpectedConditions.presenceOfElementLocated(
                By.xpath("(//div[@class='search-tags']/ul/li[text()='" + eqid_1 + "'])[2]")));

        String actual_eqid = driver.findElement(By.xpath("(//div[@class='rgbold jsLotID myone-black'])[4]"))
                .getText();
        //checking the size of search result elements, first 2 are invisible elements and each lot is having 2 more elements, so size should not exceed 4
        int size = driver.findElements(By.xpath("(//div[@class='rgbold jsLotID myone-black'])")).size();
        System.out.println("suman999999999999999999999999999999999999999999999999: " + size);
        if (size == 4 && actual_eqid.equalsIgnoreCase(eqid_1))
            resultDetails.setFlag(true);

    } catch (Exception e) {
        System.out.println(e);
        resultDetails.setFlag(false);
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void VERIFYTHIS_2(WebDriver driver, String fieldText, String value) throws Exception {
    //Used to verify the text in any specific Loctor or Message
    //<XPH or LNK or IDI or TXT><Locator> or MSG in fieldText 
    //Text or Message to be verified in Value
    int i = 0;//  ww w  .j  a va 2s  . c o  m
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS);
    String f = fieldText;
    String val = value;
    String locatorType = f.substring(0, 3);
    String locatorValue = f.substring(3, f.length());
    if (locatorType.equalsIgnoreCase("XPH")) {
        //System.out.println(driver.findElement(By.xpath(locatorValue)).getText());  
        if (driver.findElement(By.xpath(locatorValue)).getText().equalsIgnoreCase(val))
            i = 1;
    } else if (locatorType.equalsIgnoreCase("LNK")) {

        if (driver.findElement(By.linkText(locatorValue)).getText().equalsIgnoreCase(val))
            i = 1;

    }
    if (i == 0) {
        //resultDetails.setErrorMessage(fieldText+" Text is not matching with that of the locator (or) the locator not found");
        resultDetails.setErrorMessage(driver.findElement(By.xpath(locatorValue)).getText() + locatorValue);
        throw new Exception();
    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void WAITFORTHIS_2(WebDriver driver, String fieldText, String value) throws Exception {

    int i = 0;/*from  w w w.  ja  v a  2 s.  com*/
    driver.manage().timeouts().implicitlyWait(20, TimeUnit.MILLISECONDS);
    String f = fieldText;
    String val = value;
    String locatorType = f.substring(0, 3);
    String locatorValue = f.substring(3, f.length());
    if (locatorType.equalsIgnoreCase("XPH")) {

        if (driver.findElements(By.xpath(locatorValue)).size() > 0)
            i = 1;
    } else if (locatorType.equalsIgnoreCase("LNK")) {

        if (driver.findElements(By.linkText(locatorValue)).size() > 0)
            i = 1;
    }
    if (i == 0) {
        resultDetails.setErrorMessage(fieldText + "Locator Not Found");
        throw new Exception();
    }

}