#BAEL-914 SerenityBDD and Screenplay (#2001)
This commit is contained in:
parent
92b67adc12
commit
a48ded75c0
BIN
libraries/chromedriver
Executable file
BIN
libraries/chromedriver
Executable file
Binary file not shown.
@ -26,6 +26,15 @@
|
||||
</dependencies>
|
||||
<extensions>true</extensions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>2.20</version>
|
||||
<configuration>
|
||||
<systemProperties>
|
||||
<webdriver.chrome.driver>chromedriver</webdriver.chrome.driver>
|
||||
</systemProperties>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>net.serenity-bdd.maven.plugins</groupId>
|
||||
<artifactId>serenity-maven-plugin</artifactId>
|
||||
@ -243,6 +252,18 @@
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-screenplay</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.serenity-bdd</groupId>
|
||||
<artifactId>serenity-screenplay-webdriver</artifactId>
|
||||
<version>${serenity.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.rest-assured</groupId>
|
||||
<artifactId>spring-mock-mvc</artifactId>
|
||||
@ -306,7 +327,7 @@
|
||||
<commons.io.version>2.5</commons.io.version>
|
||||
<flink.version>1.2.0</flink.version>
|
||||
<jackson.version>2.8.5</jackson.version>
|
||||
<serenity.version>1.4.0</serenity.version>
|
||||
<serenity.version>1.4.1-rc.3</serenity.version>
|
||||
<serenity.jbehave.version>1.24.0</serenity.jbehave.version>
|
||||
<serenity.jira.version>1.1.3-rc.5</serenity.jira.version>
|
||||
<serenity.plugin.version>1.4.0</serenity.plugin.version>
|
||||
|
@ -0,0 +1,39 @@
|
||||
package com.baeldung.serenity;
|
||||
|
||||
import net.serenitybdd.junit.runners.SerenityRunner;
|
||||
import net.thucydides.core.annotations.Managed;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.openqa.selenium.By;
|
||||
import org.openqa.selenium.Keys;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
import org.openqa.selenium.support.ui.WebDriverWait;
|
||||
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.openqa.selenium.support.ui.ExpectedConditions.visibilityOfElementLocated;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@RunWith(SerenityRunner.class)
|
||||
public class GoogleSearchLiveTest {
|
||||
|
||||
@Managed(driver = "chrome") private WebDriver browser;
|
||||
|
||||
@Test
|
||||
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
||||
browser.get("https://www.google.com/ncr");
|
||||
|
||||
browser
|
||||
.findElement(By.name("q"))
|
||||
.sendKeys("baeldung", Keys.ENTER);
|
||||
|
||||
new WebDriverWait(browser, 5).until(visibilityOfElementLocated(By.cssSelector("._ksh")));
|
||||
|
||||
assertThat(browser
|
||||
.findElement(By.cssSelector("._ksh"))
|
||||
.getText(), containsString("Eugen (Baeldung)"));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
package com.baeldung.serenity;
|
||||
|
||||
import com.baeldung.serenity.pageobjects.GoogleSearchPageObject;
|
||||
import net.serenitybdd.junit.runners.SerenityRunner;
|
||||
import net.thucydides.core.annotations.Managed;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@RunWith(SerenityRunner.class)
|
||||
public class GoogleSearchPageObjectLiveTest {
|
||||
|
||||
@Managed(driver = "chrome") private WebDriver browser;
|
||||
|
||||
GoogleSearchPageObject googleSearch;
|
||||
|
||||
@Test
|
||||
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
||||
googleSearch.open();
|
||||
|
||||
googleSearch.searchFor("baeldung");
|
||||
|
||||
googleSearch.resultMatches("Eugen (Baeldung)");
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package com.baeldung.serenity;
|
||||
|
||||
import com.baeldung.serenity.screenplay.GoogleSearchResults;
|
||||
import com.baeldung.serenity.screenplay.SearchForKeyword;
|
||||
import com.baeldung.serenity.screenplay.StartWith;
|
||||
import net.serenitybdd.junit.runners.SerenityRunner;
|
||||
import net.serenitybdd.screenplay.Actor;
|
||||
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
|
||||
import net.thucydides.core.annotations.Managed;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.openqa.selenium.WebDriver;
|
||||
|
||||
import static net.serenitybdd.screenplay.GivenWhenThen.*;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.CoreMatchers.hasItem;
|
||||
|
||||
/**
|
||||
* Unit test for simple App.
|
||||
*/
|
||||
@RunWith(SerenityRunner.class)
|
||||
public class GoogleSearchScreenplayLiveTest {
|
||||
|
||||
@Managed(driver = "chrome") WebDriver browser;
|
||||
|
||||
Actor kitty = Actor.named("kitty");
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
kitty.can(BrowseTheWeb.with(browser));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenGoogleBaeldungThenShouldSeeEugen() {
|
||||
givenThat(kitty).wasAbleTo(StartWith.googleSearchPage());
|
||||
|
||||
when(kitty).attemptsTo(SearchForKeyword.of("baeldung"));
|
||||
|
||||
then(kitty).should(seeThat(GoogleSearchResults.displayed(), hasItem(containsString("Eugen (Baeldung)"))));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,34 @@
|
||||
package com.baeldung.serenity.pageobjects;
|
||||
|
||||
import net.thucydides.core.annotations.DefaultUrl;
|
||||
import net.thucydides.core.pages.PageObject;
|
||||
import org.openqa.selenium.Keys;
|
||||
import org.openqa.selenium.WebElement;
|
||||
import org.openqa.selenium.support.FindBy;
|
||||
|
||||
import static java.util.concurrent.TimeUnit.SECONDS;
|
||||
import static org.hamcrest.CoreMatchers.containsString;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
|
||||
/**
|
||||
* @author aiet
|
||||
*/
|
||||
@DefaultUrl("https://www.google.com/ncr")
|
||||
public class GoogleSearchPageObject extends PageObject {
|
||||
|
||||
@FindBy(name = "q") private WebElement search;
|
||||
|
||||
@FindBy(css = "._ksh") private WebElement result;
|
||||
|
||||
public void searchFor(String keyword) {
|
||||
search.sendKeys(keyword, Keys.ENTER);
|
||||
}
|
||||
|
||||
public void resultMatches(String expected) {
|
||||
withTimeoutOf(5, SECONDS)
|
||||
.waitFor(result)
|
||||
.waitUntilVisible();
|
||||
assertThat(result.getText(), containsString(expected));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package com.baeldung.serenity.screenplay;
|
||||
|
||||
import net.serenitybdd.core.pages.PageObject;
|
||||
import net.serenitybdd.screenplay.targets.Target;
|
||||
import net.thucydides.core.annotations.DefaultUrl;
|
||||
|
||||
/**
|
||||
* @author baoqiang
|
||||
*/
|
||||
@DefaultUrl("https://www.google.com/ncr")
|
||||
public class GoogleSearchPage extends PageObject {
|
||||
|
||||
public static final Target SEARCH_RESULT_TITLES = Target
|
||||
.the("search results")
|
||||
.locatedBy("._ksh");
|
||||
|
||||
public static final Target SEARCH_INPUT_BOX = Target
|
||||
.the("search input box")
|
||||
.locatedBy("#lst-ib");
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package com.baeldung.serenity.screenplay;
|
||||
|
||||
import net.serenitybdd.screenplay.Actor;
|
||||
import net.serenitybdd.screenplay.Question;
|
||||
import net.serenitybdd.screenplay.questions.Text;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author baoqiang
|
||||
*/
|
||||
public class GoogleSearchResults implements Question<List<String>> {
|
||||
|
||||
public static Question<List<String>> displayed() {
|
||||
return new GoogleSearchResults();
|
||||
}
|
||||
|
||||
public List<String> answeredBy(Actor actor) {
|
||||
return Text
|
||||
.of(GoogleSearchPage.SEARCH_RESULT_TITLES)
|
||||
.viewedBy(actor)
|
||||
.asList();
|
||||
}
|
||||
}
|
@ -0,0 +1,35 @@
|
||||
package com.baeldung.serenity.screenplay;
|
||||
|
||||
import net.serenitybdd.core.steps.Instrumented;
|
||||
import net.serenitybdd.screenplay.Actor;
|
||||
import net.serenitybdd.screenplay.Task;
|
||||
import net.serenitybdd.screenplay.actions.Enter;
|
||||
import net.thucydides.core.annotations.Step;
|
||||
import org.openqa.selenium.Keys;
|
||||
|
||||
/**
|
||||
* @author baoqiang
|
||||
*/
|
||||
public class SearchForKeyword implements Task {
|
||||
|
||||
@Step("{0} searches for '#keyword'")
|
||||
public <T extends Actor> void performAs(T actor) {
|
||||
actor.attemptsTo(Enter
|
||||
.theValue(keyword)
|
||||
.into(GoogleSearchPage.SEARCH_INPUT_BOX)
|
||||
.thenHit(Keys.RETURN));
|
||||
}
|
||||
|
||||
private String keyword;
|
||||
|
||||
public SearchForKeyword(String keyword) {
|
||||
this.keyword = keyword;
|
||||
}
|
||||
|
||||
public static Task of(String keyword) {
|
||||
return Instrumented
|
||||
.instanceOf(SearchForKeyword.class)
|
||||
.withProperties(keyword);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package com.baeldung.serenity.screenplay;
|
||||
|
||||
import net.serenitybdd.screenplay.Actor;
|
||||
import net.serenitybdd.screenplay.Task;
|
||||
import net.serenitybdd.screenplay.actions.Open;
|
||||
import net.thucydides.core.annotations.Step;
|
||||
|
||||
import static net.serenitybdd.screenplay.Tasks.instrumented;
|
||||
|
||||
/**
|
||||
* @author baoqiang
|
||||
*/
|
||||
public class StartWith implements Task {
|
||||
|
||||
public static StartWith googleSearchPage() {
|
||||
return instrumented(StartWith.class);
|
||||
}
|
||||
|
||||
private GoogleSearchPage googleSearchPage;
|
||||
|
||||
@Step("{0} starts a google search")
|
||||
public <T extends Actor> void performAs(T t) {
|
||||
t.attemptsTo(Open
|
||||
.browserOn()
|
||||
.the(googleSearchPage));
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user