java - 在同一场景中在移动和桌面浏览器/驱动程序之间切换 - java selenium cucumber
问题描述
基本前提是我想在同一场景中在默认(桌面)和移动仿真之间来回切换(你称之为不同的驱动程序吗?或不同的选项卡/窗口?)。
任何导航到后端的东西都将始终使用默认驱动程序。如果 maven 命令行中存在移动标签,前端导航将使用移动仿真@mobile
(已经让此代码工作)。
默认驱动程序已在现有抽象类中设置,我知道如何设置移动仿真,但我不确定如何在两者之间“切换”。
下面是我想要完成的一个例子:
-------------------------------
DEFAULT NAVIGATION FEATURE FILE
-------------------------------
@navigation
# no @mobile tag so both steps use default driver
Feature: Navigate to back and front ends
Scenario: Navigate to back end then front end
When I navigate to the back end (default driver)
When I navigate to the front end (default driver)
------------------------------
MOBILE NAVIGATION FEATURE FILE
------------------------------
@navigation
# @mobile tag so want to toggle between both drivers
@mobile
Feature: Navigate to back and front ends
Scenario: Navigate to back end then front end
When I navigate to the back end (default driver)
When I navigate to the front end (mobile emulation)
------------
DRIVER CLASS
------------
public class GetWebDriver() {
public GetWebDriver() {
}
public static WebDriver driver(boolean mobile) {
WebDriver driver;
if (mobile) {
// close desktop if it's open???
driver = mobile emulation;
} else {
// close mobile if it's open???
driver = default;
}
}
return driver;
}
--------------
NAVIGATE CLASS
--------------
import static com.postmedia.automation.browser.AbstractPage.driver; // this is currently how we're setting up driver in our classes
public class NavigateToSite() {
public NavigateToSite() {
}
public void navigateFrontEnd(boolean mobile) {
GetWebDriver.driver(mobile).get("frontEndUrl"); // mobile or desktop
}
public void navigateBackEnd() {
GetWebDriver.driver(false).get("backEndUrl"); // always use default
}
}
解决方案
推荐阅读
- javascript - 如何使用codeigniter(由javascript代码捕获的图像)将捕获的图像保存在文件夹中?
- php - 如何将复选框数组从 FormData 传递给 php
- android - 将UTC转换为伊朗当地时间
- javascript - 将一个词转换成另一个词
- javascript - 根据其他数组的内容使对象数组“完整”
- recursion - Elixir: What does a multiple-generator list comprehension look like without the syntax sugar?
- jquery - 在 datedropper 中不工作的数据禁用天
- javascript - React 组件更新时刷新页面
- php - 对数组进行数字排序
- java - 为什么在 void 方法中不允许 this()?