Selenium WebDriverでCucumberを使用してコードを書いています。 Webdriverを使用してGalenフレームワークテストを開始すると、すべてがデフォルトのデスクトップサイズ(ウィンドウが最大化されている場合)に渡されます。サイズをモバイル用に変更しようとしました。 私が見つけたJSでドキュメントを確認しました:
this.devices = {
mobile: {
deviceName: "mobile",
size: "400x700"
},
tablet: {
deviceName: "tablet",
size: "600x800"
},
desktop: {
deviceName: "desktop",
size: "1024x768"
}
};
http://galenframework.com/docs/reference-javascript-tests-guide/#Usingstructures
しかし、私は基本的に似たようなものを見つけることができません:http://galenframework.com/docs/reference-galen-spec-language-guide/
レイアウトの前にブラウザのサイズをチェックアウトすることで回避策を見つけ始めました-動作し、ページのサイズが変更されますが、Galenフレームワークには
@on mobile
が表示されませんモバイルで行う必要があります。
これまでの私のコード(不要な部分を削除):
Steps.feature:
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
Steps.java:
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);
}
}
ガレンテストを実行するヘルパーメソッド
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");
}
}
Gspecファイル:
@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]
回答 1 件
関連した質問
- 機能ファイルを実行してエラーが発生した場合、すべての基本的なプラグインとドライバーをセットアップしました
- キュウリの2つの機能ファイル間で共通のステップ定義を再利用する(Java)
- 「enum Identifier」を挿入して、セレンキュウリ統合シナリオでEnumHeaderを完了します
- ステップ定義ファイルから実行される現在のメソッドを返す方法
- Cucumber JVM:グローバルフックの前にタグ付きフックを実行する
- JavaでSelenium Webdriverでキュウリテストを実行しているときにNullポインタ例外を取得する
- 異なるブラウザで機能キュウリを並行して実行することは可能ですか?
- Selenium Cucumber Javaエクステントレポート
- メソッドを呼び出してURLに移動する方法は? Java
デバイスをヘルパーメソッドに適切に渡すことができます。
以下の行はタグのリストを取ります(たとえば、ブラウザ名、デバイス名、追加のタグ名、myTagName)
つまり、あなたの仕様では、galenはどのルール/チェックを使用するかを知っています 例えば@on myTagName