sitespeedio / sitespeed.io

sitespeed.io is an open-source tool for comprehensive web performance analysis, enabling you to test, monitor, and optimize your website’s speed using real browsers in various environments.
https://www.sitespeed.io/
MIT License
4.76k stars 603 forks source link

Using sitespeed.io from Selenium Java tests???????? #1451

Closed aliradd closed 7 years ago

aliradd commented 7 years ago

Hello,

I have been talking with @soulgalore and he advised me to raise an issue here.

We are running fully headed browsers using Java and Selenium 3.0.1.

I presume we are interested in sending each page that loads to analysis (or a sample of which).

PageXray converts a HAR file to a usable JSON structure that tells you more about your page.

Is there a way form me to send the JSON files converted from HAR and other information to a DB/SiteSpeed.io from the browsers running the tests?

Our load generators run currently on AWS and we can install any other server and networking required.

The idea would be as our Selenium scripts run we send the perf data to other servers I presume Graphite for now and then be able to look at them using Garafana.

So can you please help us get this going?

And finally sitespeed.io is the main tool that uses all the previously mentioned tools and add supports for testing multiple pages as well as adds the ability to report the metrics to a TSDB (currently Graphite and soon also InfluxDB).

Thank you, Ali

soulgalore commented 7 years ago

Hey @aliradd ! ok, so you want use your current setup with Selenium and add some performance metrics to what you collect, do I understand correctly then? That is possible, then you need hack the JS we use in the coach for metrics we collect and insert them into your own Selenium scripts. But it will be some work.

I think it would be easier to just use the Docker containers with sitespeed.io and feed them with the URLs you test using your Selenium setup so you actually run the performance tests standalone. I think performance vs functional testing have different characteristics. You want to isolate the performance tests so they run standalone and nothing can interfere with them, for the functional testing you can run multiple testa at the same time. And if you run our Docker containers you will also benefit of the video and VisualMetrics that will generate SpeedIndex and start render.

Is there a way form me to send the JSON files converted from HAR and other information to a DB/SiteSpeed.io from the browsers running the tests?

If you sitespeed.io standalone that's built in but only store the data in Graphite but you could build a plugin that stores the data in a database. Getting the data yourself from Selenium is possible (that's what we do in sitespeed.io) but you need code that yourself if you run Selenium standalone and run your own JS to collect metrics.

So can you please help us get this going?

I think a first step for you is to play around with https://www.sitespeed.io/documentation/sitespeed.io/performance-dashboard/#up-and-running-in-5-minutes to get a feeling what you do if use sitespeed.io directly and compare it with if you add your own scripts to collect metrics using your current Selenium setup.

Best Peter

aliradd commented 7 years ago

Hi @soulgalore,

Thank you very much for your reply.

Can you please confirm that this would work for sites that require logon and have logged on sections that are only accessible to authenticated users?

I get the feeling we need to know the URLs we are monitoring in advance for this to work or can we get it to work by following a click path?

Best, Ali

softwareklinic commented 7 years ago

Sitespeed works for logged in pages as well... using the preScript option + the JS script that u can write to reproduce the steps as precursor to the actual page that is behind the secured access.

You are right i believe - u can test a particular url by passing the preScript --- but it would be an enhancement to sitespeed to continue the STEPS/flow kind of scenario to test multiple pages by single preScript execution.

aliradd commented 7 years ago

great 👍. Thank you for your reply. I guessed that would be the case.....so the next question is can we use our Java Selenium scripts instead of PreScript and Js script?

So we have Java Selenium scripts that do the job......How easy would it be to use them?

softwareklinic commented 7 years ago

Some input here... I have never tried to convert JAVA Selenium to JS... but what I did is as below

I used Firefox Addon called Selenium Builder - that way u can record the scenario that u want to test -- and export it as a NODE JS script - which u can plug-into preScript ...

https://addons.mozilla.org/en-us/firefox/addon/selenium-builder/

image

Select Node.js - selenium webdriver

image

which gives u something like below - which u can save as xxxx.js and pass to preScript

var webdriver = require('selenium-webdriver'), By = webdriver.By, until = webdriver.until; var _ = require('underscore'); var VARS = {};

var globalTimeout = 60*1000;

var driver = new webdriver.Builder() .forBrowser('firefox') .build();

driver.controlFlow().on('uncaughtException', function(err) { console.log('There was an uncaught exception: ' + err); });

driver.get("https://www.verizonwireless.com/"); driver.findElement(By.id("onavmenu1")).click();

driver.quit();

softwareklinic commented 7 years ago

basically u can retain all the code after driver.get and paste it in the samples provided on sitespeed documentation.. the initialization part is little too specific about browser etc... which u dont need since u can use sitespeed to control what browser u want to test

softwareklinic commented 7 years ago

here is my full sample if u want to follow this

module.exports = {
  run(context) {
    return context.runWithDriver((driver) => {
      // Go to Wikipedias login URL
      return driver.get('https://www.verizonwireless.com')
           .then(() => {
      // You need to find the form, the login input fiels and the
      // password field. Just add you name and password and submit the form
      // For more docs, checkout the NodeJS Selenium version
      // http://seleniumhq.github.io/selenium/docs/api/javascript/index.html

      // we fetch the selenium webdriver from context
       var webdriver = context.webdriver;
        var By = webdriver.By;
      var sleeptime = 15000; 

driver.findElement(By.id("xxxxxxx")).clear(); 
driver.findElement(By.id("xxxxxxx")).sendKeys("xxxxxxxx"); 
driver.findElement(By.xpath("//form[@id='ribbon-sign-in-form']/button")).click(); 

driver.sleep(sleeptime);

driver.findElement(By.id("xxxxxx")).clear(); 
driver.findElement(By.id("xxxx")).sendKeys("xxxxxx"); 
driver.findElement(By.css("xxxxxx.xxx-xxxx-xxxxx")).click();

driver.sleep(sleeptime);

driver.findElement(By.id("xxxxxxxxx")).clear(); 
driver.findElement(By.id("xxxxxxx")).sendKeys("xxxxxxxxxxxxx"); 
driver.findElement(By.css("xxxxxxx.xxxxxxxx")).click(); 

driver.sleep(sleeptime);

       });
     })
   }
};
aliradd commented 7 years ago

This is great thanks you for your reply. @softwareklinic

What if we have page object model implemented does it still work?

So effectively there is a test script and then there are page objects would your example still be implementable?

softwareklinic commented 7 years ago

yes it should work just fine.

aliradd commented 7 years ago

So silly question are you able to please update your example so that it is using page object model.

Ideally we want to initialise a pageobject and use it....

Login login = new Login("xxxxxx","xxxxxx","xxxxxxxxxxxxx");

Hope my question makes sense.

Thanks, Ali

softwareklinic commented 7 years ago

Never tried it - but will give it a shot... I'm assuming you have done this with Selenium + Java....

soulgalore commented 7 years ago

@aliradd did this work out for you?

soulgalore commented 7 years ago

closing, please re-open if you need more info.

aliradd commented 7 years ago

@soulgalore thanks for the follow up and sorry for my slow response. I was awaiting to find out if we can implement a folder structure in the instructions above.

@softwareklinic thank you for your replies. Sorry it is not clear if we can implment the page object in a seperate file and just call it from the test?

In the example you have given the findelement is present in the test/script. Ideally we'll put these in a different file and just refer to them.

Is there an easy way to achieve this?