Serenity BDD结合Appium Screenplay模式不生成步骤截图问题求助
Hey there! Let’s work through this screenshot issue with Appium 1.3.1 and Serenity BDD Screenplay together— I’ve dealt with similar head-scratchers before, so here are the key fixes to check first:
Serenity needs explicit properties to enable step-level screenshots. Open your serenity.properties (or serenity.conf if using HOCON) and confirm these settings are present:
# Critical: Enables screenshots after every step (default is only on failure) serenity.take.screenshots=AFTER_EACH_STEP # Bind to Appium driver serenity.driver.capabilities=appium # Match your device setup (adjust for iOS if needed) serenity.appium.driver.capabilities.platformName=Android serenity.appium.driver.capabilities.deviceName=emulator-5554
If using a .conf file, the HOCON syntax would be:
serenity { take { screenshots = "AFTER_EACH_STEP" } driver { capabilities = "appium" } appium { driver { capabilities { platformName = "Android" deviceName = "emulator-5554" } } } }
In Screenplay, screenshots rely on the Actor having the BrowseTheWeb ability bound to a valid Appium driver. If you’re initializing the driver manually, make sure you’re assigning it correctly to the Actor:
import io.appium.java_client.android.AndroidDriver; import net.serenitybdd.screenplay.Actor; import net.serenitybdd.screenplay.abilities.BrowseTheWeb; import org.openqa.selenium.remote.DesiredCapabilities; import java.net.URL; public class MobileActorSetup { public static Actor createActor(String actorName) throws Exception { DesiredCapabilities caps = new DesiredCapabilities(); caps.setCapability("platformName", "Android"); caps.setCapability("deviceName", "emulator-5554"); caps.setCapability("app", "/path/to/your/app.apk"); AndroidDriver driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), caps); Actor actor = Actor.named(actorName); // This line is critical— don't skip it! actor.can(BrowseTheWeb.with(driver)); return actor; } }
If using Serenity’s managed drivers, ensure your config is set up so Serenity automatically injects the Appium driver into the Actor.
Serenity only captures screenshots for actions it recognizes as steps. For custom tasks, add the @Step annotation to make Serenity aware:
import net.serenitybdd.screenplay.Task; import net.serenitybdd.screenplay.actions.Click; import net.thucydides.core.annotations.Step; public class LoginActions { // Built-in interactions (like Click) are already step-aware public static Task enterUsername(String username) { return Task.where("{0} enters username: " + username, Click.on(LoginPage.USERNAME_FIELD).thenEnter(username) ); } // Custom task methods need @Step to trigger screenshots @Step("{0} taps the login button") public static Task tapLoginButton() { return Task.where("", Click.on(LoginPage.LOGIN_BUTTON)); } }
Without these annotations or using the Task.where() structure, Serenity won’t trigger screenshot captures for your actions.
Appium 1.3.1 is quite outdated (released in 2015), and newer Serenity versions (2.x+) might have compatibility gaps. Try downgrading Serenity to a version that’s known to work with older Appium builds, like the 1.9.x series. For Maven, update your pom.xml:
<dependencies> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-core</artifactId> <version>1.9.49</version> </dependency> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-screenplay</artifactId> <version>1.9.49</version> </dependency> <dependency> <groupId>net.serenity-bdd</groupId> <artifactId>serenity-appium</artifactId> <version>1.9.49</version> </dependency> </dependencies>
Sometimes screenshots are generated but don’t show up in the report. Check the target/site/serenity/screenshots folder after running tests— if you see image files there, the issue is with report rendering. Try regenerating the report:
For Maven:
mvn clean serenity:aggregate
For Gradle:
gradle clean aggregate
Also, delete the target folder before re-running tests to avoid cached data interfering.
If you’re manually calling driver.quit() in your code, you might be closing the driver before Serenity can capture screenshots. Let Serenity handle driver lifecycle through the SerenityRunner— don’t manually terminate the driver unless absolutely necessary.
If none of these fix the issue, sharing a bit more of your task/interaction code and full serenity.properties would help narrow things down further.
内容的提问来源于stack exchange,提问作者renzo.barrios1407

