Forum Discussion

knyazs's avatar
knyazs
Regular Visitor
9 years ago

Check if PowerBI page is loaded (using Selenium)

Hi!

 

I am using Selenium to automate load and performance testing of PowerBI reports and I need a reliable way to pause code execution until page is fully loaded (all queries executed and all slicers and charts displayed). Many pages on Google suggested I should use following JavaScripts codes to achieve that:

  • return jQuery.active == 0
  • return document.readyState == "complete"

But this does not work for me as both lines are always verified as true and code continues executing although I can see that chart has not been drawn.

 

The only way I could made it work is to get XPaths of all elements from the report (slicers, charts, etc.) and wait for all of those elements to "become"visible:

 

public void waitUntilReportProcesses(IWebDriver driver)
{
	WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(600.00));
	var xpaths = new string[]
	{
		"//*[@id=\"pvExplorationHost\"]/div/div/div/div[1]/div[2]/div[3]/div[2]/div[2]", // chart 1
		"//*[@id=\"pvExplorationHost\"]/div/div/div/div[1]/div[2]/div[9]/div[2]/div[2]", // chart 2
		"//*[@id=\"pvExplorationHost\"]/div/div/div/div[1]/div[2]/div[6]/div[2]/div" // slicer 1
		//...
	};

	foreach (var xpath in xpaths)
		wait.Until(ExpectedConditions.ElementIsVisible(By.XPath(xpath)));
}

 

I tried to make above code more universal by finding elements using css (By.CssSelector). With that approach I am able to get all of the necessary elemets but ElementIsVisible and VisibilityOfAllElementsLocatedBy methods seems to behave differently in that case and code never pauses execution.

 

What would be the proper way to check if PowerBI page has been loaded?

 

Thanks,

11 Replies

  • Eric_Zhang's avatar
    Eric_Zhang
    Microsoft Employee

    knyazs wrote:

    Hi!

     

    I am using Selenium to automate load and performance testing of PowerBI reports and I need a reliable way to pause code execution until page is fully loaded (all queries executed and all slicers and charts displayed). Many pages on Google

     

    What would be the proper way to check if PowerBI page has been loaded?

     

    Thanks,


     

     

    knyazs

     

    I don't have much expertise on javascript so I have no idea on how to capture the page loading accomplished in JS.

     

    However, as per the knowledge in my previous job, to test the page loading performance, a more accurate way would be tracing the network traffic. And based on my test, regarding an embeded report, the loading span is between the first embeded url request and the last "querydata" request. See below snapshot captured in F12 in firefox. So you may consider to use Wireshark or Fiddler.

  • The new JavaScript API allows you to listen to the event that indicates that the report is done loading:

     

    https://github.com/Microsoft/PowerBI-JavaScript/wiki/Handling-Events

     

    I'm not sure whether you could use this directly in your test. A different approach could be to listen for the 'loaded' event in your application code and then make some changes to the DOM in your application (something that can be detected by Selenium) that flags the report as 'finished loading'.

     

    Just an idea, hope this helps :)

  • Hey Did you get the solution to your problem?Can you provide me the code sample ? I want to create a tool to capture the Page Load Time of a Power BI Report. Can you help me with the approach I need to follow?

    • knyazs's avatar
      knyazs
      Regular Visitor

      Unfortunately, I cannot share code with you but I can tell you how I solved it - using Selenium I managed to make it work by "catching" so-called "spinning wheel" or "wait" sign on the page after slicer is clicked. I would start measuring time from slicer click and then wait few seconds to see if "wait" sign appears and disappears - it there is no wait sign after few seconds, I would take time captured immediately after slicer click; if "wait" appeared, I would wait until it disappears and capture timestamp.

       

      I hope this helps.

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hey,

         

        I am doing similar thing in selenium with PBI report. Can you share how did you get the hold of wait symbol or element in the report.

         

        Thanks,

        Kanika