使用 Cucumber 测试不同屏幕尺寸(设备)的行为

发布于 2024-12-13 13:05:02 字数 194 浏览 6 评论 0原文

我正在使用 Cucumber 自动化我的测试,并且我需要自动化移动页面中导航栏的行为,因为这些菜单选项是根据屏幕尺寸显示的...例如:

480px 有菜单 a、菜单 b、菜单 c和菜单 d.

320px有菜单a、菜单c和菜单d。

我的问题是,这可以自动化吗?如果是这样,有人有什么想法吗?

提前致谢, 伊恩

I am automating my tests using cucumber and I have a requirement to automate the behavior of our nav bar within our mobile pages as these menu options are displayed based on screen size...for example:

480px has menu a, menu b, menu c, and menu d.

320px has menu a, menu c, and menu d.

My queston is, is this possible to automate? If so has anyone got any ideas?

Thanks in advance,
Ian

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

各空 2024-12-20 13:05:02

我将其粘贴在我的步骤定义之一中,并且它起作用了:

if Capybara.current_driver == :selenium
  window = Capybara.current_session.driver.browser.manage.window
  window.resize_to(1200, 800)
end

我正在将 Cucumber 与 Capybara 一起使用。

I stuck this in one of my step definitions and it worked:

if Capybara.current_driver == :selenium
  window = Capybara.current_session.driver.browser.manage.window
  window.resize_to(1200, 800)
end

I'm using Cucumber with Capybara.

皓月长歌 2024-12-20 13:05:02

两种可能的选择:

  • 使用真实的浏览器进行测试,例如通过 Selenium,它具有设置窗口大小的方法,应该可以通过 Capybara 中的本机代理方法来调用。
  • 将窗口约束值作为额外的查询字符串传递以进行测试。您的生产代码可以检查它是否存在,并使用它而不是实际的窗口大小。例如 http://example.com/products?constrain_width=480

Two possible options:

  • Test this with a real browser, e.g. via Selenium, which has methods to set the window size, which should be callable via the native agent method in Capybara.
  • Pass a window constraint value in as an extra query string for testing. Your production code can check for the presence of this, and use it instead of the real window size. e.g. http://example.com/products?constrain_width=480
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文