After I upload a file to the website, the website showcases a loading screen. The loading screen is up depending on the size of the file. I would like to measure the duration of how long the loading page was up for. I am a beginner in jmeter and programming, so I do not know if there is a much better idea than the one that I currently have.
Here is what I got so far.
var node = implicitFind(pkg.By.xpath("//div[id]")); //xpath of the loading screen
var increment = 1;
while (node != null) {
if (increment == 1)
var before = new Date().getTime(); //gets current time of test
increment ;
}
var after = new Date().getTime();
WDS.log.info('------- Time taken for loading screen = ' (after - before) ' ms');
/*
The reason why I added an increment was so the before time can be recorded only on the
first loop rather than every loop. The loop ends when xpath no longer exist, which is
when the after time is recorded.
*/
The issue with this code is that jmeter never breaks the loop, even if condition is false. The xpath is from a text that shows up when the loading screen shows up. Please help if there is a better way or if there is a flaw with my current code. Thanks y'all!
CodePudding user response:
It's hard to say what's wrong without seeing your implicitFind
function code, you might want to re-visit it and check for element visibility or invisibility i.e. use WebElement.isDisplayed() function
More information: The WebDriver Sampler: Your Top 10 Questions Answered
CodePudding user response:
long startTime = System.currentTimeMillis();
driver.get("http://infoall.org");
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.id("Calculate")));
long endTime = System.currentTimeMillis();
long totalTime = endTime - startTime;
System.out.println("Total Page Load Time: " totalTime "milliseconds");