我如何才能同时获得秒和毫秒?

时间:2019-06-20 06:49:32

标签: java selenium selenium-webdriver webdriver parseint

我正在尝试获取自动化测试项目中的页面加载时间。

pageLoad3.start();
        WebDriverWait wait3 = new WebDriverWait(driver, 30);
        wait3.until(ExpectedConditions.visibilityOfElementLocated(By.xpath(hotelNameDetailsXpath)));
        pageLoad3.stop();
        long pageLoadTime_ms5 = pageLoad3.getTime();
        long pageLoadTime_Seconds5 = pageLoadTime_ms5 / 1000;
        //System.out.println("Time taken to get load Total price element ::");
        System.out.println("pageLoadTime_ms5 ::"+pageLoadTime_ms5);
        System.out.println("Time taken to load DB Response :: " + pageLoadTime_Seconds5 + " seconds");

输出:

pageLoadTime_ms5 ::11479
Time taken to load DB Response ::  11 seconds

我得到了 11 秒,但无法获得 479 ,如何以以下格式获取它?

  • 实际要求:我想花些时间来获得

    这样的格式
    11 seconds 47 milliseconds i.e. (00:11:47)
    

1 个答案:

答案 0 :(得分:0)

要以 11秒47毫秒的形式获取输出,可以使用以下解决方案:

  • 代码块:

    public class division_by_1000 {
    
        public static void main(String[] args) {
            //long pageLoadTime_ms5 = pageLoad3.getTime();
            // assuming pageLoadTime_ms5 = 11479
            String pageLoadTime_ms5 = "11479";
            System.out.println("pageLoadTime_ms5 ::"+pageLoadTime_ms5);
            System.out.println("Time taken to load DB Response :: " + (Integer.parseInt(pageLoadTime_ms5)/1000) + " seconds " + (Integer.parseInt(pageLoadTime_ms5)%1000) + " millisseconds ");
        }
    }
    
  • 控制台输出:

    pageLoadTime_ms5 ::11479
    Time taken to load DB Response :: 11 seconds 479 millisseconds