我将硒用于chromeDriver的端到端测试。要测试的网站需要ssl证书。手动打开浏览器时,会弹出一个窗口,供我选择已安装的证书。不同的测试访问不同的URL,并且还需要不同的证书。但是,如果我以无头模式运行测试,则不会弹出窗口。因此,我需要一种以编程方式设置.pem要用于当前测试的证书(例如,设置文件)的方法。
我该如何实现?我尝试设置一个browserMob代理,然后将其配置为selenium中的代理-但是,这似乎没有任何作用...是否有更好的方法?我究竟做错了什么?这是我尝试过的:
PemFileCertificateSource pemFileCertificateSource = new PemFileCertificateSource(
new File("myCertificate.pem"),
new File("myPrivateKey.pem"),
"myPrivateKeyPassword");
ImpersonatingMitmManager mitmManager = ImpersonatingMitmManager.builder()
.rootCertificateSource(pemFileCertificateSource)
.build();
BrowserMobProxy browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.setTrustAllServers(true);
browserMobProxy.setMitmManager(mitmManager);
browserMobProxy.start(8080);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setProxy(ClientUtil.createSeleniumProxy(browserMobProxy));
WebDriver webDriver = new ChromeDriver(chromeOptions);
// use the webdriver for tests, e.g. assertEquals("foo", webDriver.findElement(...))
Run Code Online (Sandbox Code Playgroud) java selenium ssl-certificate selenium-webdriver browsermob-proxy
我正在尝试通过 selenium 将 VPN 连接作为 chrome 扩展与 Hola 进行交互。它被读入并且浏览器使用 chrome 扩展程序呈现,但是我想向 netflix 发出 get 请求并存储所有 IP。如何发出获取请求并使用 Hola 更改列表中每个国家/地区的 IP?
谢谢。
from browsermobproxy import Server
import os, pdb
from selenium import webdriver
def bootServer():
server = Server("/Users/Desktop/browsermob-proxy-2.1.2/bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()
return proxy, server
def bootDriver(proxy):
chrome_options = webdriver.ChromeOptions()
chrome_options.add_extension('/Users/Desktop/extension.crx')
chrome_options.add_argument("--proxy-server={0}".format(proxy.proxy))
driver = webdriver.Chrome(chrome_options = chrome_options, executable_path = os.getcwd() + "/chromedriver")
return driver
def getCountryCodes():
data = []
with open("countryCodes.txt") as f:
content = f.readlines()
for cc in content:
data.append(cc.strip())
return …Run Code Online (Sandbox Code Playgroud) python selenium google-chrome selenium-webdriver browsermob-proxy
我使用 selenium 3.0.2 和 browsermob proxy 0.7.1 来捕获网络数据。我得到的只是一个空的 JSON。我的代码是:
server = Server("/Users/dev/Downloads/browsermob-proxy-2.1.2/bin/browsermob-proxy")
server.start()
proxy = server.create_proxy()
if browser is None:
profile = webdriver.FirefoxProfile()
profile.set_preference("browser.privatebrowsing.autostart", True)
browser = webdriver.Firefox(firefox_profile=profile, proxy=proxy.selenium_proxy())
proxy.new_har("google", options={'captureHeaders': True, 'captureContent': True})
browser.get("https://google.com/")
print(proxy.har)
Run Code Online (Sandbox Code Playgroud)
我得到的只是这个空的 JSON
{'log': {'pages': [{'id': 'google', 'comment': '', 'pageTimings': {'comment': ''}, 'startedDateTime': '2016-12-01T14 :23:24.984-05:00', '标题': 'google'}], '条目': [], '版本': '1.2', '创建者': {'评论': '', '名称' : 'BrowserMob 代理', '版本': '2.1.2'}, '评论': ''}}
python selenium selenium-webdriver browsermob browsermob-proxy
我使用Chrome 59 beta版以无头模式编写了一个简单的安全测试网站的Selenium测试(打开页面)。
执行代码时出现以下异常。初始化驱动程序时抛出异常
当我在注释无头选项(options.addArguments(“ headless”))后重新运行脚本时,它显示Chrome并运行良好,但我的目标是以无头方式运行它。您能否提供解决我的问题的想法?
例外:在端口4971上启动ChromeDriver 2.29.461585(0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b)仅允许本地连接。线程“主” org.openqa.selenium.WebDriverException中的异常:未知错误:Chrome无法启动:异常退出(驱动程序信息:chromedriver = 2.29.461585(0be2cd95f834e9ee7c46bcc7cf405b483f5ae83b),平台= Mac OS X 10.12.2 x86_64)(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:60.14秒构建信息:版本:'3.4.0',修订版:'未知',时间:'未知'
步骤如下:在Mac上,我将Scala与SBT一起使用。Chrome 59 beta版ChromeDrive 2.29发布版本。
添加了以下依赖
Scala代码:
val username = "username"
val password = "password"
val domainname = "yoursecuredomain.com"
val browserMobProxyServer = new BrowserMobProxyServer()
browserMobProxyServer.start(0)
browserMobProxyServer.autoAuthorization(domainname, username, password, AuthType.BASIC)
val seleniumProxy = ClientUtil.createSeleniumProxy(browserMobProxyServer)
val options = new ChromeOptions()
options.addArguments("headless")
options.addArguments("--disable-gpu")
options.setBinary("""/Applications/Google Chrome.app/Contents/MacOS/Google Chrome""")
val desiredCapabilities = new DesiredCapabilities()
desiredCapabilities.setCapability(ChromeOptions.CAPABILITY, options)
desiredCapabilities.setCapability(CapabilityType.PROXY, seleniumProxy)
val driver: WebDriver …Run Code Online (Sandbox Code Playgroud) 我正在使用此代码将浏览器mob代理与maven依赖项net.lightbody.bmp集成browsermob-core 2.1.5
它根本没有捕获网络请求,我得到了这种har文件:
{
"log":{
"version":"1.2",
"creator":{
"name":"BrowserMob Proxy",
"version":"2.1.0-beta-6-littleproxy",
"comment":""
},
"pages":[
{
"id":"11",
"startedDateTime":"2017-10-26T17:28:42.501+05:30",
"title":"11",
"pageTimings":{
"comment":""
},
"comment":""
}
],
"entries":[],
"comment":""
}
}
Run Code Online (Sandbox Code Playgroud)
package lenskart.tests;
import java.io.File;
import java.net.UnknownHostException;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.Proxy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.CapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.testng.annotations.Test;
import net.lightbody.bmp.BrowserMobProxyServer;
import net.lightbody.bmp.client.ClientUtil;
import net.lightbody.bmp.mitm.manager.ImpersonatingMitmManager;
import net.lightbody.bmp.proxy.CaptureType;
public class ProxyTestClass {
@Test
public static void main() throws Exception {
// TODO Auto-generated method stub
BrowserMobProxyServer browserMobProxy = new BrowserMobProxyServer();
browserMobProxy.setTrustAllServers(true); …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Selenium,Webdriver io和browsermob代理在har文件中记录网络流量
var webdriverio = require('webdriverio');
var Proxy = require('browsermob-proxy').Proxy
, fs = require('fs')
, proxy = new Proxy()
;
proxy.cbHAR('scratchpads.eu', doSeleniumStuff, function(err, data) {
console.log('running cb')
if (err) {
console.error('ERR: ' + err);
} else {
fs.writeFileSync('stuff.har', data, 'utf8');
}
});
const opts = {
desiredCapabilities: {
browserName: 'chrome',
},
host: 'localhost',
port: '4444',
protocol: 'http',
coloredLogs: true,
}
function doSeleniumStuff(proxy, cb) {
var browser = webdriverio.remote(opts);
browser
.init()
.url('http://scratchpads.eu')
.getTitle().then(function(title) {
console.log('Title was: ' + title);
})
.end().then(cb).catch(e …Run Code Online (Sandbox Code Playgroud) I parse website 'http://ok.ru'. To get data from the post request I need to send a specific token that is generated by Javascript on the website and this token is contained in headers.
So I thought maybe one solution would be to open the website, let it generate token, grab headers and that's it.
One tool that can implement Java scripts is Selenium, however, to get headers I need to use brosermob-proxy (or equivalent). That is where I'm …
python-2.7 har selenium-webdriver browsermob browsermob-proxy
我正在尝试使用BMP的RequestFilter和ResponseFilter获得响应和请求.但是,当加载网页时,控制台中不会打印任何内容.
其他一切似乎都有效.也许BMP不是在看GeckoDriver?
我使用的是Firefox 50.0,BrowserMobProxy 2.1.2,Selenium 3.0.1和GeckoDriver 0.11.1
.测试代码如下.有人可以帮帮我吗?
非常感谢你!
BrowserMobProxy server = new BrowserMobProxyServer();
server.enableHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);
server.start();
int port = server.getPort();
server.addRequestFilter((request, content, info) -> {
String q = URLDecoder.decode(info.getOriginalUrl(), "UTF-8");
System.out.println("Request: "+q);
return null;
});
server.addResponseFilter((response, content, info) -> {
String type = response.headers().get("Content-Type");
System.out.println("Response: "+info.getOriginalRequest());
System.out.println(type);
});
Proxy proxy = ClientUtil.createSeleniumProxy(server);
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(CapabilityType.PROXY, proxy);
capabilities.setCapability("marionette", true);
capabilities.setCapability(CapabilityType.ACCEPT_SSL_CERTS, true);
capabilities.setCapability(CapabilityType.SUPPORTS_JAVASCRIPT, true);
FirefoxProfile fp = new FirefoxProfile();
capabilities.setCapability(FirefoxDriver.PROFILE, fp);
String gecko = "d:/Programming/java/geckodriver.exe";
System.setProperty("webdriver.gecko.driver", gecko);
driver = …Run Code Online (Sandbox Code Playgroud) 在问这个时我可能显得天真.对于我们的一些测试场景,我需要检索各种HTTP代码.现在我知道Selenium无法独自完成,我们必须使用第三方资源 - 可能是像Browsermob这样的代理.
有没有人已经在这方面工作过.我已经经历了各种教程 - 比如这里的一个,但我似乎无法使用它来解决这个问题.
我使用该pip方法安装了Browsermob ,因此我将路径作为
from browsermobproxy import Server
server = Server('/usr/local/lib/python3.4/dist-packages/browsermobproxy')
Run Code Online (Sandbox Code Playgroud)
但是,我收到了例外
Exception: Browsermob-Proxy binary couldn't be found in path provided: /usr/local/lib/python3.4/dist-packages/browsermobproxy
Run Code Online (Sandbox Code Playgroud)
我的问题是 - 有什么 - 我可能在这里找不到任何文件?我是否需要下载任何其他文件或我的路径不正确?
selenium ×5
java ×3
python ×3
browsermob ×2
automation ×1
beta ×1
firefox ×1
geckodriver ×1
har ×1
headless ×1
node.js ×1
proxy ×1
python-2.7 ×1
webdriver-io ×1