3

我想在我的 webdriverio 应用程序中启用 SOCKSv5 身份验证。但是,它目前似乎不起作用。

到目前为止,我已经尝试了以下配置:

  1. 使用firefox-profile手动设置如下:
fp.setProxy({ 
    proxyType: 'manual', 
    socksProxy: `127.0.0.1:1080`,
    socksUsername: 'myuser',
    socksPassword: 'mypass'
});

这似乎不起作用,因为页面根本无法加载。

  1. 使用FoxyProxy

我尝试使用它的 api 设置 url:

proxy:host=${proxy}&port=1080&isSocks=true&enabled=true&username=myuser&password=mypass

这给了我一个警告,有些东西正在访问它的配置,因此拒绝了请求。

创建自定义 Firefox 配置文件然后加载该配置文件不起作用,因为我必须在应用程序运行时编辑代理。

  1. 使用以下配置更新 selenium (3.3) 和 geckodriver (1.15)
requiredCapabilities: {
    proxy:{
        proxyType: 'manual',
        socksProxy: '127.0.0.1',
        socksProxyPort: 1080,
        socksVersion: 5,
        socksUsername: "mine",
        socksPassword: "mine"
    }
}

或者

desiredCapabilities: {
    proxy:{
        proxyType: 'manual',
        socksProxy: '127.0.0.1',
        socksProxyPort: 1080,
        socksVersion: 5,
        socksUsername: "mine",
        socksPassword: "mine"
    }
}

但是似乎都没有工作,还尝试将代理作为 JSON.stringify(proxyObj) 而不是直接对象传递。

我按如下方式运行整个堆栈:

var options = { 
    desiredCapabilities: {
        browserName: 'firefox',
        proxy:{
            proxyType: 'manual',
            socksProxy: '127.0.0.1',
            socksProxyPort: 1080,
            socksVersion: 5,
            socksUsername: "mine",
            socksPassword: "mine"
        }
    }
};

var client = webdriverio.remote(options);
client
    .init()   
    .url('http://whatsmyip.org/')
    .end();

有没有人遇到过解决方案?

日志

D:\Users\Maxim\Desktop\test>java -jar -Dwebdriver.geckodriver.driver="D:\Users\Maxim\Desktop\test\geckodriver.exe --log debug" selenium-server-standalone-3.3.0.jar
19:18:25.855 INFO - Selenium build info: version: '3.3.0', revision: 'b526bd5'
19:18:25.855 INFO - Launching a standalone Selenium Server
2017-03-13 19:18:25.875:INFO::main: Logging initialized @204ms to org.seleniumhq.jetty9.util.log.StdErrLog
19:18:25.915 INFO - Driver class not found: com.opera.core.systems.OperaDriver
19:18:25.915 INFO - Driver provider com.opera.core.systems.OperaDriver registration is skipped:
Unable to create new instances on this machine.
19:18:25.917 INFO - Driver class not found: com.opera.core.systems.OperaDriver
19:18:25.917 INFO - Driver provider com.opera.core.systems.OperaDriver is not registered
19:18:25.923 INFO - Driver provider org.openqa.selenium.safari.SafariDriver registration is skipped:
 registration capabilities Capabilities [{browserName=safari, version=, platform=MAC}] does not match the current platform WIN10
2017-03-13 19:18:25.961:INFO:osjs.Server:main: jetty-9.2.20.v20161216
2017-03-13 19:18:25.988:INFO:osjsh.ContextHandler:main: Started o.s.j.s.ServletContextHandler@1bce4f0a{/,null,AVAILABLE}
2017-03-13 19:18:26.110:INFO:osjs.AbstractConnector:main: Started ServerConnector@4bec1f0c{HTTP/1.1,[http/1.1]}{0.0.0.0:4444}
2017-03-13 19:18:26.111:INFO:osjs.Server:main: Started @440ms
19:18:26.112 INFO - Selenium Server is up and running
19:18:33.003 INFO - SessionCleaner initialized with insideBrowserTimeout 0 and clientGoneTimeout 1800000 polling every 180000
19:18:33.027 INFO - Executing: [new session: Capabilities [{rotatable=true, proxy={socksUsername=mine, socksPassword=mine, socksVersion=5, proxyType=manual, socksProxyPort=1080, socksProxy=127.0.0.1}, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@32b33674, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.6.2, url=http://webdriver.io}}]])
19:18:33.035 INFO - Creating a new session for Capabilities [{rotatable=true, proxy={socksUsername=mine, socksPassword=mine, socksVersion=5, proxyType=manual, socksProxyPort=1080, socksProxy=127.0.0.1}, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@32b33674, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, requestOrigins={name=webdriverio, version=4.6.2, url=http://webdriver.io}}]
1489429113379   geckodriver     INFO    Listening on 127.0.0.1:2577
1489429113929   mozprofile::profile     INFO    Using profile path C:\Users\Maxim\AppData\Local\Temp\rust_mozprofile.RTu9x3vDqRxG
1489429113933   geckodriver::marionette INFO    Starting browser C:\Program Files\Firefox Developer Edition\firefox.exe with args []
1489429113939   geckodriver::marionette INFO    Connecting to Marionette on localhost:37915
[GPU 12472] WARNING: pipe error: 109: file c:/builds/moz2_slave/m-aurora-w64-ntly-000000000000/build/src/ipc/chromium/src/chrome/common/ipc_channel_win.cc, line 346
1489429115925   Marionette      INFO    Listening on port 37915
19:18:36.041 WARN - Exception thrown
java.util.concurrent.ExecutionException: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
System info: host: 'MY-PC', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: driver.version: unknown
        at java.util.concurrent.FutureTask.report(Unknown Source)
        at java.util.concurrent.FutureTask.get(Unknown Source)
        at org.openqa.selenium.remote.server.DefaultSession.execute(DefaultSession.java:183)
        at org.openqa.selenium.remote.server.DefaultSession.<init>(DefaultSession.java:119)
        at org.openqa.selenium.remote.server.DefaultSession.createSession(DefaultSession.java:95)
        at org.openqa.selenium.remote.server.DefaultDriverSessions.newSession(DefaultDriverSessions.java:131)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:59)
        at org.openqa.selenium.remote.server.handler.NewSession.handle(NewSession.java:36)
        at org.openqa.selenium.remote.server.rest.ResultConfig.handle(ResultConfig.java:111)
        at org.openqa.selenium.remote.server.JsonHttpCommandHandler.handleRequest(JsonHttpCommandHandler.java:190)
        at org.openqa.selenium.remote.server.DriverServlet.handleRequest(DriverServlet.java:222)
        at org.openqa.selenium.remote.server.DriverServlet.doPost(DriverServlet.java:184)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:707)
        at org.openqa.selenium.remote.server.DriverServlet.service(DriverServlet.java:150)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
        at org.seleniumhq.jetty9.servlet.ServletHolder.handle(ServletHolder.java:841)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doHandle(ServletHandler.java:543)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:188)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doHandle(ContextHandler.java:1228)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:168)
        at org.seleniumhq.jetty9.servlet.ServletHandler.doScope(ServletHandler.java:481)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.nextScope(ScopedHandler.java:166)
        at org.seleniumhq.jetty9.server.handler.ContextHandler.doScope(ContextHandler.java:1130)
        at org.seleniumhq.jetty9.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
        at org.seleniumhq.jetty9.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
        at org.seleniumhq.jetty9.server.Server.handle(Server.java:564)
        at org.seleniumhq.jetty9.server.HttpChannel.handle(HttpChannel.java:320)
        at org.seleniumhq.jetty9.server.HttpConnection.onFillable(HttpConnection.java:251)
        at org.seleniumhq.jetty9.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:279)
        at org.seleniumhq.jetty9.io.FillInterest.fillable(FillInterest.java:112)
        at org.seleniumhq.jetty9.io.ChannelEndPoint$2.run(ChannelEndPoint.java:124)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:672)
        at org.seleniumhq.jetty9.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:590)
        at java.lang.Thread.run(Unknown Source)
Caused by: org.openqa.selenium.WebDriverException: java.lang.reflect.InvocationTargetException
Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
System info: host: 'MY-PC', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: driver.version: unknown
        at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:89)
        at org.openqa.selenium.remote.server.FirefoxDriverProvider.newInstance(FirefoxDriverProvider.java:63)
        at org.openqa.selenium.remote.server.DefaultDriverFactory.newInstance(DefaultDriverFactory.java:60)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:222)
        at org.openqa.selenium.remote.server.DefaultSession$BrowserCreator.call(DefaultSession.java:209)
        at java.util.concurrent.FutureTask.run(Unknown Source)
        at org.openqa.selenium.remote.server.DefaultSession$1.run(DefaultSession.java:176)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
        ... 1 more
Caused by: java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
        at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
        at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
        at java.lang.reflect.Constructor.newInstance(Unknown Source)
        at org.openqa.selenium.remote.server.FirefoxDriverProvider.callConstructor(FirefoxDriverProvider.java:81)
        ... 9 more
Caused by: org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{rotatable=true, proxy={"proxyAutoconfigUrl":null,"autodetect":false,"socksPassword":"mine","socksUsername":"mine","httpProxy":null,"proxyType":"MANUAL","noProxy":null,"ftpProxy":null,"socksProxy":"127.0.0.1","hCode":1194763275,"class":"org.openqa.selenium.Proxy","sslProxy":null}, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@32b33674, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}, requestOrigins={name=webdriverio, version=4.6.2, url=http://webdriver.io}}], required capabilities = Capabilities [{}]
Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
System info: host: 'MY-PC', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
        at org.openqa.selenium.remote.ProtocolHandshake.createSession(ProtocolHandshake.java:126)
        at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:141)
        at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
        at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:604)
        at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:244)
        at org.openqa.selenium.remote.RemoteWebDriver.<init>(RemoteWebDriver.java:131)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:243)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:121)
        at org.openqa.selenium.firefox.FirefoxDriver.<init>(FirefoxDriver.java:164)
        ... 14 more
19:18:36.048 WARN - Exception: Unable to create new remote session. desired capabilities = Capabilities [{rotatable=true, proxy={"proxyAutoconfigUrl":null,"autodetect":false,"socksPassword":"mine","socksUsername":"mine","httpProxy":null,"proxyType":"MANUAL","noProxy":null,"ftpProxy":null,"socksProxy":"127.0.0.1","hCode":1194763275,"class":"org.openqa.selenium.Proxy","sslProxy":null}, locationContextEnabled=true, loggingPrefs=org.openqa.selenium.logging.LoggingPreferences@32b33674, browserName=firefox, javascriptEnabled=true, handlesAlerts=true, moz:firefoxOptions={binary=Optional.empty, args=[], legacy=null, logLevel=null, prefs={}, profile=null}, requestOrigins={name=webdriverio, version=4.6.2, url=http://webdriver.io}}], required capabilities = Capabilities [{}]
Build info: version: '3.3.0', revision: 'b526bd5', time: '2017-03-07 11:21:31 -0800'
System info: host: 'MY-PC', ip: '10.0.75.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_121'
Driver info: driver.version: FirefoxDriver
4

1 回答 1

0

我不确定您是否知道这一点,但 mozilla 团队最近决定实现他们自己的浏览器自动化工具,称为 marionette。他们还实现了一个代理(称为 geckodriver),位于与 webdriver 兼容的客户端和木偶之间。这些工具仍处于非常活跃的开发阶段,因此其中的某些部分可能无法按预期工作。您应该查看此错误报告,了解如何使用所需的功能选项正确设置代理。

我之前也遇到过同样的问题,我不得不自己去修补 geckodriver。从那以后情况似乎有所改善,但由于我不是 100% 确定更改,并且我使用的是 python 和 python 绑定,我不确定如何使用 webdriverio 和 nodejs 所需的功能。

您可以尝试以下配置:

var options = {
    desiredCapabilities: {
        requiredCapabilities: {
        proxy:{
            proxyType: 'manual',
            socksProxy: '127.0.0.1',
            socksProxyPort: 1080,
            socksVersion: 5,
            socksUsername: "mine",
            socksPassword: "mine"
        }
    }
}

如果我没记错,geckodriver 在功能中搜索 requiredCapabilities。这也是 webdriver 协议的w3c 规范所建议的。

此时根据您的回答,我认为问题实际上是在代理上进行身份验证。我查看了木偶的源代码,虽然他们有一些用于测试袜子代理的单元测试,但这些测试不会检查用户名/密码是否已设置。因此,我不确定它是否正常工作。

我的建议是检查您是否可以在代理端处理此问题。例如,如果代理处理基于 ip 的身份验证,您可以设置它并只允许来自您的 ip 的流量。

您总是可以考虑使用其他浏览器而不是 firefox。

于 2017-03-12T20:36:37.690 回答