Today we want to add selenium to our phpunit testcases.
for that we need:
1) composer installed (ubuntu)
http://magento2-tuts.blogspot.de/2016/08/ubuntu-install-composer.html
2) phpunit (ubuntu)
http://magento2-tuts.blogspot.de/2016/08/ubuntu-install-phpunit.html
3) selenium installed (ubuntu)
http://magento2-tuts.blogspot.de/2016/08/install-selenium-rc-server-2-3-on.html
It is possible to use chrome or firefox in your testcases. IE is excluded for now
lets start:
create following structure:
myproject
|__app
|__test
add a file "phpunit.xml" under "myproject"
this tells phpunit to use the composer autoloader, to do the loading
add file "composer.json" under "myproject" with folling content
This will tell composer, wich dependencies to use.
build dependency from a terminal
$ composer install
Add a testclass named GitHubTest.php under "app/test" with following code.
To explain the code above.
At first we are using the facebook testlibrary namespaces to get all the facebook webdriver stuff
setUp()
In the method "setUp()" we are configuring our selenium webdriver and tell the test to use firefox on seleniumhost on port 4443. The port is defined in your selenium startscript under /etc/init.d/selenium
tearDown()
Here we shutdown the current selenium driver instance.
testGitHubHome()
This is the method where we are doing the testing. We are simlly opening "http://github.com" and check the windowtitle for occurence of the word "Github".
Thats it.
Keine Kommentare:
Kommentar veröffentlichen