Search code examples
jmeterwebdriver

Getting Missing close quote error running the jmeter scripts


the below script was working fine and all of sudden the problem started and not able to identify what's the issue here is. if I replace the filepath with any thing else then it works. I have write access to that folder and able to run the test multiple times to save the files to that location. The test shows this error as soon as the scrip starts

 var selenium = JavaImporter(org.openqa.selenium)
 var time = JavaImporter(java.util.concurrent.TimeUnit)
 WDS.browser.manage().timeouts().implicitlyWait(30, time.TimeUnit.SECONDS)
 var support_ui=JavaImporter(org.openqa.selenium.support.ui) 
 var home = java.lang.System.getProperty('user.dir')
 var io = JavaImporter(java.io)

 WDS.sampleResult.sampleStart()
 WDS.log.info("Load the application");
 WDS.sampleResult.subSampleStart('Load the application')
 WDS.browser.get('https://ea-webapp-stg-test.com/getting-started')
 WDS.log.info("Enter the Credentials and click on Login");
 WDS.sampleResult.subSampleStart('Enter the Credentials and click on Login')
 WDS.browser.findElement(selenium.By.id("username")).sendKeys("test-user");
 WDS.browser.findElement(selenium.By.id("password")).sendKeys("Testpass");
 WDS.browser.findElement(selenium.By.id("ravenTermsAgree")).click();
 WDS.browser.findElement(selenium.By.id("kc-login")).click();
 takeScreenshot('Screenshot_Logging')

function takeScreenshot(fileName){
    WDS.log.info("Taking screenshots for: "+fileName);
    screenshot = WDS.browser.getScreenshotAs(selenium.OutputType.FILE)
    screenshot.renameTo(new java.io.File(home + '\\Test data set\\screenshots\\'+fileName+'.png'))
}
 WDS.sampleResult.sampleEnd()

The error shows as

2022-03-24 17:39:34,790 INFO o.a.j.t.JMeterThread: Thread started: Thread Group 1-1
2022-03-24 17:39:52,507 INFO c.g.j.p.w.c.WebDriverConfig: Created browser object: ChromeDriver: chrome on WINDOWS (null)
2022-03-24 17:39:52,533 ERROR c.g.j.p.w.s.WebDriverSampler: <eval>:182:92 Missing close quote
    screenshot.renameTo(new java.io.File(home + '\Test data set\screenshots\'+fileName+'.png'))
                                                                                               ^ in <eval> at line number 182 at column number 92
2022-03-24 17:39:52,534 INFO o.a.j.t.JMeterThread: Thread is done: Thread Group 1-1
2022-03-24 17:39:52,534 INFO o.a.j.t.JMeterThread: Thread finished: Thread Group 1-1
2022-03-24 17:39:53,136 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2022-03-24 17:39:53,137 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)

Solution

  • It looks like \ character is treated as escape meta character in string, I would recommend replacing it with system independent path separator

    var selenium = JavaImporter(org.openqa.selenium)
    var time = JavaImporter(java.util.concurrent.TimeUnit)
    WDS.browser.manage().timeouts().implicitlyWait(30, time.TimeUnit.SECONDS)
    var support_ui = JavaImporter(org.openqa.selenium.support.ui)
    var home = java.lang.System.getProperty('user.dir')
    var io = JavaImporter(java.io)
    var slash = java.io.File.separator
    
    WDS.sampleResult.sampleStart()
    WDS.log.info("Load the application");
    WDS.sampleResult.subSampleStart('Load the application')
    WDS.browser.get('https://ea-webapp-stg-test.com/getting-started')
    WDS.log.info("Enter the Credentials and click on Login");
    WDS.sampleResult.subSampleStart('Enter the Credentials and click on Login')
    WDS.browser.findElement(selenium.By.id("username")).sendKeys("test-user");
    WDS.browser.findElement(selenium.By.id("password")).sendKeys("Testpass");
    WDS.browser.findElement(selenium.By.id("ravenTermsAgree")).click();
    WDS.browser.findElement(selenium.By.id("kc-login")).click();
    takeScreenshot('Screenshot_Logging')
    
    function takeScreenshot(fileName) {
        WDS.log.info("Taking screenshots for: " + fileName);
        screenshot = WDS.browser.getScreenshotAs(selenium.OutputType.FILE)
        screenshot.renameTo(new java.io.File(home + slash + 'Test data set' + slash + 'screenshots' + slash + fileName + '.png'))
    }
    WDS.sampleResult.sampleEnd()
    

    More information: