1

I wrote a script on the Jmeter Web Driver in javascript and Java .

On a Windows system , the script is running perfectly . But on a Linux System , i have a weird problem . The lastmodifed then i obtain is not good. front_end.jtl has been modified yesterday , but the script say today at 10:00 in milliseconds timestamp .

Please help me.

    // Importing packages (and all classes in package) from Java into Javascript var pkg = JavaImporter(org.openqa.selenium)
    var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
    // We don't use wait in this very simple test, but here is way to access for more realistic testing
    var wait=new support_ui.WebDriverWait(WDS.browser, 5)

    // Start recording the time for this request

    WDS.sampleResult.sampleStart();

    // Let's get a page

    var baseUrl = "cnyw${FE}.mycore.core-cloud.net"

    WDS.browser.get("https://"+ baseUrl)

    var frontjtl = new java.io.File('/home/mycore/front_end.jtl')
    var frontlog = new java.io.File('/home/mycore/jmeter_front_end.log')

    var lastmodifjtl = frontjtl.lastModified()
    var lastmodiflog = frontlog.lastModified()

    if ( lastmodifjtl = lastmodiflog ) {
     var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
     screenshot.renameTo(new java.io.File('/home/mycore/screenshots/tools/screenshot_cnyw${FE}.png'))
   }

    // Record the time of the request
    WDS.sampleResult.sampleEnd();
Hurobaki
  • 3,728
  • 6
  • 24
  • 41
  • 1
    It's probably because you copied the file to linux machine and create new file with new modified date (copy date) see https://superuser.com/questions/114195/how-to-copy-a-file-in-unix-without-altering-its-last-modified-time – Ori Marko Dec 05 '17 at 09:58
  • No, the file is already created and was modifed when an error occure in my test. – Guillaume Lannes Lacrouts Dec 05 '17 at 10:10
  • You are finally right. The modified date is set by the command new file. i doesn't want create new file , i want use the file. how to do this ? – Guillaume Lannes Lacrouts Dec 05 '17 at 13:52

3 Answers3

1

I would recommend using Files.getLastModifiedTime() instead, something like:

var lastmodifjtl = java.nio.file.Files.getLastModifiedTime(java.nio.file.Paths.get(frontjtl.toURI()))

should do the trick for you.

Just in case see The WebDriver Sampler: Your Top 10 Questions Answered article for more information

Dmitri T
  • 159,985
  • 5
  • 83
  • 133
  • I try this and i have the same date . I think the problem is on the initialization of frontjtl and frontlog . New file set the lasmodified time to the time of execution . – Guillaume Lannes Lacrouts Dec 05 '17 at 12:38
0

I found an explanation : https://bugs.openjdk.java.net/browse/JDK-8177809

It's a confirmed bug ...

0

i have rewrite the script in Java directly. All is okay now.