GVKun编程网logo

BrowserMob代理+ Selenium:未收到任何HTTP响应

10

对于想了解BrowserMob代理+Selenium:未收到任何HTTP响应的读者,本文将是一篇不可错过的文章,并且为您提供关于C#Appium/SeleniumDeriveWindowsElemen

对于想了解BrowserMob代理+ Selenium:未收到任何HTTP响应的读者,本文将是一篇不可错过的文章,并且为您提供关于C# Appium/Selenium Derive WindowsElement 抛出错误、c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、http.post请求未收到任何数据、https://github.com/SeleniumHQ/selenium/tree/master/py的有价值信息。

本文目录一览:

BrowserMob代理+ Selenium:未收到任何HTTP响应

BrowserMob代理+ Selenium:未收到任何HTTP响应

具有依赖项的Maven / Java项目:

      <dependencies><dependency>  <groupId>net.lightbody.bmp</groupId>  <artifactId>browsermob-core</artifactId>  <version>2.1.4</version>  <scope>test</scope></dependency><dependency>  <groupId>junit</groupId>  <artifactId>junit</artifactId>  <version>4.12</version>  <scope>test</scope></dependency><dependency>  <groupId>org.apache.httpcomponents</groupId>  <artifactId>httpclient</artifactId>  <version>4.3.4</version></dependency><dependency>  <groupId>org.seleniumhq.selenium</groupId>  <artifactId>selenium-java</artifactId>  <version>3.7.1</version></dependency><dependency>  <groupId>com.google.guava</groupId>  <artifactId>guava</artifactId>  <version>23.0</version></dependency></dependencies>

码:

公共类bmp_Selenium {

@Testpublic void test() throws Exception {    String chromedriverPath = System.getProperty("user.dir") + "/chromedriver";    System.setProperty("webdriver.chrome.driver", chromedriverPath);    BrowserMobProxy proxy = getProxyServer(); //getting browsermob proxy    System.out.println("BrowserMob Proxy running on port: " + proxy.getPort());    Proxy seleniumProxy = getSeleniumProxy(proxy);    DesiredCapabilities capabilities = new DesiredCapabilities();    capabilities.setCapability(CapabilityType.PROXY, seleniumProxy);    WebDriver driver = new ChromeDriver(capabilities);    proxy.newHar("foo");    driver.get("http://www.google.com");    Har har = proxy.getHar();    // Write HAR Data in a File    String harFilePath = System.getProperty("user.dir") + "/hars/ww.har";    File harFile = new File(harFilePath);    try {        har.writeTo(harFile);    } catch (IOException ex) {         System.out.println (ex.toString());         System.out.println("Could not find file " + harFilePath);    }    List<HarEntry> entries = har.getLog().getEntries();    for (HarEntry entry : entries) {        System.out.println("Request URL: " + entry.getRequest().getUrl());        System.out.println("Entry response status: " + entry.getResponse().getStatus());        System.out.println("Entry response text: " + entry.getResponse().getStatusText());    }    proxy.stop();    driver.quit();}public Proxy getSeleniumProxy(BrowserMobProxy proxyServer) {    Proxy seleniumProxy = ClientUtil.createSeleniumProxy(proxyServer);    try {        String hostIp = Inet4Address.getLocalHost().getHostAddress();        seleniumProxy.setHttpProxy(hostIp + ":" + proxyServer.getPort());        seleniumProxy.setSslProxy(hostIp + ":" + proxyServer.getPort());    } catch (UnknownHostException e) {        e.printStackTrace();        Assert.fail("invalid Host Address");    }    return seleniumProxy;}public BrowserMobProxy getProxyServer() {    BrowserMobProxy proxy = new BrowserMobProxyServer();    proxy.setTrustAllServers(true);    proxy.setHarCaptureTypes(CaptureType.REQUEST_CONTENT, CaptureType.RESPONSE_CONTENT);    proxy.start();    return proxy;}

}

控制台输出:

在端口:57547上运行的BrowserMob代理在端口47157上启动ChromeDriver
2.33.506106(8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2)仅允许本地连接。2017年11月30日下午4:48:33
org.openqa.selenium.remote.ProtocolHandshake createSession
INFO:检测到方言:OSS请求URL:http :
//www.google.com/ 输入响应状态:0输入响应文本:请求URL
:http :
//www.google.com/
输入响应状态:0输入响应文本:请求URL:http :
//www.google.com/ 输入响应状态:0输入响应文本:请求URL:http://
www .google.com / 输入响应状态:0输入响应文本:

Har文件:

{  "log": {    "version": "1.2",    "creator": {      "name": "BrowserMob Proxy",      "version": "2.1.4",      "comment": ""    },    "pages": [{        "id": "foo",        "startedDateTime": "2017-11-30T21:48:34.064Z",        "title": "foo",        "pageTimings": {          "comment": ""        },        "comment": ""      }    ],    "entries": [{        "pageref": "foo",        "startedDateTime": "2017-11-30T21:48:34.210Z",        "request": {          "method": "GET",          "url": "http://www.google.com/",          "httpVersion": "HTTP/1.1",          "cookies": [          ],          "headers": [          ],          "queryString": [          ],          "headersSize": 417,          "bodySize": 0,          "comment": ""        },        "response": {          "status": 0,          "statusText": "",          "httpVersion": "unknown",          "cookies": [          ],          "headers": [          ],          "content": {            "size": 0,            "mimeType": "",            "comment": ""          },          "redirectURL": "",          "headersSize": -1,          "bodySize": -1,          "comment": "",          "_error": "No response received"        },        "cache": {},        "timings": {          "comment": "",          "send": 0,          "wait": 0,          "receive": 0,          "ssl": -1,          "connect": -1,          "blocked": 0,          "dns": -1        },        "comment": "",        "time": 0      }, {        "pageref": "foo",        "startedDateTime": "2017-11-30T21:48:34.224Z",        "request": {          "method": "GET",          "url": "http://www.google.com/",          "httpVersion": "HTTP/1.1",          "cookies": [          ],          "headers": [          ],          "queryString": [          ],          "headersSize": 417,          "bodySize": 0,          "comment": ""        },        "response": {          "status": 0,          "statusText": "",          "httpVersion": "unknown",          "cookies": [          ],          "headers": [          ],          "content": {            "size": 0,            "mimeType": "",            "comment": ""          },          "redirectURL": "",          "headersSize": -1,          "bodySize": -1,          "comment": "",          "_error": "No response received"        },        "cache": {},        "timings": {          "comment": "",          "send": 0,          "wait": 0,          "receive": 0,          "ssl": -1,          "connect": -1,          "blocked": 0,          "dns": -1        },        "comment": "",        "time": 0      }, {        "pageref": "foo",        "startedDateTime": "2017-11-30T21:48:34.225Z",        "request": {          "method": "GET",          "url": "http://www.google.com/",          "httpVersion": "HTTP/1.1",          "cookies": [          ],          "headers": [          ],          "queryString": [          ],          "headersSize": 417,          "bodySize": 0,          "comment": ""        },        "response": {          "status": 0,          "statusText": "",          "httpVersion": "unknown",          "cookies": [          ],          "headers": [          ],          "content": {            "size": 0,            "mimeType": "",            "comment": ""          },          "redirectURL": "",          "headersSize": -1,          "bodySize": -1,          "comment": "",          "_error": "No response received"        },        "cache": {},        "timings": {          "comment": "",          "send": 0,          "wait": 0,          "receive": 0,          "ssl": -1,          "connect": -1,          "blocked": 0,          "dns": -1        },        "comment": "",        "time": 0      }, {        "pageref": "foo",        "startedDateTime": "2017-11-30T21:48:34.327Z",        "request": {          "method": "GET",          "url": "http://www.google.com/",          "httpVersion": "HTTP/1.1",          "cookies": [          ],          "headers": [          ],          "queryString": [          ],          "headersSize": 443,          "bodySize": 0,          "comment": ""        },        "response": {          "status": 0,          "statusText": "",          "httpVersion": "unknown",          "cookies": [          ],          "headers": [          ],          "content": {            "size": 0,            "mimeType": "",            "comment": ""          },          "redirectURL": "",          "headersSize": -1,          "bodySize": -1,          "comment": "",          "_error": "No response received"        },        "cache": {},        "timings": {          "comment": "",          "send": 0,          "wait": 0,          "receive": 0,          "ssl": -1,          "connect": -1,          "blocked": 0,          "dns": -1        },        "comment": "",        "time": 0      }    ],    "comment": ""  }}

答案1

小编典典

根据GitHub用户mediga的建议,修改BMP依赖关系解决了该问题:

取代这个

<dependency>  <groupId>net.lightbody.bmp</groupId>  <artifactId>browsermob-core</artifactId>  <version>2.1.4</version>  <scope>test</scope></dependency>

>     <dependency>>       <groupId>net.lightbody.bmp</groupId>>       <artifactId>browsermob-core</artifactId>>       <version>2.1.5</version>>     </dependency>

https://github.com/lightbody/browsermob-
proxy/issues/689#issuecomment-348620752

C# Appium/Selenium Derive WindowsElement 抛出错误

C# Appium/Selenium Derive WindowsElement 抛出错误

如何解决C# Appium/Selenium Derive WindowsElement 抛出错误?

在我的 C# .NET Framework 4.8 项目中,我试图派生 WindowsElement 类以在新类中实现一些附加功能。 例如 ClickInMiddleOfControlIsVisibleSelectedItem(在组合框中)。

public class WindowsElementWrapper : WindowsElement
{
    public WindowsElementWrapper(RemoteWebDriver parent,string id) : base(parent,id) { }

    public void ClickInMiddleOfControl()
    {
        var rect = this.Rect;
        var offsetx = (int)(0.5 * rect.Width);
        var offsety = (int)(0.5 * rect.Height);
        new Actions(Helper.Session)
            .MovetoElement(this,0)
            .MoveByOffset(offsetx,offsety)
            .Click()
            .Build()
            .Perform();
    }
}

然后我尝试将 WindowsElement 转换为我的 WindowsElementWrapper。

var element = (WindowsElementWrapper)Session.FindElementByName("ElementName");
element.ClickInMiddleOfControl();

但在运行时我收到以下错误消息:

system.invalidCastException: ''无法转换类型的对象 OpenQA.Selenium.Appium.Windows.WindowsElement'' 输入 ''WEW.WindowsElementWrapper''。''

是否不能从 WindowsElement 类派生?还是我犯了一个根本性的错误?

解决方法

WindowsElementWindowsElementWrapper 的转换是沮丧

为了使向下转型成功,对象的运行时类型必须是目标类型本身,或者是从它派生的类型。

虽然 WindowsElementWrapperWindowsElement,但 WindowsElement 不一定是 WindowsElementWrapper

换句话说,这种向下转换永远不会成功,除非 SeleniumAPI 实例化对象作为一个 WindowsElementWrapper 开始。

为了实现您想要做的事情,您可以应用以下设计之一:


组成

public class WindowsElementWrapper
{
   private readonly WindowsElement element;

   public WindowsElementWrapper(WindowsElement element,(int Width,int Height) rect)
   {
      this.element = element;
      Rect = rect;
   }

   public (int Width,int Height) Rect { get; init; }

   public void ClickInMiddleOfControl()
      => new Actions(Helper.Session)
            .MoveToElement(element,0)
            .MoveByOffset(Rect.Width / 2,Rect.Height / 2)
            .Click()
            .Build()
            .Perform();
}

扩展方法

public static class Extensions
{
   public static void ClickInMiddleOfControl(this WindowsElement source,int Height) rect)
      => new Actions(Helper.Session)
            .MoveToElement(source,0)
            .MoveByOffset(rect.Width / 2,rect.Height / 2)
            .Click()
            .Build()
            .Perform();
}

最好的问候

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?

我之前使用IWebDriver控制IE进行测试.但是IWebDriver和IWebElement支持的方法非常有限.我发现属于Selenium命名空间的ISelenium / DefaultSelenium非常有用.如何在不安装Selenium Server的情况下使用它们来控制IE?

这是DefaultSelenium的构造函数:

ISelenium sele = new DefaultSelenium(**serveraddr**,**serverport**,browser,url2test);
sele.Start();
sele.open();
...

似乎我必须在创建ISelenium对象之前安装Selenium Server.

我的情况是,我正在尝试使用C#Selenium构建一个.exe应用程序,它可以在不同的PC上运行,并且不可能在所有PC上安装Selenium Server(你永远不知道哪个是下一个运行应用程序).

有没有人知道如何在不安装服务器的情况下使用ISelenium / DefaultSelenium?
谢谢!

解决方法

在不使用RC Server的情况下,Java中有一些解决方案:

1)对于selenium浏览器启动:

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setbrowserName("safari");
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:4444/"),new URL("http://www.google.com/"),capabilities);
WebDriver driver = new RemoteWebDriver(executor,capabilities);

2)对于selenium命令:

// You may use any WebDriver implementation. Firefox is used here as an example
WebDriver driver = new FirefoxDriver();

// A "base url",used by selenium to resolve relative URLs
 String baseUrl = "http://www.google.com";

// Create the Selenium implementation
Selenium selenium = new WebDriverBackedSelenium(driver,baseUrl);

// Perform actions with selenium
selenium.open("http://www.google.com");
selenium.type("name=q","cheese");
selenium.click("name=btnG");

// Get the underlying WebDriver implementation back. This will refer to the
// same WebDriver instance as the "driver" variable above.
WebDriver driverInstance = ((WebDriverBackedSelenium) selenium).getWrappedDriver();

//Finally,close the browser. Call stop on the WebDriverBackedSelenium instance
//instead of calling driver.quit(). Otherwise,the JVM will continue running after
//the browser has been closed.
selenium.stop();

描述于此:http://seleniumhq.org/docs/03_webdriver.html

谷歌在C#中有类似的东西.没有其他方法可以实现这一目标.

http.post请求未收到任何数据

http.post请求未收到任何数据

根据文档,Net::HTTP post方法返回一个HTTPResponse对象。由于仅返回一个对象,因此只会为resp提供一个值。

您提到“响应包含预期的数据”。我想知道您是否只需要使用body方法。 resp.body是否会为您提供所需的数据?

请参见https://ruby-doc.org/stdlib-2.7.1/libdoc/net/http/rdoc/Net/HTTP.html#method-i-post

https://github.com/SeleniumHQ/selenium/tree/master/py

https://github.com/SeleniumHQ/selenium/tree/master/py

https://github.com/SeleniumHQ/selenium/tree/master/py

今天关于BrowserMob代理+ Selenium:未收到任何HTTP响应的讲解已经结束,谢谢您的阅读,如果想了解更多关于C# Appium/Selenium Derive WindowsElement 抛出错误、c# – 是否可以在不安装Selenium Server的情况下使用ISelenium / DefaultSelenium?、http.post请求未收到任何数据、https://github.com/SeleniumHQ/selenium/tree/master/py的相关知识,请在本站搜索。

本文标签: