$npx -y skills add LambdaTest/agent-skills --skill serenity-bdd-skillGenerates Serenity BDD tests in Java with Screenplay pattern, rich reporting, and Cucumber integration. Use when user mentions "Serenity", "Screenplay", "@Steps", "Serenity BDD". Triggers on: "Serenity BDD", "Screenplay pattern", "@Steps", "Serenity report".
| 1 | # Serenity BDD Skill |
| 2 | |
| 3 | ## Core Patterns |
| 4 | |
| 5 | ### Step Library Pattern |
| 6 | |
| 7 | ```java |
| 8 | import net.serenitybdd.annotations.Step; |
| 9 | import net.serenitybdd.core.pages.PageObject; |
| 10 | |
| 11 | public class LoginSteps extends PageObject { |
| 12 | |
| 13 | @Step("Navigate to login page") |
| 14 | public void navigateToLogin() { |
| 15 | openUrl(getDriver().getCurrentUrl() + "/login"); |
| 16 | } |
| 17 | |
| 18 | @Step("Enter email: {0}") |
| 19 | public void enterEmail(String email) { |
| 20 | find(By.id("email")).sendKeys(email); |
| 21 | } |
| 22 | |
| 23 | @Step("Enter password") |
| 24 | public void enterPassword(String password) { |
| 25 | find(By.id("password")).sendKeys(password); |
| 26 | } |
| 27 | |
| 28 | @Step("Click login button") |
| 29 | public void clickLogin() { |
| 30 | find(By.cssSelector("button[type='submit']")).click(); |
| 31 | } |
| 32 | |
| 33 | @Step("Should see the dashboard") |
| 34 | public void shouldSeeDashboard() { |
| 35 | assertThat(getDriver().getCurrentUrl()).contains("/dashboard"); |
| 36 | assertThat(find(By.cssSelector(".welcome")).isDisplayed()).isTrue(); |
| 37 | } |
| 38 | } |
| 39 | ``` |
| 40 | |
| 41 | ### Test Class |
| 42 | |
| 43 | ```java |
| 44 | import net.serenitybdd.junit5.SerenityJUnit5Extension; |
| 45 | import net.serenitybdd.annotations.Steps; |
| 46 | import org.junit.jupiter.api.Test; |
| 47 | import org.junit.jupiter.api.extension.ExtendWith; |
| 48 | |
| 49 | @ExtendWith(SerenityJUnit5Extension.class) |
| 50 | public class LoginTest { |
| 51 | @Steps LoginSteps loginSteps; |
| 52 | |
| 53 | @Test |
| 54 | void shouldLoginWithValidCredentials() { |
| 55 | loginSteps.navigateToLogin(); |
| 56 | loginSteps.enterEmail("user@test.com"); |
| 57 | loginSteps.enterPassword("password123"); |
| 58 | loginSteps.clickLogin(); |
| 59 | loginSteps.shouldSeeDashboard(); |
| 60 | } |
| 61 | } |
| 62 | ``` |
| 63 | |
| 64 | ### Screenplay Pattern |
| 65 | |
| 66 | ```java |
| 67 | import net.serenitybdd.screenplay.*; |
| 68 | |
| 69 | public class Login implements Performable { |
| 70 | private final String email, password; |
| 71 | |
| 72 | public Login(String email, String password) { |
| 73 | this.email = email; this.password = password; |
| 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public <T extends Actor> void performAs(T actor) { |
| 78 | actor.attemptsTo( |
| 79 | Enter.theValue(email).into(LoginPage.EMAIL_FIELD), |
| 80 | Enter.theValue(password).into(LoginPage.PASSWORD_FIELD), |
| 81 | Click.on(LoginPage.LOGIN_BUTTON) |
| 82 | ); |
| 83 | } |
| 84 | |
| 85 | public static Login withCredentials(String email, String password) { |
| 86 | return new Login(email, password); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | // Usage |
| 91 | actor.attemptsTo(Login.withCredentials("user@test.com", "pass123")); |
| 92 | actor.should(seeThat(TheWebPage.currentUrl(), containsString("/dashboard"))); |
| 93 | ``` |
| 94 | |
| 95 | ### Reporting |
| 96 | |
| 97 | ```bash |
| 98 | # Run tests — generates rich HTML report |
| 99 | mvn verify |
| 100 | # Report at: target/site/serenity/index.html |
| 101 | ``` |
| 102 | |
| 103 | ### Cloud Execution on TestMu AI |
| 104 | |
| 105 | Add the `serenity-lambdatest` plugin dependency: |
| 106 | |
| 107 | ```xml |
| 108 | <dependency> |
| 109 | <groupId>net.serenity-bdd</groupId> |
| 110 | <artifactId>serenity-lambdatest</artifactId> |
| 111 | <version>${serenity.version}</version> |
| 112 | </dependency> |
| 113 | ``` |
| 114 | |
| 115 | Configure `serenity.conf`: |
| 116 | |
| 117 | ```hocon |
| 118 | webdriver { |
| 119 | driver = remote |
| 120 | remote.url = "https://"${LT_USERNAME}":"${LT_ACCESS_KEY}"@hub.lambdatest.com/wd/hub" |
| 121 | } |
| 122 | |
| 123 | serenity { |
| 124 | take.screenshots = AFTER_EACH_STEP |
| 125 | } |
| 126 | |
| 127 | lambdatest { |
| 128 | build = "Serenity Build" |
| 129 | } |
| 130 | |
| 131 | # LT:Options capabilities |
| 132 | "LT:Options" { |
| 133 | platformName = "Windows 11" |
| 134 | browserVersion = "latest" |
| 135 | visual = true |
| 136 | video = true |
| 137 | console = true |
| 138 | network = true |
| 139 | } |
| 140 | ``` |
| 141 | |
| 142 | Or configure via `serenity.properties`: |
| 143 | |
| 144 | ```properties |
| 145 | webdriver.driver=remote |
| 146 | webdriver.remote.url=https://hub.lambdatest.com/wd/hub |
| 147 | lt.user=${LT_USERNAME} |
| 148 | lt.key=${LT_ACCESS_KEY} |
| 149 | lt.platform=Windows 11 |
| 150 | lt.browserName=chrome |
| 151 | ``` |
| 152 | |
| 153 | ## Setup: Maven with `serenity-core`, `serenity-junit5`, `serenity-screenplay-webdriver`, `serenity-lambdatest` |
| 154 | ## Run: `mvn verify` (generates living documentation) |
| 155 | |
| 156 | ## Deep Patterns |
| 157 | |
| 158 | For advanced patterns, debugging guides, CI/CD integration, and best practices, |
| 159 | see `reference/playbook.md`. |