Geb: Open new tab for each test - testing

I am trying to open new tab for each iteration of the test for each set of data in the where block.
I am trying like:
setup:
Keys.chord(Keys.CONTROL, "t")
but it does not work.
How to do it?

I solved this problem by this [WRITING AT THE BEGGINING OF THE TEST]:
def cachedDriver = CachingDriverFactory.clearCacheAndQuitDriver()
Now a new window is opened and previous window is closed for every set of data in the where block and it is very helpful for executing thousands of tests.

To open a new window using WebDriver and therefore Geb as well you need to call the window.open() javascript method in the browser you're driving. Using Geb it can be done in the following way:
js.exec "window.open('about:blank', '', '')"

Related

Driver.getWindowHandles() is always returning 1 in IE11 on Windows 10

I know this question is duplicate with below question.
Driver.getWindowHandles() is always returning 1 in IE11 on Windows 10, although there are two windows open
Selenium - getWindowHandles() is returning value 1 irrespective of number of browser opened
But I research and try any solution but cannot resolve problem.
I also try setting follow guideline https://github.com/SeleniumHQ/selenium/wiki/InternetExplorerDriver#required-configuration
but it is not working.
This is my code for testing
WebDriver oldDriver = new InternetExplorerDriver(InternetExplorerDriverService.createDefaultService(), createIEOption(Server.OLD));
WebDriver newDriver = new InternetExplorerDriver(InternetExplorerDriverService.createDefaultService(), createIEOption(Server.NEW));
//waiting page load
TimeUnit.SECONDS.sleep(5);
while(true) {
//for test
TimeUnit.SECONDS.sleep(1);
System.out.println("OLD: " + oldDriver.getWindowHandles().size());
System.out.println("NEW: " + newDriver.getWindowHandles().size());
}
I open many tab but result getWindowHandles() always return 1.
The IE driver cannot connect to and control “manually” opened new tabs (i.e., those opened via Ctrl+t). There is no workaround. Do not attempt to use tabs with the IE driver.
Refer Selenium IE driver returns tab count as 1 while using getWindowHandles method on multiple tabs of same window

Opening a new browser tab

I've tried several functions but none seems to be working? For example:
element, _ := webdriver.FindElement(selenium.ByCSSSelector, "body")
element.SendKeys(selenium.ControlKey + "t")
Selenium is capable of executing javascript within the browser.
To open a new tab get selenium to run the following:
window.open()
I've not used Selenium & Go before - so I can't comment on the syntax. However it's normally along the lines of driver.ExecuteScript("window.open()"). See if your IDE will help you plug the gap.
After you get a new tab, you typically need to use the .switchTo in order to move selenium to another tab.
updated:
Docs suggest....
// ExecuteScript executes a script.
ExecuteScript(script string, args []interface{}) (interface{}, error)
see here

Can we get to know Browser rendering time for each page in JMeter using webDriver sampler?

I am planning to do a load test with around 220 users ,Client is expecting Browser rendering time as well. So I though 1 will create one script for load test ,and create one more script with Selenium script in JMeter to measure rendering time. So that while executing load test , if I execute selenium script as well. It will give the Browser rendering time.
But as I saw, With Selenium sampler ,Aggregate report shows end to end response time. If i want to know the Browser rendering time of each page ,if there any way to get the breakdown?
You have 2 options:
Use a separate WebDriver Sampler per "page" like:
Alternatively you can use WDS.sampleResult.addSubResult function to add "child" results to a single WebDriver Sampler instance, example code would be something like:
WDS.sampleResult.sampleStart()
var seleniumDev = new org.apache.jmeter.samplers.SampleResult()
seleniumDev.setSampleLabel('Selenium main page')
seleniumDev.sampleStart()
WDS.browser.get('https://selenium.dev')
seleniumDev.setResponseCodeOK()
seleniumDev.setSuccessful(true)
seleniumDev.sampleEnd()
WDS.sampleResult.addSubResult(seleniumDev)
var jmeter = new org.apache.jmeter.samplers.SampleResult()
jmeter.setSampleLabel('JMeter main page')
jmeter.sampleStart()
WDS.browser.get('https://jmeter.apache.org')
jmeter.setResponseCodeOK()
jmeter.setSuccessful(true)
jmeter.sampleEnd()
WDS.sampleResult.addSubResult(jmeter)
WDS.sampleResult.sampleEnd()
resulting in the following:
More information: The WebDriver Sampler: Your Top 10 Questions Answered

Not able to open new tab using selenium java in chrome latest version 65.0.3325.162

Below is my code for create new tab,open new window and switch to default window.
CreateNewTab:
jse.executeScript("window.open();");
Switch to OpenNewWindow:
deafultWindowName=driver.getWindowHandle();
for(String winHandle : driver.getWindowHandles()){
driver.switchTo().window(winHandle);}
switchToDefaultContent
driver.switchTo().window(deafultWindowName);
I don't see any error message/issue with code but when I execute it all action gets performed in the main window only and it doesn't open new tab or new window. Please suggest!
Is it possible that you might be using an older syntax?
I usually use this:
((JavascriptExecutor)driver).executeScript("window.open('about:blank','_blank');");
//#Note: if you wanna hit a specific URL, Replace about:blank with you desired URL
You could also try any of the driver methods like:
driver.findElement(By.cssSelector("body")).sendKeys(Keys.CONTROL + "t");

Can't find a popup window opened via target="_blank"

I am working with a website that has a form that submits a POST request and opens the target page in a new window using target="_blank". Firefox opens it in a new window.
When I do a loop like
String titles[];
do {
titles = browser.getAllWindowTitles();
System.out.println(titles.length);
} while (titles.length < 2);
It always prints out 1, even when the new window pops up and loads. How can I select this new window?
I am using DefaultSelenium. I have tried approaching it in other, indirect ways such as direct URL loading, but the site sends POST requests and I'm unable to simulate those.
Try the below alternative code and check if it is working as expected.
Set titles = browser.getAllWindowTitles();
Iterator i = titles.iterator();
while(i.hasNext()){
System.out.println(titles.size);
}