Firefox opens blank page instead of application url – Codeception and selenium2 - php

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('/');

Related

Chromedriver not working with codeception

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 :)

Codeception Acceptance Tests not working

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.

php Codeception not-so-quick start: [PHPUnit\Framework\Exception] Undefined index: ELEMENT

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.

Codeception\Extension\RunProcess not starting processes

PROBLEM:
Yesterday Codeception introduced new extension which should help with starting/stopping Selenium Server, Chrome Driver, etc (more here). However, even it shows that processes are starting - they're actually not.
acceptance.suite.yml
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://127.0.0.1:8080/
browser: chrome
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
extensions:
enabled:
- Codeception\Extension\RunProcess:
- java -jar /home/tajgeer/.executables/bin/selenium-server.jar
- php /home/tajgeer/Repozytoria/Yii2/yii serve
output:
Acceptance Tests (5)
[RunProcess] Starting java -jar /home/tajgeer/.executables/bin/selenium-server.jar
[RunProcess] Starting php /home/tajgeer/Repozytoria/Yii2/yii serve
E AboutCest: Ensure that about works
E ContactCest: Ensure that contact page works
E ContactCest: Contact form can be submitted
E HomeCest: Ensure that home page works
E LoginCest: Ensure that login works
[RunProcess] Stopping php /home/tajgeer/Repozytoria/Yii2/yii serve
[RunProcess] Stopping java -jar /home/tajgeer/.executables/bin/selenium-server.jar
example error:
[ConnectionException] Can't connect to Webdriver at http://127.0.0.1:4444/wd/hub. Please make sure that Selenium Server or PhantomJS is running.
I've already tried to set o+x permissions on both execs - didn't change anything. When I'm trying to run both tools by using entered commands - everything works well.
Could anyone point out what am I doing wrong?
SOLUTION:
Actually... I've solved it on my own. I've forgot about sleep (processes didn't even had a chance to run as tests were very quick). I've changed acceptance.suite.xml to following:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver:
url: http://127.0.0.1:8080/
browser: chrome
- Yii2:
part: orm
entryScript: index-test.php
cleanup: false
extensions:
enabled:
- Codeception\Extension\RunProcess:
0: java -jar /home/tajgeer/.executables/bin/selenium-server.jar
1: php /home/tajgeer/Repozytoria/Yii2/yii serve
sleep: 5

Codeception + Selenium server- browser (chrome) pops up, but web page is always white

Using the latest Codeception.
Tried selenium server 2.40.0 and 2.42.2
Snippit of Config:
enabled:
- WebDriver
WebDriver:
url: 'foo'
browser: chrome
I have chrome web driver in my path.
From cmd line, I kick off the selenium server
java -jar C:\...\vendor\selenium\selenium-server-standalone-2.42.2.jar
From cmd line2,
run acceptance fooCept.php
Chrome opens, but the page is always blank. If I was only running one step, I remember not being able to see anything on the page because it was too quick. But with my latest go around with Codeception, I cannot get to see the web page when I over 30 steps.
Your config syntax is not correct. Try this in acceptance.suite.yml:
modules:
enabled:
- WebDriver
config:
WebDriver:
url: 'http://your.site.dev'
browser: 'chrome'
PHPBrowser was also enabled in the acceptance.suite.yml. Once I removed this, it worked.

Categories