In my previous post of codeception, I posted that how to setup and create codeception acceptance test using phpbrowser. As phpbrowser has following limitation:
So we can integrate codeception with selenium webdriver and can easily handle phpbrowser drawbacks
- Can click only on links with valid urls or form submit buttons
- Not support input fields that are not inside a form
- Not support JavaScript interactions, like modal windows, datepickers, etc.
So we can integrate codeception with selenium webdriver and can easily handle phpbrowser drawbacks
Approach to setup and execute:
1. First download selenium webdriver jar file from selenium site, save into this in your machine a.
2. Open file “acceptance.suite.yml” and set your application url and webdriver like below.
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- AcceptanceHelper
config:
WebDriver:
url: 'https://www.google.com'
browser: firefox
3. Run selenium server using below command.
>>java –jar selenium-server-standalone-2.**.*.jar
4. We need to create acceptance test file, where we can write acceptance test code, to create go to your project root directory and run below command:
>>php codecept.phar
generate:cept acceptance GoogleSearch
You should see that “GoogleSearchCept.php” test file generate into acceptance folder.
Also you can write your code into cest file by using below command.
>>php codecept.phar generate:cest
acceptance GoogleSearch
Now you should see that “GoogleSearchCest.php” file generated having below syntax
use \AcceptanceTester;
class GoogleSearchCest
{
public function _before(AcceptanceTester $I)
{
}
public function _after(AcceptanceTester $I)
{
}
// tests
public function tryToTest(AcceptanceTester $I)
{
}
}
5. Rename and write your acceptance test code into “tryToTest” function and you should write setup code into “before” function
use \AcceptanceTester;
class GoogleSearchCest
{
public function _before(AcceptanceTester $I)
{
}
public function _after(AcceptanceTester $I)
{
}
// tests
public function tryToTest(AcceptanceTester $I)
{
$I->wantTo('Google
search testing keyword');
$I->amOnPage('/');
$I->fillField('q','testing');
$I->click('btnG');
}
}
Execution:
Run command and see the report in “_output” folder
>>php codecept.phar run --steps
No comments:
Post a Comment
Leave your comments, queries, suggestion I will try to provide solution