Codeception Screenshots on test pass - phantomjs

I see that Codeception takes screenshots if a test fails, is there anyway to make it take screenshots if the tests pass too?
For info, we're using the phantomjs WebDriver.

The best documentation for this I've found is for the WebDriver module
In there there's a description of makeScreenshot() which allows you to take a screenshot at any given point of your tests. It appears that it will put all of the screenshots in one directory so better think about a good naming convention.
Alternatively, we've now got the Recorder extension working which automates the process of taking screenshots at every test step and presents them in a useful report.

You can use Recorder extension with option delete_successful in configuration acceptance.suite.yml (in extensions: part, not modules:)
extensions:
enabled:
- Codeception\Extension\Recorder:
delete_successful: false # keep screenshots of successful tests
Quote from documentation about Recorder and PhantomJS:
Since PhantomJS doesn’t give you any visual feedback, it’s probably a good idea to install Codeception\Extension\Recorder which gives you screenshots of how PhantomJS “sees” your pages.
More information you can find in documentation for Recorder extension: http://codeception.com/extensions#Recorder
How to find screenchots
Results of the last test running you can find in a file _output/records.html. The file contains links to slideshows with screenshots for each test. Just reload the page after the test.

Related

Changing default path for Chrome executable for karate-chrome

I am using the Karate framework to do the API testing. As part of CI efforts, we send an email at the end of test execution listing the summary of test results. There is a need to include the screeshot of the test execution counts from 'overview-feature.html' file.
I did so through the TestRunner.java file - launched Chrome using Chrome.start() and then using it to take screenshot. It all works well locally on Windows.
However when executing on CI server which is a Unix box, the chrome executable is not present in the default location (usr/bin/google-chrome) and hence the connection for the localhost fails.
Is there a way we can change the default location of the chrome executable?
PS: Apologies if this was too trivial to be asked.
Yes Chrome on CI is hard to get right, refer: https://stackoverflow.com/a/62325328/143475 - note that CI boxes typically are "headless" a browser may not be even installed.
I think the best thing for you is to ZIP the HTML and send it. But I really think you need to work with some CI experts, because the report generation and e-mailing business is normally done by things like Jenkins. What you are doing is certainly not normal or best-practice.
If you really want, there is a Karate Docker container that can give you a proper Chrome instance (see docs) but that is overkill for what you need.
EDIT: The Chrome Java API allows for customization of the executable path and this is in the docs: https://github.com/intuit/karate/tree/master/karate-core#chrome-java-api
It should be something like this:
Chrome.start("/opt/blah/chrome");

How to limit the report generation only for specific feature file in karate framework?

I am having 3 feature file and I am trying to execute specific feature in karate using
#CucumberOptions(features = "classpath:Karate/Karate/APIM_LAYER.feature") over the test runner class.
But on execution, we are able to find reports for all the 3 feature files present in the "target/sure-fire reports path".
Please let us know is there a way to resolve this issue.
You should upgrade to V0.6.2, and when you run with #RunWith(Karate.class) with Cucumber options it will run those files sequentially and generate pretty html reports for each feature file.
As for the location of the reports, its usually mentioned in the console/terminal.
So make a testfolderunner.java file. add your cucumber options and then from terminal do mvn test -D test=testfolderunner
Al the best
I'm sure you still have the #RunWith(Karate.class) annotation even though it is clearly mentioned in the documentation that you should NOT use it for the parallel runner. Please confirm.

serenity jbehave multiple browsers

I am trying to setup a test project that uses serenity and jbehave
I am noticing that all examples use serenity.properties that define a browser in it
I would like to structure my tests in a way so that same test can be executed in IE/firefox/chrome etc
How do I do this?
You can pass in properties as command line properties, so you can rerun the same tests with different browsers by passing in different settings for webdriver.driver, e.g.
$ mvn verify -Dwebdriver.driver=firefox
$ mvn verify -Dwebdriver.driver=chrome
etc.
I think you are able to get this to work by creating multiple Junit test classes with each its own driver and execute them all in a single run.
Every test class should be able to assign a specific 'managed' driver (e.g. PhantomJS, Chrome, Firefox). This is documented here: http://www.thucydides.info/docs/serenity/#_serenity_webdriver_support_in_junit
I don't know what the impact this would have on the generated report, hopefully you are still able to identify the feature/driver combination.

How to include failed screenshots into the codeception report

Just started using codeception 2.0.9 and have installed it with phantomjs and got some sample tests running.
Codeception gives a concise html report at the end that summarises passed tests in red and green, which is nice.
In the reporting directory there is also a screenshot of failed tests, e.g. ExampleCest.CheckLabel.fail.png ExampleCest.CheckLabel.fail.html
Question, how can these be (automatically) linked into report.html so that one can see the failed screenshots from the report in the browser?
Yes, there is a enhancement (#3602) to include screenshot in the report, but it's not release in the current version (2.2).
You can check this feature status at https://github.com/Codeception/Codeception/pull/3602.

How to run tests in FitNesse/Slim headless?

we are considering to use FitNesse/Slim.
But is there a way to start all written Tests without browsing the webpage and starting each manually ?
It would be sufficient if there is a one-start-all kind of button somewhere to click.
So either starting all tests from command line (with a report of course) or with on button from the webpage.
Is this doable ?
Thanks in advance
There is a very easy way to do that. You can run FitNesse tests from the command line. You do this by using the following command line:
java -jar lib/fitnesse.jar -c "FrontPage?suite&format=text"
This will run all tests under the FrontPage and show the results as they happen in a command line friendly format. If you change FrontPage to FrontPage.MainSuite, it will run only the tests under that page.
If you have tests that are in different states. Maybe some of them are started but are not done yet. You can add a Suite Tag to the tests that must run, then you can filter the tests that are run. that would look like the following:
java -jar lib/fitnesse.jar -c "FrontPage?suite&suiteFilter=MustBeGreen&format=text"
This is also possible to do using an ANT java task.
Assuming you have a current version of fitnesse and have it running on port 8080, the following link will take you to a page with more details: http://localhost:8080/FitNesse.UserGuide.ControllingFitnesseFromTheCommandLine
Dan has it correct; but the User Guide is also posted online at:
http://fitnesse.org/FitNesse.UserGuide.ControllingFitNesseFromTheCommandLine