Skip to content

Updated Design Patterns And Development Strategies' Example Scripts #1949

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ There is currently an implementation in Java that ships as part of Selenium 2, b
### Simple Usage

As an example of a UI that we'd like to model, take a look at
the [new issue](https://github.com/SeleniumHQ/selenium/issues/new) page. From the point of view of a test author,
the [new issue](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+) page. From the point of view of a test author,
this offers the service of being able to file a new issue. A basic Page Object would look like:

```java
Expand All @@ -52,18 +52,53 @@ public class EditIssue {
this.driver = driver;
}

public void setSummary(String summary) {
WebElement field = driver.findElement(By.name("summary"));
clearAndType(field, summary);
public void setTitle(String title) {
WebElement field = driver.findElement(By.id("issue_title")));
clearAndType(field, title);
}

public void enterDescription(String description) {
WebElement field = driver.findElement(By.name("comment"));
clearAndType(field, description);
public void setBody(String body) {
WebElement field = driver.findElement(By.id("issue_body"));
clearAndType(field, body);
}

public void setHowToReproduce(String howToReproduce) {
WebElement field = driver.findElement(By.id("issue_form_repro-command"));
clearAndType(field, howToReproduce);
}

public void setLogOutput(String logOutput) {
WebElement field = driver.findElement(By.id("issue_form_logs"));
clearAndType(field, logOutput);
}

public void setOperatingSystem(String operatingSystem) {
WebElement field = driver.findElement(By.id("issue_form_operating-system"));
clearAndType(field, operatingSystem);
}

public void setSeleniumVersion(String seleniumVersion) {
WebElement field = driver.findElement(By.id("issue_form_selenium-version"));
clearAndType(field, logOutput);
}

public void setBrowserVersion(String browserVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-versions"));
clearAndType(field, browserVersion);
}

public void setDriverVersion(String driverVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-driver-versions"));
clearAndType(field, driverVersion);
}

public void setUsingGrid(String usingGrid) {
WebElement field = driver.findElement(By.id("issue_form_selenium-grid-version"));
clearAndType(field, usingGrid);
}

public IssueList submit() {
driver.findElement(By.id("submit")).click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
return new IssueList(driver);
}

Expand All @@ -90,7 +125,7 @@ By extending this base class, we need to implement two new methods:
```java
@Override
protected void load() {
driver.get("https://github.com/SeleniumHQ/selenium/issues/new");
driver.get("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+");
}

@Override
Expand Down Expand Up @@ -123,16 +158,13 @@ public class EditIssue extends LoadableComponent<EditIssue> {
private final WebDriver driver;

// By default the PageFactory will locate elements with the same name or id
// as the field. Since the summary element has a name attribute of "summary"
// as the field. Since the issue_title element has an id attribute of "issue_title"
// we don't need any additional annotations.
private WebElement summary;
private WebElement issue_title;

// Same with the submit element, which has the ID "submit"
private WebElement submit;

// But we'd prefer a different name in our code than "comment", so we use the
// But we'd prefer a different name in our code than "issue_body", so we use the
// FindBy annotation to tell the PageFactory how to locate the element.
@FindBy(name = "comment") private WebElement description;
@FindBy(id = "issue_body") private WebElement body;

public EditIssue(WebDriver driver) {
this.driver = driver;
Expand All @@ -143,25 +175,52 @@ public class EditIssue extends LoadableComponent<EditIssue> {

@Override
protected void load() {
driver.get("https://github.com/SeleniumHQ/selenium/issues/new");
driver.get("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+");
}

@Override
protected void isLoaded() throws Error {
String url = driver.getCurrentUrl();
assertTrue("Not on the issue entry page: " + url, url.endsWith("/new"));
}

public void setSummary(String issueSummary) {
clearAndType(summary, issueSummary);

public void setHowToReproduce(String howToReproduce) {
WebElement field = driver.findElement(By.id("issue_form_repro-command"));
clearAndType(field, howToReproduce);
}

public void setLogOutput(String logOutput) {
WebElement field = driver.findElement(By.id("issue_form_logs"));
clearAndType(field, logOutput);
}

public void setOperatingSystem(String operatingSystem) {
WebElement field = driver.findElement(By.id("issue_form_operating-system"));
clearAndType(field, operatingSystem);
}

public void enterDescription(String issueDescription) {
clearAndType(description, issueDescription);
public void setSeleniumVersion(String seleniumVersion) {
WebElement field = driver.findElement(By.id("issue_form_selenium-version"));
clearAndType(field, logOutput);
}

public void setBrowserVersion(String browserVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-versions"));
clearAndType(field, browserVersion);
}

public void setDriverVersion(String driverVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-driver-versions"));
clearAndType(field, driverVersion);
}

public void setUsingGrid(String usingGrid) {
WebElement field = driver.findElement(By.id("issue_form_selenium-grid-version"));
clearAndType(field, usingGrid);
}

public IssueList submit() {
submit.click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
return new IssueList(driver);
}

Expand Down Expand Up @@ -298,7 +357,7 @@ The "load" method in EditIssue now looks like:
protected void load() {
securedPage.get();

driver.get("https://github.com/SeleniumHQ/selenium/issues/new");
driver.get("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+");
}
```

Expand All @@ -323,9 +382,17 @@ public class FooTest {
public void demonstrateNestedLoadableComponents() {
editIssue.get();

editIssue.setSummary("Summary");
editIssue.enterDescription("This is an example");
editIssue.title.sendKeys('Title');
editIssue.body.sendKeys('What Happened');
editIssue.setHowToReproduce('How to Reproduce');
editIssue.setLogOutput('Log Output');
editIssue.setOperatingSystem('Operating System');
editIssue.setSeleniumVersion('Selenium Version');
editIssue.setBrowserVersion('Browser Version');
editIssue.setDriverVersion('Driver Version');
editIssue.setUsingGrid('I Am Using Grid');
}

}
```

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ LoadableComponentは、PageObjectsの作成の負担を軽減することを目

### 簡単な使用方法

モデル化するUIの例として、[新しいissue](https://github.com/SeleniumHQ/selenium/issues/new)のページをご覧ください。
モデル化するUIの例として、[新しいissue](https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+)のページをご覧ください。
テスト作成者の観点から、これは新しい問題を提出できるサービスを提供します。
基本的なページオブジェクトは次のようになります。

Expand All @@ -49,18 +49,53 @@ public class EditIssue {
this.driver = driver;
}

public void setSummary(String summary) {
WebElement field = driver.findElement(By.name("summary"));
clearAndType(field, summary);
public void setTitle(String title) {
WebElement field = driver.findElement(By.id("issue_title")));
clearAndType(field, title);
}

public void enterDescription(String description) {
WebElement field = driver.findElement(By.name("comment"));
clearAndType(field, description);
public void setBody(String body) {
WebElement field = driver.findElement(By.id("issue_body"));
clearAndType(field, body);
}

public void setHowToReproduce(String howToReproduce) {
WebElement field = driver.findElement(By.id("issue_form_repro-command"));
clearAndType(field, howToReproduce);
}

public void setLogOutput(String logOutput) {
WebElement field = driver.findElement(By.id("issue_form_logs"));
clearAndType(field, logOutput);
}

public void setOperatingSystem(String operatingSystem) {
WebElement field = driver.findElement(By.id("issue_form_operating-system"));
clearAndType(field, operatingSystem);
}

public void setSeleniumVersion(String seleniumVersion) {
WebElement field = driver.findElement(By.id("issue_form_selenium-version"));
clearAndType(field, logOutput);
}

public void setBrowserVersion(String browserVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-versions"));
clearAndType(field, browserVersion);
}

public void setDriverVersion(String driverVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-driver-versions"));
clearAndType(field, driverVersion);
}

public void setUsingGrid(String usingGrid) {
WebElement field = driver.findElement(By.id("issue_form_selenium-grid-version"));
clearAndType(field, usingGrid);
}

public IssueList submit() {
driver.findElement(By.id("submit")).click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
return new IssueList(driver);
}

Expand All @@ -86,7 +121,7 @@ public class EditIssue extends LoadableComponent<EditIssue> {
```java
@Override
protected void load() {
driver.get("https://github.com/SeleniumHQ/selenium/issues/new");
driver.get("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+");
}

@Override
Expand Down Expand Up @@ -118,16 +153,13 @@ public class EditIssue extends LoadableComponent<EditIssue> {
private final WebDriver driver;

// By default the PageFactory will locate elements with the same name or id
// as the field. Since the summary element has a name attribute of "summary"
// as the field. Since the issue_title element has an id attribute of "issue_title"
// we don't need any additional annotations.
private WebElement summary;
private WebElement issue_title;

// Same with the submit element, which has the ID "submit"
private WebElement submit;

// But we'd prefer a different name in our code than "comment", so we use the
// But we'd prefer a different name in our code than "issue_body", so we use the
// FindBy annotation to tell the PageFactory how to locate the element.
@FindBy(name = "comment") private WebElement description;
@FindBy(id = "issue_body") private WebElement body;

public EditIssue(WebDriver driver) {
this.driver = driver;
Expand All @@ -138,25 +170,52 @@ public class EditIssue extends LoadableComponent<EditIssue> {

@Override
protected void load() {
driver.get("https://github.com/SeleniumHQ/selenium/issues/new");
driver.get("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+");
}

@Override
protected void isLoaded() throws Error {
String url = driver.getCurrentUrl();
assertTrue("Not on the issue entry page: " + url, url.endsWith("/new"));
}

public void setSummary(String issueSummary) {
clearAndType(summary, issueSummary);

public void setHowToReproduce(String howToReproduce) {
WebElement field = driver.findElement(By.id("issue_form_repro-command"));
clearAndType(field, howToReproduce);
}

public void setLogOutput(String logOutput) {
WebElement field = driver.findElement(By.id("issue_form_logs"));
clearAndType(field, logOutput);
}

public void setOperatingSystem(String operatingSystem) {
WebElement field = driver.findElement(By.id("issue_form_operating-system"));
clearAndType(field, operatingSystem);
}

public void setSeleniumVersion(String seleniumVersion) {
WebElement field = driver.findElement(By.id("issue_form_selenium-version"));
clearAndType(field, logOutput);
}

public void setBrowserVersion(String browserVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-versions"));
clearAndType(field, browserVersion);
}

public void setDriverVersion(String driverVersion) {
WebElement field = driver.findElement(By.id("issue_form_browser-driver-versions"));
clearAndType(field, driverVersion);
}

public void enterDescription(String issueDescription) {
clearAndType(description, issueDescription);
public void setUsingGrid(String usingGrid) {
WebElement field = driver.findElement(By.id("issue_form_selenium-grid-version"));
clearAndType(field, usingGrid);
}

public IssueList submit() {
submit.click();
driver.findElement(By.cssSelector("button[type='submit']")).click();
return new IssueList(driver);
}

Expand Down Expand Up @@ -294,7 +353,7 @@ EditIssueの "load" メソッドは次のようになります。
protected void load() {
securedPage.get();

driver.get("https://github.com/SeleniumHQ/selenium/issues/new");
driver.get("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+");
}
```

Expand All @@ -319,8 +378,15 @@ public class FooTest {
public void demonstrateNestedLoadableComponents() {
editIssue.get();

editIssue.setSummary("Summary");
editIssue.enterDescription("This is an example");
editIssue.title.sendKeys('Title');
editIssue.body.sendKeys('What Happened');
editIssue.setHowToReproduce('How to Reproduce');
editIssue.setLogOutput('Log Output');
editIssue.setOperatingSystem('Operating System');
editIssue.setSeleniumVersion('Selenium Version');
editIssue.setBrowserVersion('Browser Version');
editIssue.setDriverVersion('Driver Version');
editIssue.setUsingGrid('I Am Using Grid');
}
}
```
Expand Down Expand Up @@ -367,4 +433,4 @@ public class ActionBot {
}
```

これらの抽象化が構築され、テストでの重複が特定されると、ボットの上にPageObjectsを階層化することができます。
これらの抽象化が構築され、テストでの重複が特定されると、ボットの上にPageObjectsを階層化することができます。
Loading
Loading