How to change the size of the browser window when

2019-04-07 17:25发布

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.

6条回答
做自己的国王
2楼-- · 2019-04-07 18:04
driver.Manage().Window.Size = new Size(x, y);

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

查看更多
我欲成王,谁敢阻挡
3楼-- · 2019-04-07 18:05

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

查看更多
别忘想泡老子
4楼-- · 2019-04-07 18:09

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);
查看更多
smile是对你的礼貌
5楼-- · 2019-04-07 18:13

Try this:

This is working fine for me.

Capybara.current_session.driver.browser.manage.window.resize_to(1800, 1000)
查看更多
啃猪蹄的小仙女
6楼-- · 2019-04-07 18:21

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.

查看更多
看我几分像从前
7楼-- · 2019-04-07 18:21

This should work:

driver.manage().window().setSize(new Dimension(800, 621));
查看更多
登录 后发表回答