serenity jbehave multiple browsers - testing

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.

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");

Display selenese-runner results in Jenkins

As I am implementing an automated way to GUI test our webapplication with selenium I ran into some issues.
I am using selenese-runner to execute our Selenium test suites, created with Selenium IDE as a post build action in Jenkins.
This works perfeclty fine, as the build fails when something is wrong, and the build succeeds if all tests are passed. And the results are stored on a per build basis as HTML files, generated be selenese-runner.
My problem is however, that I seem to be unable to find a way, how to display these results in the respective jenkins build.
Does anyone have an idea how to solve this issue. Or maybe I am on the wrong path at all?
Your help is highly appreciated!
I believe the JUnit plugin should do what you want, but it doesn't work for me.
My config uses this shell script to run the tests (you can see the names of all my test suites):
/usr/bin/Xvfb &
export DISPLAY=localhost:0.0
cd ${WORKSPACE}
java -jar ./test/selenium/bin/selenese-runner.jar --baseurl http://${testenvironment} --screenshot-on-fail ./seleniumResults/ --html-result ./seleniumResults/ ./test/selenium/Search_TestSuite.html ./test/selenium/Admin_RegisteredUser_Suite.html ./test/selenium/Admin_InternalUser_Suite.html ./test/selenium/PortfolioAgency_Suite.html ./test/selenium/FOAdmin_Suite.html ./test/selenium/PublicWebsite_Suite.html ./test/selenium/SystemAdmin_Content_Suite.html ./test/selenium/SystemAdmin_MetaData_Suite.html
killall Xvfb
And I can see the result of the most recent test (you can see the name of my jenkins task folder)
http://<JENKINS.MY.COMPANY>/job/seleniumRegressionTest/ws/seleniumResults/index.html
Earlier tests are all saved on the Jenkins server, so I can view them if I need to.

Symfony2 - reset envirnonment based on PHPUnit configuration

I am trying to set up two specific PHPUnit test environments for Symfony2.
I am using Ant to run PHPUnit, so when I run the two commands below I would expect the following results:
ant test
Runs the test suite using MySQL databse. (matching staging and production envs)
ant ramdisk
Runs the test suite using a SQLite ramdisk. (super fast!)
I can figure out how to set up the MySQL & SQLite for PHPUnit individually, quite easily.
How do I get PHPUnit to specify a particular environment to use?
Our base class for testing sets up the environment, but I cannot figure out how to get a argument passed into here from PHPUnit so that I can conditionally set the environment.
I have tried a different bootstrap for ramdisk, but since the base test class sets the environment I could not make much progress.
Any ideas?
I eventually solved this.
PHPUnit can pass variables through to Symfony: http://phpunit.de/manual/3.7/en/appendixes.configuration.html#appendixes.configuration.php-ini-constants-variables

Integration Tests on Geb / Spock + Selenium Grid do not run in parallel

I have the following set-up: an integration tests project which has a suite of tests written in Groovy/Geb + Spock, which are running perfectly both using Selenium WebDriver and Selenium Grid (RemoteWebDriver).
The problem is that no matter how much I try to tweak the "system", I can't get the tests to run in parallel (i.e. although I have 3 slaves [nodes] registered to the hub, only one of the slaves actually receives the requests). I've enforced maxSession=1 to the Selenium nodes and tried different combinations of parallel=classes|methods, threadCount and fork settings in failsafe plugin configuration (pom.xml file).
I have the feeling that the problem lies somewhere between the maven configuration and selenium grid, probably in relation to Geb/Spock config.
Does any of you have any insight on this issue?
PS: someone suggested that running tests in parallel using Geb / Spock is not possible - because for some reason ?Geb? locks the JUnitRunner (not sure what this means).
Add following configuration to your build.gradle file:
tasks.withType(Test) {
maxParallelForks = 3 // here three forks shall open in parallel
forkEvery = 1
include '**/*TestName*.class' // name of your test class
}
There are test frameworks, TestNG for example, that support parallel testing on the method level out of the box.
Spock, as an example to the contrary, does not support it.
But you do not have to have multithreading implemented by your test framework to make this work.
You can use your build tool to run test classes in parallel, both Maven and Gradle support this.
If you are using Maven, this documentation page and examples might help you:
https://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html
Specifically have a look at "Forked Test Execution".
You can run it for sure, The point is you have to put them (your tests) in threads. Here is the link.

selenium RC and Flow control

Currently I am working on selenium IDE, now I need to switch to selenium RC. I have downloaded selenium server.But I really don't know how to proceed further. Even I am not able to start server from command prompt. I have used C:\Selenium RC\selenium-server\jave -jar selenium-server.jar, but it struck in between and not proceeding further..
I am looking for language java or PHP.
Let me know how should I move further for successful execution of scripts by using selenium RC
First of all: save a test suite in Selenium IDE (File > Save Test Suite). You should generate test suite - it will contain information about test cases (which, of course, should also be saved (File > Save Test Case)).
Then you are ready for testing with Selenium RC.
Try it with below command:
java -jar path/to/selenium-server-standalone.jar -htmlsuite "*firefox" "http://google.com" "path/to/your/testsuite1" "path/to/result.html"
result.html - this file will be generated during/after execution.
Be sure that name of browser, URL and paths to test suite and result file are in the quotation marks.
I am using Selenium with PHPUnit. I have got class called, lets say, somethingTest (test classes must have 'Test' at the end of their names) and extended PHPUnit_Extensions_SeleniumTestCase. This class contains several test cases as methods (e.g. function testSomeMethod1() - 'test' at the beginning).
And I run it by command:
phpunit somethingTest.php
As to the second thing:
Unknown command: gotoIf
You should load gotoif extension by adding to the execution command something like: -userExtensions path/to/extension-file
This indicates a JavaScript file that will be loaded into Selenium.
If you choose Java to write code, a better approach would be using an IDE like Eclipse. Once you link the JARs and import them in your Java classes you can write your code quickly and efficiently. On top of that, Ecplise has lot of plugins for testing software like Junit, TestNG's to help you create better test suites. Not to mention a Java IDE is always helpful in debugging test code. Here is a tutorial on how to setup Eclipse with Selenium: http://selftechy.com/2011/05/31/setting-up-selenium-with-eclipse
Hope it helps.