Configure alpine-sqs for codeception testing - php

Im trying to run API tests enabling Queue module in codeception.
Im running a project which consists on an api running on a vagrant machine, alpine-sqs is running on host:
http://localhost:9325/ web interface of alpine-sqs
http://localhost:9324/queue/default default alpine-sqs queue
I didnt modify default alpine-sqs config. And I have the following configuration in my codeception api suite:
class_name: ApiTester
modules:
enabled:
- Symfony:
app_path: src
environment: dev
- REST:
url: /api
depends: Symfony
- Queue
- \Helper\Api
- Asserts
config:
Queue:
'type': 'aws'
'endpoint': 'http://10.0.2.2:9324'
'version': '2012-11-05'
'region': 'eu-central-1'
When I run the following test:
<?php
$I->seeQueueExists('default');
$I->clearQueue('default');
$I->addMessageToQueue('this is a message', 'default');
$I->seeQueueHasCurrentCount('default', 1);
?>
It fails and the last step throwing the following:
1) CorrectCreationCest: Send valid creation request
Test tests/api/campaigns/create/CorrectCreationCest.php:sendValidCreationRequest
Fail Failed asserting that '0' matches expected 1.
Scenario Steps:
4. $I->seeQueueHasCurrentCount("default",1) at tests/api/campaigns/create/CorrectCreationCest.php:111
3. $I->addMessageToQueue("this is a message","default") at tests/api/campaigns/create/CorrectCreationCest.php:110
2. $I->clearQueue("default") at tests/api/campaigns/create/CorrectCreationCest.php:109
1. $I->seeQueueExists("default") at tests/api/campaigns/create/CorrectCreationCest.php:108
Somehow codeception achieves connecting to alpine-sqs and retrieves queues correctly but when checking message in queue fails, I dont know why.
Thanks

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 do I configure REST module in Codeception to use browserstack?

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.

How can i debug a failed ci build?

i created some tests with PHPUnit and laravel. The tests are running locally successful, but as a gitlab ci job there is an error.
Here is the ci log:
There was 1 failure:
1) Tests\Feature\AuthTest::testAuthLoggedInIsAdmin
Expected status code 200 but received 500.
Failed asserting that false is true.
/builds/XXX/webproject/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.php:55
/builds/XX/webproject/tests/Feature/AuthTest.php:53
For the better debug and finding a solution i need the error trace from the project or the error.log from the webserver.
What is the best practise to debug errors in the ci?
ok, the solution is very simple... i don't delete the question. Here is the solution:
You have to add an artifact to the job. You can set the artifact, that only on failures the artifact is created. If there is an failure on the build, the hole project is dumped to a seperated location. Now you can browse each files on the dump.
.gitlab-ci.yml
stages:
- test
- deploy
php-7.0:
stage: test
type: test
services:
- mysql:latest
image: tetraweb/php:7.0
script:
- bash .gitlab-ci.sh
- php vendor/bin/phpunit --coverage-text --colors=never
artifacts:
when: on_failure
name: "${CI_BUILD_STAGE}_${CI_BUILD_REF_NAME}_FAILED"
paths:
- "."
untracked: false
expire_in: 1 day
deploy:
stage: deploy
# etc...
Here are more informations about artifacts.
You can download the artifacts in the pipelines section in gitlab:

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.

Test multiple urls (files) with codeception and log separate results

I'm trying to create a small test suite for a homework assignment, using Codeception. My idea is to apply a single Cest test scenario to multiple URLs and get the different results, which I can then log by some identification (for example name of the file).
There are two main things I can't figure out:
How to run a single test with different URL and log failed assertions/passed assertions for every test?
How to check every assertion, even if some of them fail?
First part:
I assume you are using Codeception with Selenium.
You can configure this in acceptance.suite.yml:
class_name: AcceptanceTester
modules:
enabled:
- WebDriver
- AcceptanceHelper
config:
WebDriver:
url: 'http://localhost.dev:8000/'
browser: 'firefox'
env:
url1:
modules:
config:
WebDriver:
url: 'http://url-1.dev/'
browser: 'chrome'
url2:
modules:
config:
WebDriver:
url: 'http://url-2.dev/'
browser: 'chrome'
url3:
modules:
config:
WebDriver:
url: 'http://url-3.dev/'
browser: 'chrome'
Then invoke the tests like this:
$ php codecept.phar run acceptance --env url1 --env url2 --env url3
For more details: http://codeception.com/docs/07-AdvancedUsage#Environments
Second part:
If an assertion fails, testing still continues with the subsequent environments. You can also use conditional assertions (those that start with canSee and cantSee), which will allow the test to continue even if the assertion fails.
For more details: http://codeception.com/docs/03-AcceptanceTests#Conditional-Assertions

Categories