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 REDIRECT(WebDriver driver, String fieldText) {

    try {/*from www .  j a va2 s. com*/
        String field = fieldText;

        driver.get(field);

        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

        resultDetails.setFlag(true);

    } catch (Exception e) {

        resultDetails.setFlag(false);
        resultDetails.setErrorMessage("URL is not redirected");
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void LITEUSERREGISTRATION(WebDriver driver, String fieldText, String value) {
    //Lite user registration

    try {/*from www.j ava2  s  . c  om*/
        driver.manage().deleteAllCookies();
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        driver.get(fieldText);

        String pwd = "Equipment1$";

        String phone = "";
        String Email = "";
        String Fname = value;
        String lname = "Test";
        String validation = "";
        long inc = Math.round(Math.random() * 100000); // generates 5 digit number.
        String ID = "@yahoo.in";

        Random random = new Random();
        long dphone = Math.round(random.nextFloat() * Math.pow(10, 12));

        Email = Fname + lname + inc + ID;

        driver.findElement(By.id("emailaddress")).sendKeys(Email);
        System.out.println(Email);

        phone = Long.toString(dphone);

        driver.findElement(By.id("firstname")).sendKeys(Fname);
        driver.findElement(By.id("lastname")).sendKeys(lname);
        driver.findElement(By.id("phone")).sendKeys(phone);
        driver.findElement(By.id("newPassword")).sendKeys(pwd);
        driver.findElement(By.id("confirmPassword")).sendKeys(pwd);
        driver.findElement(By.xpath("//button[text()='JOIN NOW']")).click();
        Thread.sleep(10000);

        //condition to check the email is already exist
        if (driver.findElements(By.xpath("//*[@class='error-txt']")).size() > 0) {

            //If the email" Email Address already exists"
            if (driver.findElement(By.xpath("//*[@class='error-txt']")).getText()
                    .contains("Email Address already exists in the system")) {
                inc = inc++;
                Email = Fname + lname + inc + "test" + ID;
                driver.findElement(By.id("emailaddress")).clear();
                driver.findElement(By.id("emailaddress")).sendKeys(Email);
                driver.findElement(By.xpath("//button[text()='JOIN NOW']")).click();
            }

            // If the phone number already exist
            if (driver.findElement(By.xpath("//*[@class='error-txt']")).getText()
                    .contains("Another user has the same daytime phone number")) {
                phone = phone + random.nextInt(9);
                driver.findElement(By.id("phone")).clear();
                driver.findElement(By.id("phone")).sendKeys(phone);
                driver.findElement(By.xpath("//button[text()='JOIN NOW']")).click();

            }
        }

        //Verifying that user is successfully registered
        WebDriverWait wait = new WebDriverWait(driver, 35);
        wait.until(ExpectedConditions
                .visibilityOfElementLocated(By.xpath("//*[@class='fa fa-user famember-icon']"))); //verifying the "Activate your membership" icon 
        System.out.println("Successfully Registered user with mail id: " + Email);
        EMAIL = Email;

        resultDetails.setFlag(true);

    }

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

        e.printStackTrace();

    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void NEWUSERREGISTRATION(WebDriver driver, String fieldText, String value) {
    //NEW user registration
    //Registration URL in FieldText field
    //AMP URL in value field 

    try {/*from   w  ww .  j av  a 2s .c o  m*/
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        String value1 = "Val";
        LITEUSERREGISTRATION(driver, fieldText, value1);

        driver.manage().deleteAllCookies();
        driver.navigate().refresh();

        driver.get(value);
        AMPLOGIN(driver, value);
        driver.findElement(By.linkText("Users")).click();
        driver.findElement(By.name("email")).sendKeys(EMAIL);
        driver.findElement(By.xpath("//input[@value='Search']")).click();
        String VerifyUser = driver.findElement(By.xpath("//input[@value='Search']/following::tr[3]/td[2]"))
                .getText();

        if (VerifyUser.equalsIgnoreCase(EMAIL))
            ;
        {

            System.out.println("User Verified");

        }
        resultDetails.setFlag(true);
    }

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

        resultDetails.setWarningMessage("Registration failed");

    }

}

From source file:com.java.AppTestType_18_11_2015.java

public void AGREETERMS(WebDriver driver) {
    try {//from w ww .  j a v a  2  s .  co  m
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        // System.out.println("size is:"+driver.findElements(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")).size());suman
        if (driver.findElements(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")).size() > 0) {
            driver.findElement(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']")).click();
            driver.findElement(By.xpath("//*[@class='btn btn-primary btn-group-justified' and @type='submit']"))
                    .click();
            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

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

From source file:com.java.AppTestType_18_11_2015.java

public boolean SEARCH_RESULT_COMPARISON(WebDriver driver) {
    try {/*  ww w. java 2 s . c o m*/
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        String msg = driver.findElement(By.id("e1SitesFound")).getText();
        driver.findElement(By.linkText("Source Site")).click();
        Thread.sleep(2500);

        if (msg.contains("Ritchie Bros"))
            driver.findElement(By.xpath("(//*[@id='site_id:RBA']/span[1]/input)[2]")).click();
        Thread.sleep(1500);
        if (msg.contains("SalvageSale"))
            driver.findElement(By.xpath("(//*[@id='site_id:SS']/span[1]/input)[2]")).click();

        Thread.sleep(5000);

        //String E1Count = driver.findElement(By.cssSelector("span.e1Count")).getText();//
        System.out.println("size1 issssssssssssssssssss: "
                + driver.findElements(By.xpath("(//*[@id='site_id:E1']/span[3])[2]")).size());
        String E1Count = driver.findElement(By.xpath("(//*[@id='site_id:E1']/span[3])[2]")).getText();
        System.out.println(E1Count);
        String EOCountt = E1Count.substring(E1Count.indexOf("(") + 1, E1Count.lastIndexOf(")"));
        Integer count1 = Integer.parseInt(EOCountt);
        System.out.println("count1 is: " + count1);

        Thread.sleep(5000);
        System.out.println("size2 isssssssssssssssssssssss" + driver.findElements(By.id("e1NumFound")).size());
        System.out.println(
                "size3 isssssssssssssssssssssss" + driver.findElements(By.id("e1ResultsFound")).size());
        String listingcount = driver.findElement(By.id("e1NumFound")).getText();
        String nextlistingcount = driver.findElement(By.id("e1ResultsFound")).getText();

        System.out.println(listingcount);
        System.out.println(nextlistingcount);
        //suman
        boolean lotDisplay = driver.findElement(By.id("e1NumFound")).isDisplayed();
        boolean eventDisplay = driver.findElement(By.id("e1ResultsFound")).isDisplayed();
        boolean auctionDisplay = driver.findElement(By.id("e1AuctionsFound")).isDisplayed();
        //System.out.println(nextlistingcount);
        String listingcount2 = "";
        int convlistingcount = 0;
        if (lotDisplay) {
            listingcount2 = listingcount.replace(",", "");
            convlistingcount = Integer.parseInt(listingcount2);
        }

        String nextlistingcount2 = "";
        int convnextlistingcount = 0;
        if (eventDisplay) {
            nextlistingcount2 = nextlistingcount.replace(",", "");
            convnextlistingcount = Integer.parseInt(nextlistingcount2);

        }

        String auctionCount = "";
        int auctionCount2 = 0;
        if (auctionDisplay) {
            auctionCount = driver.findElement(By.id("e1AuctionsFound")).getText().replace(",", "");
            auctionCount2 = Integer.parseInt(auctionCount);

        }

        System.out.println("lot count is: " + convlistingcount);
        System.out.println("event count is: " + convnextlistingcount);
        System.out.println("auction count is: " + auctionCount2);

        Integer myfinalcount = convlistingcount + convnextlistingcount + auctionCount2;
        String compfinalcount = String.valueOf(myfinalcount);

        System.out.println(count1);
        System.out.println(myfinalcount);

        if (count1 <= 0 || (!count1.equals(myfinalcount)))
            return false;

        else
            return true;

    } catch (Exception e) {
        return false;
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void MYOPERATION(WebDriver driver, String fieldText, String value) {
    //It is used where framework actions doesn't work 
    //We need to proviede SND<Text to enter> in the value fields to perform "Sendkeys"
    //We need to proviede CLK in the value fields to perform "Click"
    try {/*from www. j av  a2 s  . com*/
        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
        String f = fieldText;
        String oper = value;

        String attribute = f.substring(0, 3);
        String locator = f.substring(3, f.length());

        String operation = oper.substring(0, 3);
        String val = oper.substring(3, oper.length());

        if (operation.equalsIgnoreCase("CLK")) {
            switch (attribute) {
            case "IDI":
                driver.findElement(By.id(locator)).click();
                resultDetails.setFlag(true);
                break;
            case "XPH":
                driver.findElement(By.xpath(locator)).click();
                resultDetails.setFlag(true);
                break;
            case "LNK":
                driver.findElement(By.linkText(locator)).click();
                resultDetails.setFlag(true);
                break;
            case "PLK":
                driver.findElement(By.partialLinkText(locator)).click();
                resultDetails.setFlag(true);
                break;
            default:
                System.out.println("Invalid Locator attribute");
                break;
            }

        }

        else if (operation.equalsIgnoreCase("SND")) {

            switch (attribute) {
            case "IDI":
                driver.findElement(By.id(locator)).clear();
                driver.findElement(By.id(locator)).sendKeys(val);
                resultDetails.setFlag(true);
                break;
            case "XPH":
                driver.findElement(By.xpath(locator)).clear();
                driver.findElement(By.xpath(locator)).sendKeys(val);
                resultDetails.setFlag(true);
                break;
            case "LNK":
                driver.findElement(By.linkText(locator)).clear();
                driver.findElement(By.linkText(locator)).sendKeys(val);
                resultDetails.setFlag(true);
                break;
            default:
                System.out.println("Invalid Locator attribute");
                break;
            }

        } else if (operation.equalsIgnoreCase("MTE")) {
            switch (attribute) {
            case "IDI":
                new Actions(driver).moveToElement(driver.findElement(By.id(locator))).perform();
                break;
            case "XPH":
                new Actions(driver).moveToElement(driver.findElement(By.xpath(locator))).perform();
                resultDetails.setFlag(true);
                break;
            case "LNK":
                new Actions(driver).moveToElement(driver.findElement(By.linkText(locator))).perform();
                resultDetails.setFlag(true);
                break;
            default:
                System.out.println("Invalid Locator attribute");
                break;
            }

        } else if (operation.equalsIgnoreCase("SEL")) {
            switch (attribute) {

            case "XPH":
                new Select(driver.findElement(By.xpath(locator))).selectByVisibleText(val);
                resultDetails.setFlag(true);
                break;

            }

        }

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

From source file:com.java.AppTestType_18_11_2015.java

public void SIGNIN(WebDriver driver, String fieldText, String value) {

    try {/*  w ww  .  j a  va2s . c om*/

        try {
            WebDriverWait wait = new WebDriverWait(driver, 20);
            // wait.until(ExpectedConditions.titleIs("Used Equipment Sales | Buy & Sell Online | Ritchie Bros. EquipmentOne"));

            driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
            driver.manage().deleteAllCookies();
            //driver.findElement(By.linkText("Sign In")).click();
            driver.findElement(By.name("josso_username")).clear();
            driver.findElement(By.name("josso_username")).sendKeys(fieldText);
            driver.findElement(By.name("josso_password")).clear();
            driver.findElement(By.name("josso_password")).sendKeys("Equipment1$");
            try {
                driver.findElement(By.xpath("//*[@value='SIGN IN']")).click();
            } catch (Exception elementnotfoundexException) {
                driver.findElement(By.xpath("//button[text()='SIGN IN']")).click();
            }
            System.out.println("size is   :" + driver.findElements(By.id("iduser")).size());
            if (driver.findElements(By.id("iduser")).size() > 0) {
                System.out.println("1111111111");
                driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
                if (driver.findElements(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']"))
                        .size() > 0) {
                    driver.findElement(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']"))
                            .click();
                    driver.findElement(
                            By.xpath("//*[@class='btn btn-primary btn-group-justified' and @type='submit']"))
                            .click();
                    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                    // driver.findElement(By.xpath("//input[@value='Go to EquipmentOne']")).click();
                    //  wait.until(ExpectedConditions.titleIs("Used Equipment Sales | Buy & Sell Online | Ritchie Bros. EquipmentOne"));
                }
                //to confirm successful sign in as valid user,verifying the name displayed next to "Hello" text

                if (driver.findElement(By.id("iduser")).getText().equalsIgnoreCase(value))
                    System.out.println("Successfully Logged in");
                else {
                    driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                    driver.findElement(By.linkText("Sign Out")).click();
                    wait.until(ExpectedConditions.visibilityOfAllElementsLocatedBy(By.name("josso_password")));
                    driver.findElement(By.name("josso_username")).clear();
                    driver.findElement(By.name("josso_username")).sendKeys(fieldText);
                    driver.findElement(By.name("josso_password")).clear();
                    driver.findElement(By.name("josso_password")).sendKeys("Equipment1$");
                    driver.findElement(By.xpath("//*[@value='SIGN IN']")).click();
                    wait.until(ExpectedConditions.elementToBeClickable(By.id("iduser")));
                    //agree terms-This piece of code is to verify agree terms checkbox after re logging(not logged in as the valid user)
                    driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
                    if (driver.findElements(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']"))
                            .size() > 0) {
                        driver.findElement(By.xpath("//input[@id='useragreetoterms' and @type='checkbox']"))
                                .click();
                        driver.findElement(By
                                .xpath("//*[@class='btn btn-primary btn-group-justified' and @type='submit']"))
                                .click();
                        driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                        // driver.findElement(By.xpath("//input[@value='Go to EquipmentOne']")).click();
                        //  wait.until(ExpectedConditions.titleIs("Used Equipment Sales | Buy & Sell Online | Ritchie Bros. EquipmentOne"));
                    }

                }
                resultDetails.setFlag(true);
            }

        }

        //This catch is used to catch the error "You are NOT authorized to access Site" in E1 Login//
        /////////////////////////////////////
        catch (Exception e1) {

            driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
            if (driver.getPageSource().contains("You are NOT authorized to access Site")) {
                System.out.println("You are NOT authorized to access Site error message is displayed");
                driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
                driver.navigate().to("http://e1.dev.assetnation.com");
                SIGNIN(driver, fieldText, value);
            }

        }
    }

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

}

From source file:com.java.AppTestType_18_11_2015.java

public void SIGNOUT(WebDriver driver) {
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    try {//from www  .j  av a 2  s.  c  o m
        String url = driver.getCurrentUrl();
        String url2 = url.toUpperCase();
        //according to new to changes the following is not needed
        /*if(url2.contains("LISTINGID"))
        {
           driver.findElement(By.id("uname")).click();
           Thread.sleep(2000);
                   
        }*/

        driver.findElement(By.linkText("Sign Out")).click();
        if (driver.findElement(By.linkText("Sign In")).isDisplayed())
            resultDetails.setFlag(true);

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

From source file:com.java.AppTestType_18_11_2015.java

public void WAITFORTHIS(WebDriver driver, String fieldText, String value) {
    //Used to verify the text in any specific Loctor or Message
    //<XPH or LNK or IDI or TXT or MSG><Locator> in fieldText 
    //Time in milliseconds in Value
    try {/* ww w .j  a  v a  2 s .co m*/

        String f = fieldText;
        String time = value;
        String locatorType = f.substring(0, 3);
        String locatorValue = f.substring(3, f.length());
        int timevalue = Integer.parseInt(time);
        driver.manage().timeouts().implicitlyWait(timevalue, TimeUnit.MILLISECONDS);

        if (locatorType.equalsIgnoreCase("XPH")) {

            if (driver.findElements(By.xpath(locatorValue)).size() > 0)
                resultDetails.setFlag(true);
        } else if (locatorType.equalsIgnoreCase("LNK")) {

            if (driver.findElements(By.linkText(locatorValue)).size() > 0)
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) {

            if (driver.findElements(By.id(locatorValue)).size() > 0)
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("MSG")) {

            int j = 0;
            int t = timevalue / 1000;
            for (int i = 0; i < t; i++) {
                if (driver.findElement(By.xpath("//*[contains(text(),'" + locatorValue + "')]"))
                        .isDisplayed()) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("PLK")) {

            if (driver.findElements(By.partialLinkText(locatorValue)).size() > 0)
                resultDetails.setFlag(true);

        }

    }

    catch (Exception e) {
        resultDetails.setErrorMessage(fieldText + "Locator Not Found");
        resultDetails.setFlag(false);
        e.printStackTrace();
    }
}

From source file:com.java.AppTestType_18_11_2015.java

public void VERIFYTHIS(WebDriver driver, String fieldText, String value) {
    //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
    try {//  ww  w  .ja v a2s . 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))
                resultDetails.setFlag(true);
        } else if (locatorType.equalsIgnoreCase("LNK")) {

            if (driver.findElement(By.linkText(locatorValue)).getText().equalsIgnoreCase(val))
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("IDI") || locatorType.equalsIgnoreCase("TXT")) {

            if (driver.findElement(By.id(locatorValue)).getText().equalsIgnoreCase(val))
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("MSG")) {

            int j = 0;
            for (int i = 0; i < 20; i++) {
                if (driver.findElement(By.xpath("//*[contains(text(),'" + val + "')]")).isDisplayed()) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        }

        else if (locatorType.equalsIgnoreCase("TTL")) {
            int j = 0;
            for (int i = 0; i < 20; i++) {
                if (driver.getTitle().equalsIgnoreCase(val)) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        } else if (locatorType.equalsIgnoreCase("URL")) {
            int j = 0;
            for (int i = 0; i < 20; i++) {
                if (driver.getCurrentUrl().equalsIgnoreCase(val)) {
                    j = 1;
                    break;
                }
                Thread.sleep(1000);

            }
            if (j == 1)
                resultDetails.setFlag(true);

        }
    }

    catch (Exception e) {
        e.printStackTrace();
        resultDetails.setErrorMessage(
                fieldText + " Text is not matching with that of the locator (or) the locator not found");
        resultDetails.setFlag(false);
    }

}