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 :)
Related
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
Since there is no official troubleshooting information, it is an uphill struggle for anyone without a more complete knowledge of working with similar systems to install.
I want to address issues specifically for OSX Catalina and the Selenium server/Chromedriver configuration and put them all in one place. I'll also include my problem at the end.
It seems to me that most of the problems revolve around:
An incorrect installation of either Selenium, Codeception or Chromedriver
Conflicting versions of the above (or php?)
Problems with the port the Selenium server runs on
Coding mistakes: typos, old code etc
Lack of knowledge of terminal/java commands
Path problems
Anything I don't know about/my problem
I'll start with the things I have learnt along the way, please help to fill in the gaps or correct anything I state below if you are able.
Incorrect installation
Installing via homebrew seems the most foolproof way.
Selenium
brew install selenium-server-standalone
Chromedriver
brew tap homebrew/cask
brew cask install chromedriver
Then you can run brew doctor to check installation is okay and follow instructions or google issues. More brew commands.
Check conflicting versions
Installed Google Chrome and Chromedriver should be the same version.
Check Chrome by going to "Chrome" at the top left of the app and the "about Google Chrome".
Check Chromedriver by running brew info chromedriver
Port problems
You might have an old server running on a port you're trying to use. Shut it down going to this page in google chrome.
http://localhost:<port number>/selenium-server/driver?cmd=shutDownSeleniumServer
You can specify the port you run Selenium in terminal using the -port flag. Like this
java -jar <location of your server> -port 8090
Then match this in your acceptance.suite.yml config file
url: 'http://localhost:<port number>/wd/hub'
Coding mistakes in config file
The most common ones I've seen is having a slash at the end of the line of code above or not including '/wd/hub'
Formatting is like so:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://192.168.88.100:<port number>/wd/hub'
browser: chrome
- \Helper\Acceptance
And to format extensions (automatically run) is like this:
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
Lack of knowledge of terminal/java commands
Run a codeception test in terminal using
php vendor/bin/codecept run acceptance --steps
You must have first used
cd <location of your code>
Paths
I don't know how to go about checking paths are configured correctly. (are they inside config files that point to the other programs?) but I keep seeing hints of them scattered around.
My Issue
From below log, I think that chromedriver is loading and there is something happening in the browser, but it does not load my website. Instead it loads the page below. Help greatly appreciated!
Log:
Codeception PHP Testing Framework v4.1.8
Powered by PHPUnit 9.4.2 by Sebastian Bergmann and contributors.
Running with seed:
Acceptance Tests (1) --------------------------------------------------------------------------------------------------
[RunProcess] Starting chromedriver
QuizCest: New user_complete quiz
Signature: QuizCest:newUser_completeQuiz
Test: tests/acceptance/QuizCest.php:newUser_completeQuiz
Scenario --
I am on page "/"
I see "Fragrant"
FAIL
-----------------------------------------------------------------------------------------------------------------------
[RunProcess] Stopping chromedriver
Time: 00:02.653, Memory: 10.00 MB
There was 1 failure:
---------
1) QuizCest: New user_complete quiz
Test tests/acceptance/QuizCest.php:newUser_completeQuiz
Step See "Fragrant"
Fail Failed asserting that on page /wd/hub/static/resource/hub.html
--> Sessions
Create Session | Refresh Sessions
Chrome
e999201a1381fb966c9d02785c094ae6 | Capabilities | Take Screenshot | Delete Session | Load Script
Mac OS X 10.15.7 | v3.141.59 | re82be7d358
--> contains "Fragrant".
Scenario Steps:
2. $I->see("Fragrant") at tests/acceptance/QuizCest.php:14
1. $I->amOnPage("/") at tests/acceptance/QuizCest.php:13
Artifacts:
Png: /Applications/MAMP/htdocs/fragrantmandarin.com/tests/_output/QuizCest.newUser.completeQuiz.fail.png
Html: /Applications/MAMP/htdocs/fragrantmandarin.com/tests/_output/QuizCest.newUser.completeQuiz.fail.html
FAILURES!
Tests: 1, Assertions: 1, Failures: 1.
My Config file:
actor: AcceptanceTester
modules:
enabled:
- WebDriver:
url: 'http://localhost:4444/wd/hub'
browser: chrome
- \Helper\Acceptance
extensions:
enabled:
- Codeception\Extension\RunProcess:
- chromedriver
step_decorators: ~
This excellent explanatory guide on how Selenium works led to a breakthrough.
I mistakenly thought the url for the WebDriver was the Selenium server url, but it was actually my MAMP url.
So I changed the port in my code to my MAMP url:
- WebDriver:
url: 'http://localhost:8888/wd/hub'
browser: chrome
- \Helper\Acceptance
And voila, a day of work finally complete. Hallelujah! Hope this helps someone else out.
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('/');
I have got a test case in my test class and some problems with it. I run the script from console. The script is executed to a certain point and then the test fails with error:
Could not connect to the Selenium RC server.
Here is log from console:
PHPUnit 3.5.15 by Sebastian Bergmann.
E
Time: 01:56, Memory: 4.00Mb
There was 1 error:
1) someTest::testSomething
PHPUnit_Framework_Exception: Could not connect to the Selenium RC server.
/var/www/path.../someTest.php:105
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
Line 105 in my test script:
$this->clickAndWait("//a[text()='Next']");
And here is Selenium log:
14:00:40.983 INFO - Command request: click[//a[text()='Next'], ] on session 4222e17607254f41a6a52e13d0fd7cc5
14:00:41.205 INFO - Got result: OK on session 4222e17607254f41a6a52e13d0fd7cc5
14:00:41.207 INFO - Command request: waitForPageToLoad[600000000, ] on session 4222e17607254f41a6a52e13d0fd7cc5
14:02:11.328 INFO - Command request: testComplete[, ] on session 4222e17607254f41a6a52e13d0fd7cc5
14:02:11.328 INFO - Killing Firefox...
14:02:11.506 INFO - Got result: ERROR: Got a null result on session 4222e17607254f41a6a52e13d0fd7cc5
14:02:11.508 INFO - Got result: OK on session
I tried with Selenium Server Standalone 2.19.0, then with 2.20.0 - the same result.
The server is still running, even after test interruption.
My question is:
why this error occurs suddenly and unexpectedly interrupts the script?
PHPUnit 3.5.15
Selenium Server Standalone 2.19.0 & 2.20.0
Firefox 3.6.18
Ubuntu 10.04
Try with $this->click("link=Next");
The reason behind this, When selenium try to find a text and the page is not fully loaded or there are ambiguous text then selenium throws it and shows like "Could not connect to the Selenium RC server". verification/assertion of text is making problem some times.