JMeter - WebDriver Sampler - waitForPopUp

3k Views Asked by At

I am trying to work out a comparable command to use in jmeter webdriver sampler (JavaScript) how to do a waitForPopUp command. There must be a way. I have something that works for waiting for an element, but I can't work it out for a popup.

Update

I am using this code for waiting for an element:

var wait = new support_ui.WebDriverWait(WDS.browser, 5000)
WaitForLogo = function() {
var logo = WDS.browser.findElement(org.openqa.selenium.By.xpath("//img[@src='/images/power/ndpowered.gif']"))     
}
wait.until(new com.google.common.base.Function(WaitForLogo))

And this works, but I can't work out how reuse this to wait for a popup, that has no name, in Java I have used:

    selenium.waitForPopUp("_blank", "30000");
    selenium.selectWindow("_blank");

And that works, but I can't work out an comparable JavaScript that will work in Jmeter for performance, as I can't get Java working in Jmeter.

2

There are 2 best solutions below

0
On

I was able to get this working using:

    var sui = JavaImporter(org.openqa.selenium.support.ui)

and:

    wait.until(sui.ExpectedConditions.numberOfWindowsToBe(2))
2
On

In WebDriver Sampler you have the following methods:

  • WDS.browser.switchTo.frame('frame name or handle') - for switching to a frame
  • WDS.browser.switchTo.window('window name or handle') - for switching to a window
  • WDS.browser.switchTo.alert() - for switching to a modal dialog
  • WDS.browser.getWindowHandles() - for getting all open browser window handles

See JavaDoc on WebDriver.switchTo method and The WebDriver Sampler: Your Top 10 Questions Answered guide for more details.