How to wait for Selenium to start during Codeception tests

Example tutorial for how to wait until webdriver and Selenium have started during Codeception PHP tests

If you test using PHP and Codeception you may have run into the issue of how to start Selenium before your tests. Some people use a wait or sleep command but here is a tip to automatically start Selenium during tests and wait for it to start:

Configure acceptance.suite.yml

With the RunProcess extension with can add a special timeout wait command to wait for Selenium to start before starting our tests:

actor: AcceptanceTester
extensions:
    enabled:
        - Codeception\Extension\RunFailed
        # the lines will run the selenium server before tests start and wait for the process to answer on port 4444
        - Codeception\Extension\RunProcess:
            - java -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server.jar
            - "timeout 300 bash -c 'while [[ \"$(curl -s -o /dev/null -w ''%{http_code}'' localhost:4444)\" != '200' ]]; do sleep 5; done' || false"
modules:
    enabled:
        - WebDriver:
           url: "https://playground.mailslurp.com"
           browser: firefox
        - \Helper\Acceptance
step_decorators: ~        

That's it!

More information

For more tips on testing with Codeception see the PHP guide.

Related content

Golang email library

Golang Email Library for sending and receiving emails in Go over SMTP or HTTP/S.

Send and receive email in PHP (without using mail functions)

PHP email API for creating inboxes, sending email, and receiving attachments in code and tests.

Email for testing

Test email accounts for email testing. Alternatives to Mailinator, MailTrap, Mailosaur and more.

How to wait for Selenium to start during Codeception tests

Example tutorial for how to wait until webdriver and Selenium have started during Codeception PHP tests

Email API for email marketing and more

APIs for email marketing and social campaign testing. Send, receive, validate and test emails in code and online.

How to test an email address

Test email accounts for testing email addresses in code or online. Create fake email accounts for testing.

Ready to dive in?Start building email applications today.