How do I fix the route for acceptance tests? - yii2

I am trying to run acceptance tests on the yii2 advanced app. Out of the box the acceptance tests fail. I will just start with the first problem: I think the routes are wrong and I have no idea where to look to fix them. The error for the about page for example says:
Can't be on page "/frontend/web/index-test.php/site/about":
"/frontend/web/index-test.php/site/signup"
Where did it get this route from?? Of course there is no page there, that route is garbage. i tried putting it in a browser .. nothing .. of course. I would love to step through the testing classes to see what's going on but I can't figure that out either. Anyone have an idea on this? I think if I can get the routes right at least I can get somewhere.

Updated answer:
Make sure that you run php -S localhost:8080from the project root, and not from the test directory!
I just tried that, and got pretty much the same errors as you do.
Original answer:
Out of the box, you will need to do a couple of things before the tests can be run.
yii2-app-advanced tests readme
Install Codeception globally.
Create test db.
Go to tests/codeception/configand look at / edit config.php (see below)
Run migrations: codeception/bin/yii migrate
Fire up a webserver: php -S localhost:8080
Navigate to each of the directories in tests/codeceptionthat you want to test for - like frontend
Run codecept build
Run codecept run
It does run and it does succeed out of the box - provided that you haven't changed any code. :)
If you did change some code, then the tests breaks, and you will have to fix it.
tests/codeception/config/config.php:
'components' => [
'db' => [
'dsn' => 'mysql:host=localhost;dbname=name_of_test_db',
],
Edit:
That route looks fine to me, btw. I guess the issue is that you haven't fired up a webserver before engaging the tests.
You might need to fix your document roots, as described here: Installation Guide

Related

Cypress mocha-junit-reporter - pass test filename to reporter output filename

I'm using Cypress to run a suite of automated tests.
The current version of cypress provides mocha-junit-reporter out of the box, and provides configuration options to pass to the reporter. One of the options is the 'mochaFile'.
I'm using the recommended [hash] tag to output reports across multiple spec files.
this results in a flat mess of files that look like 'results/test-output-abc12345.xml'.
What I want instead is for the test file's relative path and filename to be pass in as the reporter's output file path.
This would give me a structured, feature first view of the output, and in Azure Dev Ops, which aggregates the test output, it would give me correct filenames to detect intermittently failing tests.
Things I've tried that haven't worked:
I've tried to use hooks to modify Cypress's config or set environment variables to try to override the reporterOptions/mochaFile per test at (hopefully) the right time.
I've tried to grab the outputted defaultly-named xml file, and copy it to the correct path+filename given the Cypress.spec.name context, but I can't seem to find the right hook or time to do this.
after and afterEach don't work - I don't think the test report has saved the file yet.
Using a plugin, hooking to some event on test:before:run or test:after:run seem promising, but I'm flying blind since I can't debug into it, so I've been unsucessful in modifying the reporter's output path or copying the file.
I'd love it if someone could show a working example using mocha-junit-reporter, or even a different mocha compatible reporter, if the reporter would play well with Azure Dev Ops, and can help me discover intermittently failing tests.

Yii2 controller/action in windows scheduler

I have found a few questions and answers for this, but I can't make it work. I have a controller (extending controller), and an action. When I try this in PowerShell (as admin):
C:\wamp64\www\project\yii controller/action
a black cmd window is appearing for a moment but certainly doesn't do what it supposed to do, otherwise I could see the results what I'm waiting for. How can I check what is going on in this cmd window? Maybe there is an error message that could help me to find out what is wrong. I have tried -noexit but it's still disappearing.
If I run the controller/action in a browser, it is working.
Once it is working I guess I can add it to windows scheduler.
Try executing as
C:\wamp64\www\project\yii.bat controller/action
I have figured it out:
first, the controller has to be in project\commands. You are in your project folder in CMD and run the following command:
yii controller/action
and that's it.

Gradle Splitting up Testing Tasks with File Structure

I'm trying to make my tasks run tests in a certain directory. I was looking at sourceSets, however I inferred that they are useful if you are running outside the test/groovy folder. All of my tests are within the test/groovy folder.
I've got a set of Geb tests as well as a set of service tests. I would like to run them both together and independently. Essentially my tree structure would look like this, being able to run all tests.
Test
--gebTest
----firefoxTest
----chromeTest
----ieTest
--servicesTest
----service1Test
----service2Test
----service3Test
----etc.
My file structure is as follows:
project
-src
--test
---groovy
----com
-----acme
------functional <---where my geb tests sit
------services <---umbrella for services
-------service1 <---each unique service
-------service2
-------service3
-------etc
Can anyone lend me a hand. For the life of me I don't know how Gradle picks what tests to execute.
Thank you in advanced.
SourceSets are indeed a solution to your problem, but I notice you only differentiate your tests by their package names. I'm not sure but that may prove problematic with source sets.
Personally I would prefer a directory structure like this anyway
src
-test
--groovy
---functional
----com etc
---services
----com etc
However, if you are attached to your current structure then take a look at Gradle's test filtering support, which will allow you to filter by package name.
http://www.gradle.org/docs/current/userguide/java_plugin.html#sec:java_test

Msbuild running in Jenkins target calling HgPull fails with HgProcessException: The command <hg.exe> is not available

I am porting over an MSBuild script from CCnet to run in Jenkins. The MSBuild project is used to create a deployment package. I would rather have Jenkins drive this process itself but that's a longer term aim.
The problem i am having is (as in the title) when we try and use the HgPull target, from the MSBuild mecurial task (http://msbuildhg.codeplex.com/) we get the error message
HgProcessException: The command hg.exe is not available [Path to project]
I have seen on the project web site that someone solved it by adding the LibraryLocation proeprty to the target but that seems to have made no difference. My target currently looks like this:
Target Name="UpdateSources">
<HgPull
LibraryLocation="C:\Program Files\TortoiseHg\hg.exe"
Force="true"
Update="true"
LocalPath="$(SourcePath)"
/>
<HgUpdate
LibraryLocation="C:\Program Files\TortoiseHg\hg.exe"
Clean="true"
LocalPath="$(SourcePath)"
/>
I'm rather at a loss. Please let me know if you need any more information added to this post to solve this issue. I'm really quite new to MSBuild so really not sure where to start investigating this.
EDIT:
One thing i forgot to mention was that i have tried running the MSbuild command in a console window on the build server and still get the same result. This is really odd given it works fine in CCNet, what magic is CCNet doing to make this command work?
This is now resolved, unfortunately i'm not sure what changes i made to correct these. I believe it may have been down to path separators and whether they where trailing or not in another part of the config file. It does so annoy me with the lack of resilience/consistency between applications where you need to specify paths with/without trailing slashes.
Just a thought, but try adding 'C:\Program Files\TortoiseHg' to your system path. Maybe CCNet has it specified somewhere that Jenkins doesn't have access to.
Also, just for sanity's sake, verify that hg.exe actually exists at that location.

Login/Signup tests using Capybara + rspec + selenium, connected to my DB?

I'm trying to write 2 simple tests for my website. It's my first time doing this, and I'm running into a bit of an issue
The test specs are super simple: just fill_in the email + password fields, then I click "signup" or "login" based on which I am testing.
I am facing several issues sadly:
After the click_on("...") call, I have a page.should have_content call. But this never seems to succeed. Selenium closes firefox before I see a successful sign up or login.
For login, I'm not sure how to make sure that the test is using my local database. I am on mysql, and I know my DB is running (I can run queries on mysql administrator), but I don't know if the login is using my DB, and I don't know if the signup is actually putting a new record in my DB.
Thanks a lot for your help in advance!
Ringo
Rspec will use a different database as development and production.
You can check the name of the database in config/database.yml with the environment 'test'.
To see the page which is testing, you can call the method save_and_open_page.
It will open a page in your browser and you will be able to know what's going on.