Skip to content

Adding info about Scenario #37

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

Closed
wants to merge 4 commits into from
Closed
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
14 changes: 14 additions & 0 deletions src/Codeception/Module/WebDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,20 @@
* until it finally tries to find the form by XPath).
* If speed is a concern, it's recommended you stick with explicitly specifying the locator type via the array syntax.
*
* ###
*
* You can switch between browsers inside your code by injecting `\Codeception\Scenario` into your test like this:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This sentence doesn't make sense to me.

In order to change browsers you have to use

$this->getModule('WebDriver')->_restart(['browser' => $browser]);

as documented at https://codeception.com/docs/modules/WebDriver#_restart

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The idea was to show some example for scenario, see Codeception/Codeception#6035 (comment) - and I couldn't think of another use case as switching the browser ;-)

I now added your line - but will $this->getModule(...) work from within a test at all? Or do I have to think of another use case...?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

getModule method is not accessible in test code, it can only be used in helpers.

* ```php
* use Codeception\Scenario
* public function myTest(AcceptanceTester $I, Scenario $scenario)
* {
* if ('firefox' === $scenario->current('browser')) {
* $this->getModule('WebDriver')->_restart(['browser' => 'chrome']); // See https://codeception.com/docs/modules/WebDriver#_restart
* }
* }
* ```
* See [Get Scenario Metadata](https://codeception.com/docs/07-AdvancedUsage#Get-Scenario-Metadata) for more information on `$scenario`.
*
* ## Public Properties
*
* * `webDriver` - instance of `\Facebook\WebDriver\Remote\RemoteWebDriver`. Can be accessed from Helper classes for complex WebDriver interactions.
Expand Down