skip to main | skip to sidebar

Java Programs and Examples with Output

Pages

▼
 
  • RSS
  • Twitter
Monday, September 17, 2012

Automation with java Selenium

Posted by Admin at 11:44 AM – 0 comments
 

we can write functional test cases using selenium in java for automation


import java.util.Collection;

import org.openqa.selenium.By;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.Proxy.ProxyType;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;

import com.googlecode.fightinglayoutbugs.FightingLayoutBugs;
import com.googlecode.fightinglayoutbugs.LayoutBug;
import com.googlecode.fightinglayoutbugs.WebPage;

public class Test {
 public static void main(String[] args) {
  Proxy proxy = new Proxy();
  proxy.setProxyType(ProxyType.MANUAL);
  proxy.setHttpProxy("localhost:8080");
  proxy.setSslProxy("localhost:8080");
  proxy.setFtpProxy("localhost:8080");
  proxy.setNoProxy("localhost,127.0.0.1");

  //End Proxy Settings

  //Auto Configure Firefox Download folder for Excel Type
  FirefoxProfile firefoxProfile = new FirefoxProfile();
  firefoxProfile.setPreference("browser.download.folderList",2);
  firefoxProfile.setPreference("browser.download.manager.showWhenStarting",false);
  firefoxProfile.setPreference("browser.helperApps.neverAsk.saveToDisk","application/vnd.ms-excel");  
  DesiredCapabilities dc = DesiredCapabilities.firefox();
  dc.setCapability(CapabilityType.PROXY, proxy);
  firefoxProfile.setProxyPreferences(proxy);
  WebDriver driver =new FirefoxDriver(firefoxProfile);

  String userNames[] = {};
  String passwords[] = {};
  int i=0;
  driver.get("http://localhost/authentication/login.jsf");
  driver.findElement(By.id("_id166:username")).sendKeys(userNames[i]);
  driver.findElement(By.id("_id166:password")).sendKeys(passwords[i]);
  driver.findElement(By.id("_id166:submitLogin")).click();
  try{
   Test.wait(driver, "next Page title");
  }
  catch(Exception ex){ex.printStackTrace();}

  public static void wait(WebDriver driver,final String pageTitle)
  {
   (new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
    public Boolean apply(WebDriver d) {
     return d.getTitle().toLowerCase().startsWith(pageTitle);
    }});
  }

 }



Leave a Reply

Newer Post Older Post
Subscribe to: Post Comments ( Atom )
  • Popular
  • Recent
  • Archives
Powered by Blogger.
 
 
 
© 2011 Java Programs and Examples with Output | Designs by Web2feel & Fab Themes

Bloggerized by DheTemplate.com - Main Blogger