I am writing codeception tests with selenium running chrome driver for my local env, which is MacOS, running valet+. I am having issue of getting an error when I try to call methods like see() or click(). However other functions like seeInSource(), executeJS() and grabPageSource() are working fine.
For Example:
$I->see('Go to au site'); //Errors out
while
$I->seeInSource('Go to au site') // works fine
My acceptance.suite.yml is as following.
actor: AcceptanceTester
modules:
enabled:
# - PhpBrowser:
# url: http://npr.test/
- WebDriver:
url: http://npr.test/
browser: chrome
capabilities:
chromeOptions:
w3c: true
goog:chromeOptions:
w3c: true
- \Helper\Acceptance
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
step_decorators: ~
The Error I am getting when I use see or click
php vendor/bin/codecept run acceptance --steps
Codeception PHP Testing Framework v4.1.21
Powered by PHPUnit 8.5.16 by Sebastian Bergmann and contributors.
Acceptance Tests (1) -------------------------------------------------------------------------------------------------------------------------
[RunProcess] Starting chromedriver
LandingPageCest: Landing page test
Signature: LandingPageCest:landingPageTest
Test: tests/acceptance/LandingPageCest.php:landingPageTest
Scenario --
I am on url "http://npr.test"
I am on page "/"
I see "Go to au site"
ERROR
----------------------------------------------------------------------------------------------------------------------------------------------
[RunProcess] Stopping chromedriver
Time: 6.38 seconds, Memory: 10.00 MB
There was 1 error:
---------
1) LandingPageCest: Landing page test
Test tests/acceptance/LandingPageCest.php:landingPageTest
[PHPUnit\Framework\Exception] Undefined index: ELEMENT at vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:228
Scenario Steps:
3. $I->see("Go to au site") at tests/acceptance/LandingPageCest.php:16
2. $I->amOnPage("/") at tests/acceptance/LandingPageCest.php:15
1. $I->amOnUrl("http://npr.test") at tests/acceptance/LandingPageCest.php:14
#1 /Users/techlead/Projects/npr-testing/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:228
#2 Codeception\Module\WebDriver->see
#3 /Users/techlead/Projects/npr-testing/tests/_support/_generated/AcceptanceTesterActions.php:329
#4 /Users/techlead/Projects/npr-testing/tests/acceptance/LandingPageCest.php:16
#5 LandingPageCest->landingPageTest
Artifacts:
Png: /Users/techlead/Projects/npr-testing/tests/_output/LandingPageCest.landingPageTest.fail.png
Html: /Users/techlead/Projects/npr-testing/tests/_output/LandingPageCest.landingPageTest.fail.html
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Also I have looked at issue
Codeception: $i->see(text) but not $i->click(text)
That didn't help me as I am setting my wc3 as true, and if I set it as false my selenium fails to start session.
So after trying a few things what worked for me was to replace my facebook/webdriver to php-webdriver. So my composer json looks like.
{
"require": {
"php-webdriver/webdriver": "^1.11"
},
"require-dev": {
"codeception/codeception": "^4.1",
"codeception/module-phpbrowser": "^1.0.0",
"codeception/module-asserts": "^1.0.0",
"codeception/module-webdriver": "^1.2"
}
}
Run the follwoing commands on your console to add php-driver and remove facebook/webdriver
composer require php-webdriver/webdriver
composer remove facebook/webdriver
Related
So I'm making an automated test with codeception. It was working well using phpbrowser, but the page I want to test uses ajax so I changed to webdriver, following the instructions on the codeception website.
I chose to use chromedriver since I'm only going to be doing this test with chrome, but it's giving me back this error
Acceptance Tests (1) ---------------------------------------------------------------------------------------------------
FirstCest: Login successfully
Signature: FirstCest:loginSuccessfully
Test: tests\acceptance\FirstCest.php:loginSuccessfully
Scenario --
ERROR
------------------------------------------------------------------------------------------------------------------------
Time: 722 ms, Memory: 8.00 MB
There was 1 error:
---------
1) FirstCest: Login successfully
Test tests\acceptance\FirstCest.php:loginSuccessfully
[Facebook\WebDriver\Exception\WebDriverException] JSON decoding of remote response failed.
Error code: 4
The response: 'unknown command: wd/hub/session'
#1 D:\Programas\xampp\htdocs\autTest\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:298
#2 D:\Programas\xampp\htdocs\autTest\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:126
#3 D:\Programas\xampp\htdocs\autTest\vendor\symfony\event-dispatcher\EventDispatcher.php:212
#4 D:\Programas\xampp\htdocs\autTest\vendor\symfony\event-dispatcher\EventDispatcher.php:44
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
I tried changing the chromedriver.exe to the installation path of chrome but it's still the same. I really don't know how to configure the url for chromedriver since it only came as an .exe.
This is my acceptance suite in codeception just in case:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost/ASTechOLE/login.php'
window_size: false # disabled in ChromeDriver
port: 9515
browser: chrome
capabilities:
"goog:chromeOptions": # additional chrome options
- \Helper\Acceptance
Thanks in advance
Update:
I ran chromedriver with ./chromedriver --url-base=/wd/hub
Now it gives me
There was 1 error:
---------
1) FirstCest: Login successfully
Test tests\acceptance\FirstCest.php:loginSuccessfully
[Facebook\WebDriver\Exception\WebDriverException] JSON decoding of remote response failed.
Error code: 4
The response: 'unhandled request'
#1 D:\Programas\xampp\htdocs\autTest\vendor\facebook\webdriver\lib\Remote\HttpCommandExecutor.php:298
#2 D:\Programas\xampp\htdocs\autTest\vendor\facebook\webdriver\lib\Remote\RemoteWebDriver.php:126
#3 D:\Programas\xampp\htdocs\autTest\vendor\symfony\event-dispatcher\EventDispatcher.php:212
#4 D:\Programas\xampp\htdocs\autTest\vendor\symfony\event-dispatcher\EventDispatcher.php:44
ERRORS!
Tests: 1, Assertions: 0, Errors: 1.
Based on your stacktrace, it seems that you are working in Windows.
Try running the chromedriver without leading trailing slash, wd/hub instead of /wd/hub.
Your command then becomes: ./chromedriver --url-base=wd/hub.
I know, Windows can be "fun" sometimes :)
I'm trying to test my Yii2 application by codeception.
I want to see coverage of my code.
I'm running selenium server:
java -jar -Dwebdriver.chrome.driver=chromedriver /path/to/selenium-server-standalone-3.141.59.jar
And i'm running my test in the following way:
./vendor/bin/codecept run `tests/acceptance/callIn/FinishCallCest.php:submitBlank --coverage`
When I'm runinng codeception acceptance test without --coverage everything works fine. And if I'm running codeception unit tests with --coverage I get correctly coverage report.
But, if I run codeception acceptance test with --coverage I seeing following:
localhost:8080 link opens in my browser. And i see "NOT FOUND 404" page from Yii2.
Then redirect to http://localhost:8080/index-test.php?r=call-in%2Ffinish-call&callId=1
happens, and I see the page and test is successfully done.
Why does the localhost:8080 page load first? And how can I fix the error with 0% coverage?
Here's my codeception.yml
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
helpers: tests/_support
settings:
bootstrap: _bootstrap.php
memory_limit: 1024M
colors: true
modules:
config:
Yii2:
configFile: 'config/test.php'
cleanup: false
coverage:
c3_url: http://127.0.0.1:8080/index-test.php/
enabled: true
whitelist:
include:
- models/*
- controllers/*
config:
test_entry_url: http://localhost:8080/idnex-test.php
Here's my acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- Yii2:
part: [orm] # allow to use AR methods
cleanup: false
- WebDriver:
url: 'http://test:test#localhost:8080'
auth: ['test', 'test']
browser: chrome
restart: true
window_size: 1024x768
And here's a codeception test log:
Acceptance Tests (1) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Yii2, WebDriver
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FinishCallCest: Submit blank finish form
Signature: calIn\FinishCallCest:submitBlankFinishForm
Test: tests/acceptance/callIn/FinishCallCest.php:submitBlankFinishForm
Scenario --
Destroying application
Starting application
[ConnectionWatcher] watching new connections
[Fixtures] Loading fixtures
[Fixtures] Done
[GET] http://test:test#localhost:8080/
[Cookies] [{"domain":"localhost","httpOnly":true,"name":"_csrf","path":"/","secure":false,"value":"c99eee70d806de0660302db950c436a04f5a6316b5847caed6de7d1d2e2d896aa%3A2%3A%7Bi%3A0%3Bs%3A5%3A%22_csrf%22%3Bi%3A1%3Bs%3A32%3A%22PXMEKYNF-k-StsR38slXolelVVLuFKTK%22%3B%7D"},{"domain":"localhost","expiry":1543848123.606772,"httpOnly":true,"name":"_identity","path":"/","secure":false,"value":"dacb46519512cd901d6c8ceafb494a3d2893b6cf41a196e111c9c522aa4605c9a%3A2%3A%7Bi%3A0%3Bs%3A9%3A%22_identity%22%3Bi%3A1%3Bs%3A77%3A%22%5B%22corebofs000080000ktnhd8g9vnbio68%22%2C%22corebofs000080000ktnhd8g9vnbio68%22%2C18000%5D%22%3B%7D"},{"domain":"localhost","httpOnly":true,"name":"PHPSESSID","path":"/","secure":false,"value":"06okm3re6q6ncjj6q878sdq88j"}]
I am on page "/index-test.php?r=call-in%2Ffinish-call&callId=1"
[GET] http://test:test#localhost:8080/index-test.php?r=call-in%2Ffinish-call&callId=1
I wait 5
I click "//*[#id="w3"]/div[1]/div[1]/h4/a"
I wait 5
I see "Завершение звонка","//*[#id="w1"]/div[4]/button"
I click "//*[#id="w1"]/div[4]/button"
PASSED
Destroying application
[ConnectionWatcher] no longer watching new connections
[ConnectionWatcher] closing all (0) connections
Suite done, restoring $_SERVER to original
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 24.18 seconds, Memory: 14.00MB
OK (1 test, 1 assertion)
Code Coverage Report:
2018-12-03 09:42:01
Summary:
Classes: 0.00% (0/84)
Methods: 0.00% (0/389)
Lines: 0.00% (0/2706)
Remote CodeCoverage reports are not printed to console
HTML report generated in coverage
everyone!
I have been trying to configure Codeception 2.3.6 with Laravel 5.3.30 running on PHP 7.0.23 powered by WAMP 3.1.0. My functional test cases are running fine, but when I try to run my acceptance test cases, a new chrome window opens and then closes without doing anything.
The output in the HTML Report is Codeception Results OK(0s), while the output on the command line is:
WelcomeCept: Perform actions and see result (0.00s)
Time: 3.24 seconds, Memory: 22.75MB
OK (1 test, 0 assertions)
HTML report generated in file://D:\wamp\www\myApp\tests/_output\report.html
First I start ChromeDriver with the command
chromedriver --url-base=/wd/hub
Then I start Selenium Standalone Server 3.13.0 with the command:
java -Dwebdriver.chrome.driver="chromedriver" -jar selenium-server-standalone-3.13.0.jar -port 4445
Then I run my acceptance test suite which contains a single test file, with the command:
call vendor/bin/codecept run acceptance --html
My acceptance.suite.yml is:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://lcms.com/
window_size: false # disabled in ChromeDriver
port: 9515
browser: 'chrome'
restart: true
wait: 200
capabilities:
unexpectedAlertBehaviour: 'accept'
webStorageEnabled: true
javascriptEnabled: true
- Laravel5:
part: ORM
cleanup: false # can't wrap into transaction
environment_file: .env
- \Helper\Acceptance
My WelcomeCept.php file, just for testing the configuration, is:
<?php
class WelcomeCept
{
public function welcomeTest(AcceptanceTester $I)
{
$I->wantTo('perform actions and see result');
}
}
Please review my workflow and let me know if I'm doing things incorrectly or am missing something.
Thanks!
Update: Same thing is happening using GeckoDriver or PhantomJS in WebDriver mode. The tests are passing with OK but not performing any actions.
Solved! I tried WelcomeCest instead of WelcomeCept and things have fallen into place.
So, I followed the Codeception Quick Start instructions faithfully. I run the first example test using the PhpBrowser...
# Codeception Test Suite Configuration
#
# [further comments omitted]
#
actor: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: 'http://office.localhost/'
browser: 'firefox'
- \Helper\Acceptance
and the test:
<?php
class FirstCest
{
public function frontpageWorks(AcceptanceTester $I)
{
$I->amOnPage('/');
$I->see('We hope you enjoy it');
}
}
and all is well.
Then I change the configuration to this:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://office.localhost/'
browser: 'firefox'
- \Helper\Acceptance
per the instructions, and I have Selenium installed and up and running, and away we go...
1) FirstCest: Frontpage works
Test tests/acceptance/FirstCest.php:frontpageWorks
[PHPUnit\Framework\Exception] Undefined index: ELEMENT
Scenario Steps:
2. $I->see("InterpretersOffice") at tests/acceptance/FirstCest.php:22
1. $I->amOnPage("/") at tests/acceptance/FirstCest.php:21
#1 /opt/www/court-interpreters-office/vendor/facebook/webdriver/lib/Remote/RemoteWebDriver.php:198
#2 Codeception\Module\WebDriver->see
#3 /opt/www/court-interpreters-office/tests/_support/_generated/AcceptanceTesterActions.php:363
#4 /opt/www/court-interpreters-office/tests/acceptance/FirstCest.php:22
#5 FirstCest->frontpageWorks
Selenium is driving Firefox, the page is loaded, the content that $I want to see() is there, so that ain't the problem. I have poked around in the source a bit, but haven't figured this out. I have tried changing $I->see() to $I->seeInSource() and found that does work, FWIW.
Any thoughts?
The problem is apparently that Facebook's php-webdriver isn't compatible with current Firefox.
These threads discuss the issue in more detail, and php-webdriver issue #469 tracks adding full W3C WebDriver support (which will fix the incompatibility).
A workaround is to add the -enablePassthrough false argument when launching Selenium. For example:
java -Dwebdriver.gecko.driver=./geckodriver -jar selenium-server-standalone-3.8.1.jar -enablePassThrough false
Unfortunately, Selenium removed support for pass through mode in 3.9, so you'll have to use an older version.
Another workaround is to switch to Chrome.
In my case the only solution was:
Install chromedriver in a path that is in $PATH (/usr/bin or /bin)
and using in your test class:
$capabilities = DesiredCapabilities::chrome()
It works with executing Selenium standard way:
java -jar selenium-server-standalone-3.14.0.jar
There are different situations on my Ubuntu ver. 18.x:
The vendor files has been for years, I have to rm the vendor fold and rebuild it with php composer.phar require facebook/webdriver for my PHP library.
The version of selenium-server-standalone-x.jar and chromedriver doesn't match. So download more version and try, finally you will get one pair to work.
I'm trying to use codeception for acceptance tests. I decided to use it with Selenium2.
Starting environment:
acceptance.suite.yml:
class_name: WebGuy
modules:
enabled:
- Selenium2
- WebHelper
config:
Selenium2:
url: 'http://nemo.dev'
browser: firefox
delay: 1000
test:
<?php
$I = new WebGuy($scenario);
$I->wantTo('see text');
$I->amGoingTo('/');
$I->see('text');
After build and run Firefox starts, shows blank page, and exits.
In console:
1) Couldn't see text in SigninCept.php
Guy couldn't see "text": 'text' in .
Failed asserting that response contains "text". Response was saved to 'log' directory.
Scenario Steps:
2. I see "text"
1. I am going to /
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
Running Mac OS X 10.8.3, selenium: selenium-server-standalone-2.32.0.jar, PHP 5.3.15.
Failure, white screen screenshot in logs, no understanding of situation.
Pretty basic issue. You should specify the starting page. Always.
Insert this line before commands.
$I->amOnPage('/');