0 votes
1 view
in Devops and Agile by (17.6k points)

I want to get output that is a network panel on developer tools.[ Network panel--> Name,method,status,Type,Initiator,Size,Time,Timeline] I need this information.

1 Answer

0 votes
by (47.9k points)

This is possible using Selenium WebDriver. For this you should do the following:

  1. Download selenium language-specific client drivers from - http://docs.seleniumhq.org/download/ and add appropriate jar files to your project build path.

  2. To run a test with Chrome/Chromium you will also need chrome driver binary which you can download from - http://chromedriver.storage.googleapis.com/index.html

  3. Create a test case like this:

 

 // specify the path of the chromedriver binary that you have downloaded (see point 2)

    System.setProperty("webdriver.chrome.driver", "/root/Downloads/chromedriver");

    ChromeOptions options = new ChromeOptions();

    // if you like to specify another profile

    options.addArguments("user-data-dir=/root/Downloads/aaa"); 

    options.addArguments("start-maximized");

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();

    capabilities.setCapability(ChromeOptions.CAPABILITY, options);

    WebDriver driver = new ChromeDriver(capabilities);

    driver.get("http://www.google.com");

    String scriptToExecute = "var performance = window.performance || window.mozPerformance || window.msPerformance || window.webkitPerformance || {}; var network = performance.getEntries() || {}; return network;";

    String netData = ((JavascriptExecutor)driver).executeScript(scriptToExecute).toString();

Executing javascript on Chrome/Chromium will be helpful as it will give you the networking information also. The resulting string 'netData' will contain the required data in the JSONArray format.

I hope this helps.

...