Thursday 7 August 2014

Selenium web driver Action bot & Page Object



/*In action bot frame work, we can define each action in separately, Page Objects are a useful way of reducing duplication in your tests*\

                                                                                                                               Build.XML For ANT

package com.action;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

public class ActionBot {
    private WebDriver driver;
   
    public ActionBot(WebDriver driver)
    {
        this.driver = driver;
    }

    public void click(By locator)
    {
        (new WebDriverWait(driver, 90)).until
        (ExpectedConditions.visibilityOfElementLocated(locator));
        driver.findElement(locator).click();
    }
    public void browseclick(By locator, int index) throws IOException{
        (new WebDriverWait(driver, 30)).until
        (ExpectedConditions.visibilityOfElementLocated(locator));
        List<WebElement> browse = driver.findElements(locator);
        browse.get(index).click();
       
    }
    public void type(By locator, String value)
    {
        (new WebDriverWait(driver, 30)).until
        (ExpectedConditions.visibilityOfElementLocated(locator));
        WebElement element = driver.findElement(locator);
        element.clear();
        element.sendKeys(value);
    }

    public String getTitle(){
        return driver.getTitle();
        }
    public String getText(){
        String actual= driver.switchTo().alert().getText();
        return actual;
        }
    public void fileUpload(String filePath) throws IOException, InterruptedException
     {
      Runtime.getRuntime().exec(filePath);
      Thread.sleep(4000);
     }
    public int randomNumber(){
         Random rand = new Random();
            int  num = rand.nextInt(50) + 1;
            return num;
    }
     public String alertgetText()
     {
      return driver.switchTo().alert().getText();
         
      }
     public void alertAccept()
     {
      driver.switchTo().alert().accept();
         
      }
     public void typeFileUpload(By locator, String value)
     {
      (new WebDriverWait(driver, 30)).until
      (ExpectedConditions.visibilityOfElementLocated(locator));
      WebElement element = driver.findElement(locator);
      element.sendKeys(value);
     }
     public void clickByPresenceofelement(By locator)
        {
            (new WebDriverWait(driver, 90)).until
            (ExpectedConditions.presenceOfElementLocated(locator));
            driver.findElement(locator).click();
        }
     public String getTextForTextbox(By locator)
     {
         (new WebDriverWait(driver, 30)).until
            (ExpectedConditions.visibilityOfElementLocated(locator));
            WebElement element = driver.findElement(locator);
            return element.getText();
           
     }

}

/* Page object Model
/* For declaration of element using page Program-1

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.CacheLookup;
import org.openqa.selenium.support.FindBy;
public class login
{

    @FindBy(id="username")
    @CacheLookup
    private WebElement userIdBox;
   
    @FindBy(id="password")
    @CacheLookup
    private WebElement passwordBox;
   
    @FindBy(id="ipurl")
    @CacheLookup
    private WebElement logInButton;

    public WebElement getUserIdBox() {
        return userIdBox;
    }

    public WebElement getPasswordBox() {
        return passwordBox;
    }

    public WebElement getLogInButton() {
        return logInButton;
    }
    }
/* Driver script
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.PageFactory;
import org.testng.annotations.Test;
public class pageObjectMain
{
         WebDriver driver= new FirefoxDriver();
        @Test
        public void login()
        {
        loginC3dn login=PageFactory.initElements(driver,loginC3dn.class);
        driver.get("http://172.16.1.203:8080/C3DNA/renderEnterpriseView.html#");
        login.getLogInButton().sendKeys("ritesk");
        login.getPasswordBox().sendKeys("test");
        login.getUserIdBox().sendKeys("15885.132");
        }
   
}
Buy Websites
Tags:- Acceptance Testing Application programming interface assertEquals() Automation Automation testing Bug Bugs ChromeDriver Compatibility database testing Document Object Model Eclipse Exception handling Fitnesse Functional Testing getText() Google Chrome HTML Installation Testing Java JavaScript JDBC jQuery Manual testing Operating Systems Programming Quality assurance regression testing Requirement Selenium Selenium IDE Selenium RC Selenium Webdriver Software Testing SQL injection Test Case Test Cases testing TestNg Test Plan Unit testing Usability Web application Webdriver Xpath webdriver parallel execution selenium webdriver tutorial selenium explicit wait selenium ide download
andoid device androiddriver androidscreencast appium architecture css html-table hybrid app iosdriver iphonedriver junit maven native app qualitia regression approach screencast selendroid selenese selenium conference selenium project web app webdriver architecture webdriver wait webtable xpath

Mobile Automation


Powered By- selenium blogs Hitesh Singh 

No comments:

Post a Comment