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

浪尽此生 提交于 2019-12-06 01:59:48

问题


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.


回答1:


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);



回答2:


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




回答3:


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.




回答4:


This should work:

driver.manage().window().setSize(new Dimension(800, 621));



回答5:


driver.Manage().Window.Size = new Size(x, y);

This works fine for me. The x and y are in a feature file.




回答6:


Try this:

This is working fine for me.

Capybara.current_session.driver.browser.manage.window.resize_to(1800, 1000)


来源:https://stackoverflow.com/questions/10806998/how-to-change-the-size-of-the-browser-window-when-running-the-firefoxwebdriverpr

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!