How do I configure REST module in Codeception to use browserstack? - php

I am writing acceptance codeception tests on a web application. It will require me to check headers, specifically response codes. I have found that the codeception REST module can be used, but it appears to require phpbrowser. I am required though to use browserstack. How would the configuration look using browserstack as aposed to phpbrowser.
My acceptance.suite.yml is currently set up like:
chrome-dev:
modules:
enabled:
- WebDriver
- \Helper\
config:
WebDriver:
url: 'https://XXXXXXXXXXXXXXXXXX.com'
host: 'XXXXXXXX#XXXXXXXX.com:XXXXXXXXXX.browserstack.com'
port: 80
browser: 'chrome'
window_size: maximize
capabilities:
'os': 'Windows'
'os_version': '10'
'browser_version': '57'
'acceptSslCerts': true
'resolution': '1600x1200'
'browserstack.chrome.enablePopups': true
'browserstack.chrome.allowAllCookies': true
My question here is how would I insert the REST module without using phpbrowser? It appears that it may be required, but does anybody know otherwise?

It is impossible - WebDriver and REST modules are incompatible.

Related

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.

How to made to work Codeception + facebook webdriver agent?

okay, i'm setup appium 1.6.3 server on my mac, webdriver agent inspector works great on real device. now i have this config in codeception yml file:
actor: AcceptanceTester
modules:
enabled:
- \Helper\Acceptance
- \Appium\AppiumDriver:
host: 0.0.0.0
port: 4723
dummyRemote: false
resetAfterSuite: true
resetAfterCest: false
resetAfterTest: false
resetAfterStep: false
capabilities:
app : '/Users/kirill/Documents/iCanDeliver/Deliver.app'
platformName : 'ios'
platformVersion : '10.3'
deviceName : 'iPhone (Kirill)'
automationName : 'XCUITest'
udid: c57bcfcc08ee2485d02f30298dc98bef808a39a5
when I concept run any script appium server unlock the real device, deploy app, deploy webdriveragent, connect to webdriveragent, starting app OK,
but how to writing cases? maybe I made something wrong, there is no any info about codeception-webdriveragent.
Thanks!

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

How to use the "cookies" setting for PhpBrowser in codeception's acceptance.suite.yml?

I've tried googling this but I wasn't able to find an answer so I'm posting here.
I'm trying out codeception 2.1.5 on Cloud9 IDE using PHP 5.5.9, looking at writing acceptance tests, and configuring my acceptance.suite.yml file.
I'm trying to have a cookie included in the request made by PhpBrowser as described on the codeception PhpBrowser page. I thought I could do this with the "cookies" setting in acceptance.suite.yml.
acceptance.suite.yml
# Codeception Test Suite Configuration
#
# Suite for acceptance tests.
# Perform tests in browser using the WebDriver or PhpBrowser.
# If you need both WebDriver and PHPBrowser tests - create a separate suite.
class_name: AcceptanceTester
modules:
enabled:
- PhpBrowser:
url: https://dm1-cboudreausf.c9users.io
cookies:
c9_user_cookie:
Name: c9.live.user.sso
Value: somevaluehere
Path: /
Domain: .c9users.io
- \Helper\Acceptance
Here's my HomepageCept.php:
<?php
$I = new AcceptanceTester($scenario);
$I->wantTo('ensure the homepage renders correctly');
$I->amOnPage('/');
$I->see('welcome');
But when I run my test in debug mode like this:
php codecept.phar run --debug
I can see that there are no request cookies:
Ensure the homepage renders correctly (HomepageCept)
Scenario:
* I am on page "/"
[Page] /
[Response] 302
[Request Cookies] []
[Response Headers] {"Location":["https://c9users.io/_user_content/authorize?redirect=https%3A%2F%2Fdm1-cboudreausf.c9users.io%2F"],"Date":["Mon, 21 Dec 2015 22:38:44 GMT"],"Transfer-Encoding":["chunked"],"X-BACKEND":["apps-proxy"],"Content-Type":["text/html"]}
[Redirecting to] https://c9users.io/_user_content/authorize?redirect=https%3A%2F%2Fdm1-cboudreausf.c9users.io%2F
What is the correct syntax for this??
Cookies parameter is not processed by PhpBrowser but passed to Guzzle HTTP Client.
If you run your test and PHP 5.4, then you use Guzzle 5.3, http://docs.guzzlephp.org/en/5.3/clients.html?highlight=cookies
Types: bool / array / GuzzleHttp\Cookie\CookieJarInterface
I don't know if the format that you used works with Guzzle 5.3, but the key-value pairs should be working
cookies:
'c9.live.user.sso': 'somevaluehere'
If you run your test on a newer version of PHP, then you probably use Guzzle 6
http://docs.guzzlephp.org/en/latest/request-options.html#cookies
You must specify the cookies option as a GuzzleHttp\Cookie\CookieJarInterface or false.
I see no way cookies option could be working with Guzzle 6, so I raised the issue in Github: https://github.com/Codeception/Codeception/issues/2653.

Are some Codeception modules incompatible?

I am using Codeception to make acceptance tests for Symfony project. I need to test everything, this means testing pages (html content) as well as the ajax calls they perform (JSON content).
I have enabled the Symfony2 module in my suite settings but I find few methods in it to check JSON strings, so I guess I'm supposed to enable the REST module as well. However, if I do so, other previously existing tests fail.
For instance, this simple test:
public function privateExtranetHome(AcceptanceTester $I)
{
$I->wantTo('test something');
$I->amOnRoute('acme_site_home.es');
$I->assertEquals(
'container',
$I->grabAttributeFrom('#container-slider', 'class')
);
}
This is not a JSON testing test, just an already existing test in my Cest class, that passed when I only had the Symfony2 module enabled, and fails now that I added the REST module. The error message is :
Scenario:
* I am on route "acme_site_home.es"
[Page] http://localhost/es
[User] anon. []
* I grab attribute from "#container-slider","class"
Fatal error: Call to a member function hasAttribute() on null in [...]\Codeception\Module\REST.php on line 993
Maybe the amOnRoute() method is incompatible with the REST module, because when the latter is enabled, I get an empty response. But therefore my question is: is there some documentation, somewhere which states which modules are incompatible and should not be enabled together? Or should I take as a rule of thumb to use a separate suite for each module?
Just in case, my acceptance suite settings are as follows:
class_name: AcceptanceTester
modules:
enabled:
- Asserts
- Db
- Symfony2
- Doctrine2
- \Tests\Helper\Acceptance
And my Codeception settings:
namespace: Tests
actor: Tester
paths:
tests: tests
log: tests/_output
data: tests/_data
support: tests/_support
envs: tests/_envs
settings:
bootstrap: _bootstrap.php
colors: true
memory_limit: 1024M
extensions:
enabled: [ Codeception\Extension\RunFailed ]
modules:
config:
Db:
dsn: 'mysql:host=localhost;dbname=acme_test'
user: 'root'
password: 'blahblah'
dump: 'tests/_data/dump.sql'
populate: false
cleanup: false
Doctrine2:
depends: Symfony2
cleanup: false
PhpBrowser:
url: http://acme.com
WebDriver:
browser: firefox
url: http://acme.com
REST:
depends: Symfony2
url: http://acme.com
REST module is compatible with and relies on framework modules to process requests.
However you discovered an unreported incompatibility - grabAttributeFrom method is defined both modules - Symfony2 and REST. I will raise an issue for that.
There is one workaround you could use - grabAttributeFrom is defined in XML part of REST module, so if your REST requests return only JSON, you could enable JSON functionality only.
REST:
depends: Symfony2
part: JSON

Categories