I am getting this wired error in jmeter, "function noSuchMethod() { [native code] } is not a constructor function" when I try to look for logout element and click on it. So I have couple functions written in the Webdriver sampler and if I try to logout without calling the other function then it works normally. In the below code if I run the verifyEmailBatchListed(emailBatchName,counterVal) script then the logout function is failing to find the element and throwing this noSuchMethod error. I am not sure what wrong I am doing. I even checked if the element is not in view and tried to scroll the element in to view. Its something to do with the function verifyEmailBatchListed which I am totally missing something.
var selenium = org.openqa.selenium
var time = JavaImporter(java.util.concurrent.TimeUnit)
var support_ui = JavaImporter(org.openqa.selenium.support.ui)
var EC = org.openqa.selenium.support.ui.ExpectedConditions
var io = JavaImporter(java.io)
var sleepThr = java.lang.Thread
var counterVal = WDS.vars.get("counter");
WDS.props.put("userNum", counterVal)
var filePath = WDS.vars.get('FileLocation')
var fileTimer = WDS.vars.get('timer')
var ENV = WDS.args[0]
WDS.sampleResult.sampleStart()
WDS.browser.get(BaseURL)
login()
uploadFile()
clickSubmitBtn(submitButtonState,fileTimer)
verifyEmailBatchListed(emailBatchName,counterVal)
WDS.log.info("return value is "+value)
logout()
WDS.sampleResult.sampleEnd()
function verifyEmailBatchListed(emailBatchName,counterVal) {
WDS.props.put("emailBatchId_user" + counterVal, "")
var round = 1
try{
do {
WDS.log.info("attempting to check for the email batch exist- " + round)
WDS.browser.navigate().refresh()
emailBatchlistItem = waitByElement(selenium.By.xpath("//span[contains(text(),'" + emailBatchName + "')]"), EC.presenceOfAllElementsLocatedBy, 120)
// emailBatchlistItem.get(0).click()
// sleepThr.sleep(2000)
if (undefined !== emailBatchlistItem && emailBatchlistItem.length != 0) {
emailBatchlistItem.get(0).click()
var emailBatchOverview = waitByElement(selenium.By.xpath("//div[contains(@data-testid,\"email-dumps-overview-loading-false\")]"), EC.presenceOfElementLocated, 60)
var checkStateCt = 0
var EmailBatchUploadState
var runCleanup = false
try {
do {
WDS.log.info("attempting to check for the state- " + checkStateCt)
EmailBatchUploadState = waitByElement(selenium.By.xpath("//p[contains(text(),'Email Batch Status')]/following-sibling::div[contains(@class,'editField__target')]/p"), EC.presenceOfElementLocated, 60)
var uploadState = EmailBatchUploadState.getText()
WDS.log.info("The file batch '" + emailBatchName + "' is displayed in the email batches list and has status as - " + uploadState)
if (uploadState == "COMPLETED") {
runCleanup = true
WDS.log.info("The email batch will be deleted")
break;
}
else if (checkStateCt == 3) {
WDS.log.info("The email batch will not be deleted")
break;
}
else {
sleepThr.sleep(2000)
WDS.browser.navigate().refresh()
emailBatchlistItem = waitByElement(selenium.By.xpath("//span[contains(text(),'" + emailBatchName + "')]"), EC.presenceOfAllElementsLocatedBy, 120)
emailBatchlistItem.get(0).click()
}
checkStateCt++
} while (checkStateCt <= 3)
} catch (err) {
WDS.log.error(err.message)
}
WDS.props.put("runCleanup", runCleanup)
var emailBatchIdText = WDS.browser.findElement(selenium.By.xpath("//span[contains(text(),'" + emailBatchName + "')]/../parent::li")).getAttribute("data-testid")
var emailBatchId = emailBatchIdText.substring(emailBatchIdText.length() - 3);
WDS.log.info("emailBatchId_user" + counterVal + " in WDS is " + emailBatchId);
WDS.props.put("emailBatchId_user" + counterVal, emailBatchId)
break;
}
else if (round == 4) {
WDS.log.info("The file batch '" + emailBatchName + "' is not displayed in the email batches list")
break;
} else {
sleepThr.sleep(2000)
}
round++
} while (round <= 4)
WDS.log.info("done checking for the email batch item in the list")
} catch (err) {
WDS.log.error(err.message)
}
}
function logout() {
WDS.log.info("pass 4")
WDS.browser.switchTo().defaultContent();
WDS.browser.executeScript("window.scrollTo(document.body.scrollHeight, 0)");
// WDS.browser.navigate().refresh()
takeScreenshot('screenshot_beforeLogout')
WDS.browser.findElement(selenium.By.xpath("//li[@data-selenium='/getting-started']")).click()
var btnlist = waitByElement(selenium.By.xpath("//div[@data-testid='subbar']//button"), EC.presenceOfAllElementsLocatedBy, 60)
WDS.log.info("List of buttons are " + btnlist.length)
for (var b = 0; b < btnlist.length; b++) {
var btnTitle = btnlist.get(b).getAttribute("title")
WDS.log.info("the btn attribute is " + btnTitle)
if (btnTitle == "User Options") {
btnlist.get(b).click();
WDS.browser.findElement(selenium.By.cssSelector("button[data-testid='logout']")).click();
var userNameField = waitByElement(selenium.By.xpath("//*[contains(text(),'Disclaimer')]"), EC.presenceOfElementLocated, 60)
takeScreenshot('screenshot_loggedout')
}
}
}
function waitByElement(elementBy, conditionToExpect, timer) {
try {
var wait = new support_ui.WebDriverWait(WDS.browser, timer)
element = wait.until(conditionToExpect(elementBy));
return element;
} catch (error) {
WDS.log.error(error.message)
}
}
Log trace
2022-04-11 10:56:19,333 INFO c.g.j.p.w.s.WebDriverSampler: Load the application
2022-04-11 10:56:24,414 INFO c.g.j.p.w.s.WebDriverSampler: Disclaimer screen displayed and clicking on Agree button
2022-04-11 10:56:25,851 INFO c.g.j.p.w.s.WebDriverSampler: Enter the Credentials and click on Login
2022-04-11 10:56:29,917 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: Screenshot_Logging
2022-04-11 10:56:30,149 INFO c.g.j.p.w.s.WebDriverSampler: Select Email Batches menu
2022-04-11 10:56:30,928 INFO c.g.j.p.w.s.WebDriverSampler: Click on Upload Email link
2022-04-11 10:56:31,068 INFO c.g.j.p.w.s.WebDriverSampler: Select an email file to Upload
2022-04-11 10:56:32,823 INFO c.g.j.p.w.s.WebDriverSampler: Enter email batch details
2022-04-11 10:56:33,168 INFO c.g.j.p.w.s.WebDriverSampler: Selecting the file portfolio type
2022-04-11 10:56:34,814 INFO c.g.j.p.w.s.WebDriverSampler: Got list of SM portfolios: 30
2022-04-11 10:56:34,815 INFO c.g.j.p.w.s.WebDriverSampler: Selecting suggested portfoilio item
2022-04-11 10:56:34,857 INFO c.g.j.p.w.s.WebDriverSampler: Selecting portfolio name: test
2022-04-11 10:56:35,169 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_SelectSuggestedPortfolio
2022-04-11 10:56:35,964 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_beforeUpload
2022-04-11 10:56:36,242 INFO c.g.j.p.w.s.WebDriverSampler: Click Upload submit button
2022-04-11 10:56:36,263 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_clickingUploadBtn
2022-04-11 10:56:37,567 INFO c.g.j.p.w.s.WebDriverSampler: Waiting for loading image displayed
2022-04-11 10:56:37,657 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_AfterUpload
2022-04-11 10:56:38,301 INFO c.g.j.p.w.s.WebDriverSampler: Waiting for loading image removed
2022-04-11 10:56:38,959 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_Noloadingimage
2022-04-11 10:56:39,452 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_UploadPercentage
2022-04-11 10:56:39,883 INFO c.g.j.p.w.s.WebDriverSampler: File started uploading
2022-04-11 10:56:39,917 INFO c.g.j.p.w.s.WebDriverSampler: current upload percent 0
2022-04-11 10:56:57,489 INFO c.g.j.p.w.s.WebDriverSampler: Email batch upload processed succesfully in 17 secs
2022-04-11 10:56:57,490 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_UploadCompleted
2022-04-11 10:56:57,980 INFO c.g.j.p.w.s.WebDriverSampler: attempting to check for the email batch exist- 1
2022-04-11 10:57:02,859 INFO c.g.j.p.w.s.WebDriverSampler: attempting to check for the state- 0
2022-04-11 10:57:02,909 INFO c.g.j.p.w.s.WebDriverSampler: The file batch 'Uploaded from Jmeter_VLK' is displayed in the email batches list and has status as - COMPLETED
2022-04-11 10:57:02,910 INFO c.g.j.p.w.s.WebDriverSampler: The email batch will be deleted
2022-04-11 10:57:02,960 INFO c.g.j.p.w.s.WebDriverSampler: emailBatchId_user1 in WDS is 711
2022-04-11 10:57:02,961 INFO c.g.j.p.w.s.WebDriverSampler: done checking for the email batch item in the list
2022-04-11 10:57:02,968 INFO c.g.j.p.w.s.WebDriverSampler: pass 4
2022-04-11 10:57:03,004 INFO c.g.j.p.w.s.WebDriverSampler: Taking screenshots for: screenshot_beforeLogout
2022-04-11 10:57:03,326 ERROR c.g.j.p.w.s.WebDriverSampler: function __noSuchMethod__() { [native code] } is not a constructor function
2022-04-11 10:57:03,328 ERROR c.g.j.p.w.s.WebDriverSampler: TypeError: Cannot read property "length" from undefined in <eval> at line number 291
2022-04-11 10:57:03,328 INFO o.a.j.t.JMeterThread: Thread is done: Upload Email batches 2-1
2022-04-11 10:57:03,329 INFO o.a.j.t.JMeterThread: Thread finished: Upload Email batches 2-1
2022-04-11 10:57:03,945 INFO o.a.j.e.StandardJMeterEngine: Notifying test listeners of end of test
2022-04-11 10:57:03,946 INFO o.a.j.s.FileServer: Close: C:/Dev/jmeter/apache-jmeter-5.4.3/bin/Test data set/UploadTestEmailBatchesFile.csv
2022-04-11 10:57:03,948 INFO o.a.j.g.u.JMeterMenuBar: setRunning(false, *local*)