Forum Discussion
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_ZhangMicrosoft 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,
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.
- knyazsRegular Visitor
Hi Eric,
Thanks for the quick reply. Fiddler is a great tool but I don't think I can use it in this case.
Just to be absolutely clear on this matter, let me explain what I'm doing - I created C# project which uses Selenium to simulate user clicks on PowerBI report slicers. After slicer is clicked, page will start refreshing but Selenium cannot automatically detect when load is over as PowerBI (I assume) uses ajax / json / jquery. If page is not completely loaded and code continues with the execution (next slicer click) an attempt to click on non-existing / non-visible / non-clickable / ... element may occur and code will throw an error. Also, adding a delay after slicer click is not an option as I am trying to test how quick report is.
Thanks,
- ddevogelFrequent Visitor
knyazs Might Selenium's built-in ImplicitWait help to solve your problem?
http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp
- ekeijlHelper I
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 :)
- taruntalreja08Frequent Visitor
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?
- knyazsRegular 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.
- AnonymousNot 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