Selenium webdriver操作日历控件

发表于:2015-2-02 10:33

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:to be crazy    来源:51Testing软件测试网采编

  其中:DriverFactory
package com.packt.webdriver.chapter3;
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.openqa.selenium.firefox.internal.ProfilesIni;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.os.WindowsUtils;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
public class DriverFactory {
public static WebDriver getHtmlUnit()
{
HtmlUnitDriver ht=new HtmlUnitDriver();
return ht;
}
public static WebDriver getChromeDriver() {
// TODO Auto-generated method stub
String chromdriver="E:\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", chromdriver);
ChromeDriverService.Builder builder=new  ChromeDriverService.Builder();
File file=new File(chromdriver);
//        int port=12643;
//        ChromeDriverService service=builder.usingDriverExecutable(file).usingPort(port).build();
//        try {
//            service.start();
//        } catch (IOException e) {
//            // TODO Auto-generated catch block
//            e.printStackTrace();
//        }
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File(""));
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
capabilities.setCapability("chrome.switches",
Arrays.asList("--start-maximized"));
options.addArguments("--test-type", "--start-maximized");
WebDriver driver=new ChromeDriver(options);
return driver;
}
public static WebDriver getFirefoxDriver()
{
try
{
WindowsUtils.tryToKillByName("firefox.exe");
}
catch(Exception e)
{
System.out.println("can not find firefox process");
}
File file=new File("d:\\firebug-2.0.4-fx.xpi");
FirefoxProfile profile = new FirefoxProfile();
//        profile.setPreference("network.proxy.type", 2);
//        profile.setPreference("network.proxy.autoconfig_url", "http://proxy.successfactors.com:8083");
//        profile.setPreference("network.proxy.no_proxies_on", "localhost");
//
//        profile.setPreference("network.proxy.http", "proxy.domain.example.com");
//        profile.setPreference("network.proxy.http_port", 8080);
//        profile.setPreference("network.proxy.ssl", "proxy.domain.example.com");
//        profile.setPreference("network.proxy.ssl_port", 8080);
//        profile.setPreference("network.proxy.ftp", "proxy.domain.example.com");
//        profile.setPreference("network.proxy.ftp_port", 8080);
//        profile.setPreference("network.proxy.socks", "proxy.domain.example.com");
//        profile.setPreference("network.proxy.socks_port", 8080);
try {
profile.addExtension(file);
profile.setPreference("extensions.firebug.currentVersion", "2.0.4");
profile.setPreference("extensions.firebug.allPagesActivation", "on");
} catch (IOException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
WebDriver driver = new FirefoxDriver(profile);
return driver;
}
public static WebDriver getIEDriver()
{
String IEDriverServer="E:\\IEDriverServer.exe";
System.setProperty("webdriver.ie.driver",IEDriverServer);
WebDriver driver=new InternetExplorerDriver();
return driver;
}
}
22/2<12
《2023软件测试行业现状调查报告》独家发布~

精彩评论

  • goodsecret
    2015-10-16 17:16:39

    留名收藏,太J了

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号