Skip to content
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

How to register webdriver/actor for current running test? #2450

Closed
MHamzaY-E opened this issue May 7, 2021 · 7 comments
Closed

How to register webdriver/actor for current running test? #2450

MHamzaY-E opened this issue May 7, 2021 · 7 comments
Labels

Comments

@MHamzaY-E
Copy link

I am creating actors during the runtime during a junit test. For these actors screenshots do not appear in the report. From what I have found is that I got to use

@Managed
WebDriver driver;

inside the test class. As the serenity runner initializes and uses this driver to get screenshots. But I do not know how many actors will be created during runtime. So I am creating actors in the code without predefining them in the main test class.

How can I register drivers of the dynamically created actors ? I have tried this

ThucydidesWebDriverSupport.getWebdriverManager().registerDriver(BrowseTheWeb.as(actor).getDriver());

as the code inside the registerDriver method kinda suggests that it registers the driver to current test.

@Override
   public void registerDriver(WebDriver driver) {
       if (driver != null) {
           inThisTestThread().registerDriverCalled(nameOf(driver)).forDriver(driver);
           inThisTestThread().setCurrentDriverTo(driver);
       }
   }

But it did not work. So how can I pass the webdriver/actors to current test so it can take the screenshots.

@globalworming
Copy link
Collaborator

Just out of curiosity, why don't you know how many actors you need?

I am pretty sure you problem disappears when you get your actors from a new OnlineCast()

@wakaleo
Copy link
Member

wakaleo commented May 11, 2021

As @globalworming says, try using an OnlineCast

@MHamza-Y
Copy link

MHamza-Y commented May 12, 2021

As @globalworming says, try using an OnlineCast

I tried this before using managed driver,

OnStage.setTheStage(new OnlineCast());
Actor actor = OnStage.theActorCalled("James");

I declared this inside a junit rule called SetTheStage . In the test I am calling this and some other rules.

public SetTheStage stage = new SetTheStage("James");

public LoginToXXXXX login = new LoginToXXXXX();

public NavigationRule navigationRule = new NavigationRule(XXXXXpage.class);

@Rule
public TestRule chain = RuleChain.outerRule(stage).around(login).around(navigationRule);

Inside my test script

givenThat(theActorInTheSpotlight()).wasAbleTo(...);

And for the part where I create actors during runtime. I am calling OnStage.theActorCalled(<some name>)
The code works fine. But no screenshots are recorded. For both the actor James and dynamically created ones with OnlineCast

@MHamza-Y
Copy link

Just out of curiosity, why don't you know how many actors you need?

I am pretty sure you problem disappears when you get your actors from a new OnlineCast()

My script creates n instances of something. Each Instance have its own IP. I have to open each IP address in the browser and verify something.

@wakaleo
Copy link
Member

wakaleo commented May 12, 2021

@rules are going to be outside of the Serenity/Screenplay lifecycle I suspect (they will depend on the JUnit runner). Why not just put this logic in a @before method?

@MHamza-Y
Copy link

MHamza-Y commented May 14, 2021

@rules are going to be outside of the Serenity/Screenplay lifecycle I suspect (they will depend on the JUnit runner). Why not just put this logic in a @before method?

This way I can make many reusable rules and chain them up. The advantage would be flexibility. Instead of making separate base classes for each small group of tests with slight setup variations. Also it would follow composition over inheritance rule.

@wakaleo
Copy link
Member

wakaleo commented May 15, 2021

Rules are managed outside the Serenity lifecycle so there is no guarantee that they will work this way.

@wakaleo wakaleo closed this as completed Feb 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants