资源简介
Selenium Webdriver使用已打开的浏览器
代码片段和文件信息
package webtest;
import org.openqa.selenium.firefox.FirefoxDriver;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import org.openqa.selenium.Capabilities;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.Command;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.DriverCommand;
import org.openqa.selenium.remote.HttpCommandExecutor;
import org.openqa.selenium.remote.Response;
import org.openqa.selenium.remote.internal.WebElementToJsonConverter;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
public class myFirefoxDriver extends FirefoxDriver{
private Capabilities mycapabilities;
public myFirefoxDriver(String localserverString sessionID){
mystartClient(localserver);
mystartSession(sessionID);
}
protected void mystartClient(String localserver) {
HttpCommandExecutor delegate = null ;
try {
URL driverserver = new URL(localserver);
delegate = new HttpCommandExecutor(driverserver);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
try {
// TODO: use a more intelligent way of testing if the server is ready.
delegate.getAddressOfRemoteServer().openConnection().connect();
super.setCommandExecutor(delegate);
System.out.println(“Connect to the existing browser“);
} catch (IOException e) {
System.out.println(e.getMessage());
System.out.println(“can not connect“ + delegate.getAddressOfRemoteServer() + “ and “ + delegate);
}
}
@Override
protected void startClient() {
// Do nothing
}
protected void mystartSession(String sessionID) {
if(!sessionID.isEmpty()){
super.setSessionId(sessionID);
}
Command command = new Command(super.getSessionId() DriverCommand.GET_CAPABILITIES);
Response response;
try {
response = super.getCommandExecutor().execute(command);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
System.out.println(“Can‘t use this Session“);
return;
}
Mapject> rawCapabilities = (Mapject>) response.getValue();
DesiredCapabilities returnedCapabilities = (DesiredCapabilities) super.getCapabilities();
if(returnedCapabilities == null){
returnedCapabilities = new DesiredCapabilities();
}
for (Map.Entryject> entry : rawCapabilities.entrySet()) {
// Handle the platform later
if (CapabilityType.PLATFORM.equals(entry.getKey())) {
continue;
}
returnedCapabilities.setCapability(entry.getKey() entry.getValue());
}
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 5565 2016-04-24 10:27 myFirefoxDriver.java
文件 2968 2016-04-24 11:18 readme.txt
文件 3407 2016-02-01 20:58 webtest01.jar
相关资源
- IEDriverServer.exe --64位
- selenium-ide-2.9.0.xpi
- Selenium IDE v2.9.1.1官方版
- WEBDRIVER 黑苹果英伟达显卡驱动 可去系
- SeleniumWebdriver自动化测试设计视频课程
- Selenium自动化测试实战.txt
- Biotransformation of selenium by seaweed Graci
-
selenium fr
amework design data driven testi -
Regulation of ex
pression and activity of se - 用expect 实现切换用户时自动输入密码
- selenium-ide-2.5.0工具
- selenium_ide-2.9.1完整版
- selenium IDE 2.9.1.1
- Firefox浏览器xpath插件webdriver_element_l
- geckodriver-v0.18.0-win64.zip
- geckodriver-v0.23.0
- selenium_ide-2.9.1-fx.rar
- selenium_ide-2.9.1.xpi
- selenium-server-2.48.0.zip
- selenium 2.53.1 for windows
评论
共有 条评论