Selenium 使用WebDriver在移动设备上进行Galen测试
我正在用Cucumber和Selenium WebDriver编写代码。我可以使用Webdriver启动galenframework测试,所有内容都传递到默认桌面大小(当窗口最大化时)。我试着把尺寸改成移动的。 我查看了文档,在JS中我发现:Selenium 使用WebDriver在移动设备上进行Galen测试,selenium,cucumber,galen,Selenium,Cucumber,Galen,我正在用Cucumber和Selenium WebDriver编写代码。我可以使用Webdriver启动galenframework测试,所有内容都传递到默认桌面大小(当窗口最大化时)。我试着把尺寸改成移动的。 我查看了文档,在JS中我发现: this.devices = { mobile: { deviceName: "mobile", size: "400x700" }, tablet: { deviceName: "tablet", size
this.devices = {
mobile: {
deviceName: "mobile",
size: "400x700"
},
tablet: {
deviceName: "tablet",
size: "600x800"
},
desktop: {
deviceName: "desktop",
size: "1024x768"
}
};
但我找不到基本上类似的东西:
我开始寻找一种解决方法,在布局前设置检查浏览器的大小-它可以工作,页面的大小会改变,但是Galen framework没有看到移动设备上的@
应该在移动设备上完成
迄今为止我的代码(删除了不必要的部分):
步骤。功能:
Feature: First step for regression tests
Scenario: Opening the form
Given Open the Firefox and launch the application
Given Set size the browser to "desktop"
When Login page is opened
When Enter the Username "foo" and Password "abcd"
Then I check layout on "desktop"
Given Set size the browser to "mobile"
Then I check layout on "mobile"
Then I log out
public class Steps {
private WebDriver driver;
private String device ="";
@Given("^Open the Firefox and launch the application$")
public void open_the_Firefox_and_launch_the_application() throws Throwable
{
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\geckodriver.exe");
driver= new FirefoxDriver();
driver.manage().window().maximize();
}
@Given("^Set size the browser to \"([^\"]*)\"$")
public void resizeBrowser(String device) throws Throwable {
if (device.equals("desktop")) {
System.setProperty(device, "desktop");
driver.manage().window().maximize();
}
else if (device.equals("mobile")) {
System.setProperty(device, "mobile");
driver.manage().window().setPosition(new Point(0,0));
driver.manage().window().setSize(new Dimension(400,700));
}
else if (device.equals("tablet")){
System.setProperty(device, "tablet");
driver.manage().window().setPosition(new Point(0,0));
driver.manage().window().setSize(new Dimension(800,600));
}
}
@When("^Login page is opened$")
public void openingLoginPage() throws Throwable {
driver.get("foo");
}
@When("^Enter the Username \"(.*)\" and Password \"(.*)\"$")
public void enter_the_Username_and_Password(String username,String password) throws Throwable
{
driver.findElement(By.name("login")).sendKeys(username);
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.cssSelector("input[type=submit]")).click();
}
@Then("^I check layout on \"(.*)\"$")
public void DesignCheck() throws Throwable {
Helper.confirmationEmailPageLayoutTest(driver, device);
}
@When("^I log out$")
public void logOut() throws Throwable {
Helper.logOut(driver);
}
}
@objects
header css .container-fluid
titlebar id call-details-header
text h1
clearbtn a
image img
text span
PageFForm id tmpComponent(...)
@on mobile, desktop
= header =
header:
height > 20 px
width ~ 98 % of screen/width
= titlebar =
titlebar:(...)
= Page =
PageFForm:
height > 3000 px
PageFForm.allsections:(...)
@on desktop
= titlebar =
titlebar.text:
height < 50 px
= Page =
PageFForm:
width 75 to 95% of screen/width
@on mobile
= titlebar =
titlebar.text:
height < 100 px
= Page =
PageFForm:
width ~98% of screen/width
"PageFForm" width is 90% [1170px] which is not in range of 96 to 100% [1235 to 1287px]
Steps.java:
Feature: First step for regression tests
Scenario: Opening the form
Given Open the Firefox and launch the application
Given Set size the browser to "desktop"
When Login page is opened
When Enter the Username "foo" and Password "abcd"
Then I check layout on "desktop"
Given Set size the browser to "mobile"
Then I check layout on "mobile"
Then I log out
public class Steps {
private WebDriver driver;
private String device ="";
@Given("^Open the Firefox and launch the application$")
public void open_the_Firefox_and_launch_the_application() throws Throwable
{
System.setProperty("webdriver.gecko.driver", System.getProperty("user.dir") + "\\geckodriver.exe");
driver= new FirefoxDriver();
driver.manage().window().maximize();
}
@Given("^Set size the browser to \"([^\"]*)\"$")
public void resizeBrowser(String device) throws Throwable {
if (device.equals("desktop")) {
System.setProperty(device, "desktop");
driver.manage().window().maximize();
}
else if (device.equals("mobile")) {
System.setProperty(device, "mobile");
driver.manage().window().setPosition(new Point(0,0));
driver.manage().window().setSize(new Dimension(400,700));
}
else if (device.equals("tablet")){
System.setProperty(device, "tablet");
driver.manage().window().setPosition(new Point(0,0));
driver.manage().window().setSize(new Dimension(800,600));
}
}
@When("^Login page is opened$")
public void openingLoginPage() throws Throwable {
driver.get("foo");
}
@When("^Enter the Username \"(.*)\" and Password \"(.*)\"$")
public void enter_the_Username_and_Password(String username,String password) throws Throwable
{
driver.findElement(By.name("login")).sendKeys(username);
driver.findElement(By.name("password")).sendKeys(password);
driver.findElement(By.cssSelector("input[type=submit]")).click();
}
@Then("^I check layout on \"(.*)\"$")
public void DesignCheck() throws Throwable {
Helper.confirmationEmailPageLayoutTest(driver, device);
}
@When("^I log out$")
public void logOut() throws Throwable {
Helper.logOut(driver);
}
}
@objects
header css .container-fluid
titlebar id call-details-header
text h1
clearbtn a
image img
text span
PageFForm id tmpComponent(...)
@on mobile, desktop
= header =
header:
height > 20 px
width ~ 98 % of screen/width
= titlebar =
titlebar:(...)
= Page =
PageFForm:
height > 3000 px
PageFForm.allsections:(...)
@on desktop
= titlebar =
titlebar.text:
height < 50 px
= Page =
PageFForm:
width 75 to 95% of screen/width
@on mobile
= titlebar =
titlebar.text:
height < 100 px
= Page =
PageFForm:
width ~98% of screen/width
"PageFForm" width is 90% [1170px] which is not in range of 96 to 100% [1235 to 1287px]
助手方法,该方法运行Galen测试
public static void confirmationEmailPageLayoutTest(WebDriver driver, String device) throws IOException {
//Create a layoutReport object
//checkLayout function checks the layout and returns a LayoutReport object
String pathToSpecs = "/src/galenTests/URF.gspec";
if (System.getProperty("os.name").toLowerCase().contains("win")) {
pathToSpecs = "src\\galenTests\\URF.gspec";
}
LayoutReport layoutReport = Galen.checkLayout(driver, pathToSpecs, Arrays.asList(device));
//Create a tests list
List<GalenTestInfo> tests = new LinkedList<>();
//Create a GalenTestInfo object
GalenTestInfo test = GalenTestInfo.fromString("confirmation email layout");
//Get layoutReport and assign to test object
test.getReport().layout(layoutReport, "check confirmation email layout");
//Add test object to the tests list
tests.add(test);
//Create a htmlReportBuilder object
HtmlReportBuilder htmlReportBuilder = new HtmlReportBuilder();
//Create a report under /target folder based on tests list
htmlReportBuilder.build(tests, "target");
//If layoutReport has errors Assert Fail
if (layoutReport.errors() > 0) {
Assert.fail("Layout test failed");
}
}
您可能希望将设备正确地传递给助手方法:
@Then("^I check layout on \"(.*)\"$")
public void DesignCheck() throws Throwable {
Helper.confirmationEmailPageLayoutTest(driver, System.getProperty(device));
}
下一行获取标记列表(任何,例如浏览器名称、您的设备名称、附加标记名、myTagName)
这意味着在你的规范中,galen知道使用哪个规则/检查
e、 g.@在myTagName上
LayoutReport layoutReport = Galen.checkLayout(driver, pathToSpecs, Arrays.asList(device, myTagName));