我们如何使用Appium和Java获得精确的时间来加载移动应用程序页面?

发布于 2025-02-11 22:53:00 字数 227 浏览 2 评论 0原文

嗨,团队,我需要计算移动应用程序页面加载时间,当我们从一个屏幕到另一个屏幕以获取移动应用程序。

我已经尝试了以下方法:

在单击元素之前,在MS中获取当前时间,然后单击该元素,等待可见期望的元素,然后再次将当前时间置于MS并减去时间。

请通过更好的方法来帮助我,以计算准确的页面加载时间。

谢谢。

Hi Team, I need to calculate the Mobile app Page loading time when we navigate from one screen to other screen for Mobile Application.

I have Tried below Approach:

Before Clicking on Element, get the current Time in MS and after clicking on the element, Waiting for expected element to be visible then again getting current time in MS and Subtract the times.

Please Help me out with better approach to calculate accurate page load time.

Thank you.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

2025-02-18 22:53:00
driver.get('url')
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
 
backendPerformance_calc = responseStart - navigationStart
frontendPerformance_calc = domComplete - responseStart
 
print("Back End: %s" % backendPerformance_calc)
print("Front End: %s" % frontendPerformance_calc)

您可以将其用于页面加载。不确定Java的方式。

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeAsyncScript("return window.performance.timing.navigationStart");  
driver.get('url')
navigationStart = driver.execute_script("return window.performance.timing.navigationStart")
responseStart = driver.execute_script("return window.performance.timing.responseStart")
domComplete = driver.execute_script("return window.performance.timing.domComplete")
 
backendPerformance_calc = responseStart - navigationStart
frontendPerformance_calc = domComplete - responseStart
 
print("Back End: %s" % backendPerformance_calc)
print("Front End: %s" % frontendPerformance_calc)

You can use this for page loads. Not sure of the Java way for this.

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeAsyncScript("return window.performance.timing.navigationStart");  
緦唸λ蓇 2025-02-18 22:53:00

您可以测量持续时间。
开始加载应用程序/页面时开始秒表。
并在加载最后一个元素时将其停止。

You can measure the duration.
Start stopwatch when you start loading the application/page.
And stop it when the last element is loaded.

岁月静好 2025-02-18 22:53:00

嗨,您可以使用秒表类找到加载主页的确切时间。
使用以下代码:

stopwatch loadTime = new stopwatch();

    driver.get("url");
    loadTime.start();
    
    boolean appLoaded = new WebDriverWait(driver, 30).until(
            ExpectedConditions.elementToBeClickable(MobileBy.xpath("any xpath of expected page"))).isDisplayed();
    
    loadTime.stop();
    
    System.out.println("is App loaded : " +appLoaded);
    long pageLoadTime_ms = loadTime.getTime();
    System.out.println(" Load Time: " + pageLoadTime_ms + " milliseconds");

Hi You can find the exact time of loading a homepage by using stopwatch class.
Use below code:

StopWatch loadTime = new StopWatch();

    driver.get("url");
    loadTime.start();
    
    boolean appLoaded = new WebDriverWait(driver, 30).until(
            ExpectedConditions.elementToBeClickable(MobileBy.xpath("any xpath of expected page"))).isDisplayed();
    
    loadTime.stop();
    
    System.out.println("is App loaded : " +appLoaded);
    long pageLoadTime_ms = loadTime.getTime();
    System.out.println(" Load Time: " + pageLoadTime_ms + " milliseconds");
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文