How to change the size of the browser window when running the FirefoxWebDriverProvider in JBehave Web - selenium

We're using JBehave Web to drive our selenium test suite for a new project and really like the Etsy.com example available on JBehave, especially the Java/Spring maven archetype as this fits in with our architecture.
The biggest problem so far has been documentation, which is why I'm posting here in the hopes that I can get some help from others in a similar situation.
It looks like JBehave Web only provides a "FirefoxWebDriverProvider" class and no corresponding one for Chrome. Has anyone else run into this problem? Have you written your own ChromeDriverProvider?
Also, we need to change the size of the browser that comes up by default and I can't seem to find a way of doing that during the bootstrapping of the test run.
We're using the Maven archetype: jbehave-web-selenium-java-spring-archetype which uses the jbehave-maven-plugin and the "run-stories-with-annotated-embedder" goal so we're using the "Annotated" method of extending the InjectableEmbedder.
If anyone can provide some guidance, I'd really appreciate it, even if just pointers to more examples.

How To Resize Window
webDriverProvider.get().manage().window().setSize(new Dimension(width, height));
You can easily find code like this by navigating through the code. If you are using Eclipse, Open Declaration and Quick Type Hierarchy options are everything you need.
How to Use Chrome Driver
You can use TypeWebDriverProvider or PropertyWebDriverProvider. For instance:
new TypeWebDriverProvider(ChromeDriver.class);

This should work:
driver.manage().window().setSize(new Dimension(800, 621));

What jokka said is correct, justr a side note: Before resizing window, I always put it to top left corner, so I know that WebDriver can "see" everything:
driver.get().manage().window().setPosition(new Point(0, 0));
Obviously, the driver above is assumed healthy instance of WebDriverProvider

We ended up finding this Chrome Driver and it's been working great. It can take a parameter when it is bootstrapped to start in maximized mode and also exposes the capability to add extensions when it starts up.

driver.Manage().Window.Size = new Size(x, y);
This works fine for me. The x and y are in a feature file.

Try this:
This is working fine for me.
Capybara.current_session.driver.browser.manage.window.resize_to(1800, 1000)

Related

Karate Robot: Not able to click button using image

I am using Karate robot for clicking a button using image.
Below is my code:
robot { app: '^Chrome', highlight: true }
robot.input('OracleDriver')
delay(2000)
robot.click('delete.png')
Sometimes I am able to click delete button for delete.png but other times I am not.
So facing this issue intermittently.
Yes, finding by image is indeed not very reliable and should be only used as a backup when normal windows locators don't work.
I have only the following suggestions:
find a windows locator that works. note that you can navigate from a known locator using someElement.parent.firstChild etc: https://github.com/intuit/karate/tree/master/karate-robot#element-api
try to standardize the resolution that works best
see if using OCR works better
contribute code to Karate to make this better
look for another solution
I tried clicking delete button by using it's class and it is very reliable, below is my code
waitFor('.icons8-delete-blue').click()
I also followed #Peter's suggestion (someElement.parent.firstChild) and it worked for me!, below is the code
waitFor('.modal-footer').children[0].click()
Thanks #Peter for the suggestion

Is automated testing of Open Layers possible?

I am attempting to use selenium to test OpenLayers-2.13.1 functionality.
I am having problems with mouse clicks, mouse downs etc....
I found a couple of out-dated posts with similar problems but their resolution didn't help me.
Does anyone know of any software that can be automated to properly test Open Layers.
http://lists.osgeo.org/pipermail/openlayers-users/2012-November/026791.html
We have had some success in using Selenium WebdriverIO in running automated tests of our mapping.
The way we address map click throughs is by exposing a function from the map script from which we can get the pixel location of a feature on the map.
function pixelOfFeature (id) {
return map.getPixelFromCoordinate(...coordinate of feature...)
}
Then in our test script, once on our loaded mapping page, we query the map object for the pixel of the feature we want to click, and using webdriverio we can then move the mouse to the pixel value within the map css selector, and then perform a .buttonPress().
var client = webdriverio.remote(options)
client.moveToObject('.map', pixel[0], pixel[1]).then(function(){
client.buttonPress(0).then(callback)
})
http://webdriver.io/api/action/moveToObject.html
http://webdriver.io/api/protocol/buttonPress.html
We use ol3 however the same approach could be taken for openlayers 2
It's probably too late for the OP but hopefully this might help someone get started.

click() not working occassionally in selenium

I had written a script in selenium webdriver which uses click() to click on a button which is a "dojo" element.
Previously it was working fine but its not working now, i have tried all the possible ways to make it work (using javascipt, waiting for element to be present, checking enabled and disabled options etc etc) but nothing seems to work.
I would really appreciate if anybody could help me out with this. thanks in advance. i am attaching the script and html code for ur reference.
public void Search_Project_Test(String Project_name,String Os_type,String Start_rel,String End_rel) throws InterruptedException, IOException
{
this.Software_type.click();
this.select_os_type(Os_type);
this.search_proj.sendKeys(Project_name);
com.wait_till_pageload();
SORA_Constants.driver.findElement(By.xpath("//button[#id='submit_project_search']")).click();
Thread.sleep(5000);
Try this ! And also check that element is visible on the page
SORA_Constants.driver.findElement(By.id("submit_project_search")).click();
IT worked finally, all I did is upgraded the FireFox version. i was using 23.0 and later switched to 26.0 which resolved the problem. i never knew if selenium had such kind of issues with different versions of firefox. Hope if anyone faces similiar kind of situation later, then this could b helpful. :)
Try this:
SORA_Constants.driver.findElement(By.xpath("//button[#id='submit_project_search']")).SendKeys("\n");
or:
SORA_Constants.driver.findElement(By.xpath("//button[#id='submit_project_search']")).SendKeys(Keys.Enter);

How to check resolution of browser when running Selenium WebDriver

I want to check the resolution of browser when running Selenium WebDriver to change to expected resolution if ii is not correct. Is it possible to do that? Please give me some suggestion for this. Thanks.
None of the earlier answers actually answered the question (You asked how to get and set, rather than maximize or just set).
I don't know what binding you are using, I'll show you Ruby binding as an example, my blog article also shows examples in other bindings.
Full Ruby API doc is here. Java, C# or Python's API docs are here, here and here.
Get the current window size:
initial_size = driver.manage.window.size # type of Selenium::WebDriver::Dimension
Set current window size:
driver.manage.window.size = Selenium::WebDriver::Dimension.new(1024, 768)
Resize current window:
driver.manage.window.resize_to(800, 600)
Maximize current window:
driver.manage.window.maximize
using python bindings you can set the resolution like this
driver = webdriver.Firefox()
driver.get("http://www.google.com")
# Resize the window to the screen width/height
driver.set_window_size(300, 500)
Try this,
driver.manage().window().maximize();
for more info http://selenium.googlecode.com/svn/trunk/docs/api/java/org/openqa/selenium/remote/RemoteWebDriver.RemoteWebDriverOptions.RemoteWindow.html#maximize
Hope it will help you.

Selenium Webdriver hover not working

Selenium Webdriver 2.31.0
with Scala 2.9
Anyone know how to do a mouse hover in Firefox? I'm basically trying to hover over an element to display a tooltip.
This code fails to move the mouse over the element specified.
val webElement = webDriver.findElement(By.cssSelector(myElement.queryString))
val builder = new Actions(webDriver)
val hover = builder.moveToElement(webElement).build()
hover.perform()
I have also tried mouse events without success (as described here WebDriver mouseOver is not working properly with selenium grid)
This is somewhat anecdotal since I don't have an exact technical explanation, but I've experienced this in the past and have remedied by upgrading Selenium.
The first thing I check is to make sure my selenium is up to date. This includes dependencies, standalone-server and browser drivers (though, in this case, not applicable as Firefox is included with Selenium).
Another possible (and more probable) cause, more directly related to Firefox, is Firefox itself. It's been my experience that a Firefox update can, from time to time, break some selenium functions, particularly hovers. I've found that either upgrading selenium, or if no update has been released, downgrading Firefox will solve the problem.
I wish I had more detailed information to give you, but I'm still learning the finer details of this situation myself. If nothing else, I hope this points you in the right direction.
Since you havn't said you got any errors,
After build().perform(), provide a wait method say, Thread.sleep() for certain amount of time, since there are posibilities where mousehover performed in fraction of seconds and it may not be possible to see the tooltip.
Makesure the locator is correct (because you may point to someother locator which doesn't show up any tooltip)
Makesure you firefox supports the mousehover functionality
The code might resemble as same as your's, but give it a try(JAVA),
Actions builder = new Actions(driver);
WebElement we = driver.findElement(locator);
Actions perf= builder.moveToElement(we).build();
perf.perform();
Thread.sleep(1000);
You can look out the link for your ref : #firefox issue
As your issue is in Firefox, you may need to enable Native Events with webdriver, specifically
FirefoxProfile profile = new FirefoxProfile();
profile.setEnableNativeEvents(true);
WebDriver driver = new FirefoxDriver(profile);
I've had to do this to get drag and drop working in Firefox on Unix, although it worked with the same code on a Windows box.