Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in DevOps and Agile by (19.7k points)

I am using Selenium2/WebDriver to test my web applications. All the tests are written in Java and run with Maven.

While opening a page with webdriver I'd like to capture all the requests made by page (images, js and css files, etc). I use this data mainly for two reasons

  • checking for 404 (and other errors) in calls
  • checking if analytics code is working (checking if it's sending proper requests)

Depending on the project I use either Firebug with Netexport or Browsermob proxy. In both cases, I can easily obtain a HAR (Html ARchive) file, parse it and extract the data I want.

Here's the problem: I am not happy with neither of these solutions. I have especially problems with getting HAR file when a page contains video that is being loaded too long. I am looking for something more stable.

So, the questions are:

Is there any alternative to Browsermob? I know about FiddlerCore but it's a .NET library and my tests are written in Java. I've also heard about Ajax DynaTrace and I know that there is some way to integrate it with Selenium but the documentation I found was for Selenium-RC not WebDriver.

Is there any way to integrate DynaTrace with WebDriver or use FiddlerCore with Java?

Is there any other way to achieve the goals I mentioned? I am looking for a proxy that I can easily control from my code. Exporting data to HAR would be a great plus.

1 Answer

0 votes
by (62.9k points)

I would suggest you do the following things:

  1. Add dependency to your project 

 

 <dependency>

  <groupId>com.moxproxy</groupId>

  <artifactId>moxproxy.core</artifactId>

  <version>1.0.2</version>

</dependency>

             2.  Start proxy

  MoxProxy proxy = LocalMoxProxy.builder()

                .withPort(89)

                .build();

    proxy.startServer();

             3.  Then you need to setup selenium webdriver to use proxy on localhost with port 89 and run test

 

           4. Collect traffic

 List<MoxProxyProcessedTrafficEntry> requestTraffic = proxy.getAllRequestTraffic();

List<MoxProxyProcessedTrafficEntry> responseTraffic = proxy.getAllResponseTraffic();

Besides collecting traffic, the proxy provides the possibility to modify requests and responses.

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...