Skip to content

catp3rson/web-assignment

Repository files navigation

Testing Guidelines

Setting Up

{
    "require-dev": {
        "phpunit/phpunit":"^9",
        "phpunit/phpunit-selenium": "*",
        "php-webdriver/webdriver":"1.9.0"
    }
}

Note: Remember to check the PHP version for compatible versions of the dependencies.

  • Install PHPUnit and Selenium WebDriver as project dependencies by running the following command (in the project folder):
composer update

Note: When rolling out to production, run the following command to avoid installing the development dependencies

composer update --no-dev

Writing the test cases

  • Create a folder named test in the project folder. This is where we store the test cases written in PHP.
  • Test cases should be grouped into test suites. Define the test suites in phpunit.xml. Each test suite corresponds to a seperate folder inside test. The test folder should look like this.

    test folder

    And the phpunit.xml looks something like this

    phpunit.xml

  • Start writing test cases :^)
    Note: In the test/test_setup folder, there are test cases named GoogleSearchxxxxTest.php where xxxx is the browser's name. Execute these test cases first to check if the setup is correct. PHPUnit should output something like this

    test_setup output

Executing the test cases

  • First, run the Selenium server using the following command (run the command in the testing_setup folder):
java -jar selenium-server-standalone-3.141.59.jar
  • Run a specific test case using the following command (run the command in the project folder):
.\vendor\bin\phpunit --debug .\test\xxxxTest.php

where xxxxTest.php is the php file contained in test folder corresponding to the test case you want to run.

  • Run a test suite using the following command (run the command in the project folder):
.\vendor\bin\phpunit --testsuite <name of test suite>

For example,

.\vendor\bin\phpunit --testsuite test_setup

Notes

  • PHPUnit identifies test files by their names. A test file should be named xxxxTest.php. For example, LoginTest.php, SearchTest.php, ... Other names are invalid.
  • A test method should be named testxxx. For example,
public function test_Login () {
    ...
}

Other methods are using the @test annotation in the method’s docblock or calling the method explicitly (not reccommended) (see [2] for more details).

References

[1] https://thecodedeveloper.com/install-composer-windows-xampp/
[2] https://www.lambdatest.com/blog/selenium-php-tutorial/
[3] https://phpunit.de/getting-started/phpunit-9.html
[4] https://docs.oracle.com/javase/10/install/installation-jdk-and-jre-microsoft-windows-platforms.htm
[5] https://www.guru99.com/desired-capabilities-selenium.html
[6] https://www.lambdatest.com/blog/locators-in-selenium-webdriver-with-examples/
[7] https://stackoverflow.com/questions/33016300/selenium-change-language-browser-chrome-firefox
[8] https://github.com/php-webdriver/php-webdriver
[9] https://github.com/sebastianbergmann/phpunit/commit/80754cf323fe96003a2567f5e57404fddecff3bf

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published