Selenium IDE and Headless Browser Testing - selenium

How do I run test cases made with Selenium IDE (Firefox Plugin) in a headless browser?
When I create test cases with the firefox plugin it saves them as .html files.
I am trying to setup a way of running them in a headless browser, (using phantomJS or another tool/lib). I have seen many people mention running firefox in a hidden frame, but this is not the same as headless (ie. PhantomJS)
I have already figured out how to run selenium test cases from command line, but only in firefox or ie, I can't get it to run .html testcases on phantomjs:
java -jar selenium-server-standalone-2.39.0.jar -htmlSuite "*firefox" "http://127.0.0.1" "ts-ProjectList/TestSuite.html" "ProjectList-results.html"
I know the IDE can export test cases in different languages, but I want non-tech team members to be able to create tests using the firefox plugin.

Have you looked at http://code.tutsplus.com/tutorials/headless-functional-testing-with-selenium-and-phantomjs--net-30545?
Changing "*firefox" to phantomjs should get you started.
You'll need the phantomJS driver:
http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_phantomjs/selenium.webdriver.phantomjs.webdriver.html

Related

What is the difference between Selenium Grid and pytest-xdist plugin?

I'm new to parallel testing and I was wondering what the difference is between them.
Apparently, pytest-xdist does not need Selenium Grid to run. It can be used with Selenium alone.
Does anybody have any clue or resource where I can learn the difference?
Thanks and kind regards.
Just in case this is useful for anybody I will write down what I learnt:
pytest-xdist: It is used for running parallel tests in the browsers that are installed in the local machine where tests will be run. This means that each test has a browser configured (e.g.: Firefox, Chrome) such as:
driver = webdriver.Firefox()
or
driver = webdriver.Chrome()
And so each test will run with the driver that was specified in the code. Obviously, the local machine needs the browser drivers to be available in any PATH location, so that tests can be run with them.
Selenium Grid: It allows the execution of tests in different browsers, browser versions and operating systems configurations.
Selenium Grid combined with pytest-xdist allows the execution of parallel tests in different browser-OS environments (configured with capabilities, I think).
An execution command example would be:
pytest -n5 -v -s -m "test or ready" --capability browserName firefox
-n5: (pytest parameter) means that 5 instances of the browser will be launched simultaneously.
test or ready: these are the markers that can be combined to execute tests that have these markers.
browserName firefox: It is a capability that indicates that tests must be run in the specified browser, in this case, Firefox. Some possible values are: chrome, firefox, internet explorer, safari.
Some other capabilities are:
version: The browser version to use.
platform: The platform in which the browser will be executed. Some possible values are: WINDOWS, XP, VISTA, MAC, LINUX, UNIX, ANDROID.
To set up the Selenium Grid environment go along the following steps:
Download selenium-server-standalone-[version].jar from
https://www.selenium.dev/downloads/.
Initiate the HUB:
java -jar selenium-server-standalone-[version].jar -role hub
Initiate as many NODES as you want with:
java -jar selenium-server-standalone-[version].jar -role node -hub http://[URL_HUB]/wd/hub
Configure a RemoteDriver in the tests, for example: driver = webdriver.Remote( desired_capabilities = DesiredCapabilities.CHROME, command_executor = 'http://[URL_HUB]:4444/wd/hub')
I still need to learn how to pass the capabilities args as parameters for the RemoteDriver. In conftest.pyfile I can get the capabilities as a list with config.getoption('--capability')). I still need to figure out how to pass the capabilities I want to the setUp method of all my tests.
If someone knows, I will really appreciate a hint on this.
I hope this helps someone who is as lost as I was at the beginning :)

How to keep data after headless browser selenium tests are passed?

Currently, we are using selenium for the automation test within our projects. We are using PhantomJs WebDriver to be able to run headless browser tests on bamboo. We want to be able to see the data(or content) which are created and saved by tests using PhantomJs but looks like the content will be gone after that tests are passed.
If we run the tests on Firefox driver without PhantomJs, we can see the content (or data) which is created by tests.
How we could config Phantomjs WebDriver in selenium to be able to see new content (or data) after running tests?
Any suggestion?

Selenium Junits on headless browser

I have recorded scripts through Selenium IDE and converted them to JUnit 4 Webdriver scripts.
Of course converted scripts had to be changed to run smoothly as Junits. Now my next goal is to make these scripts run on CI, So obviously I need some headless browser for this purpose. I found some threads, but I am looking for Junits specifically.
What could be the best solution/approach for this, any help in this regard is appreciated.
Take a look at PhantomJS. It is a headless WebKit-based browser and there is Selenium WebDriver for that called GhostDriver.
That's what i use and is OK but there is also the option of using a headed browser like Firefox or Chrome and then use Xvfb to ignore screen output.

Selenium testing machine

--- TL;DR
At this point I suggest everyone to tied their Continuous Integration server/service to https://ghostinspector.com/
OLD QUESTION
after three days googling and testing I gave up, and I need help.
My objective is allow my co-workers to record one or more tests with Selenium IDE. Export them, upload them into a server, and get this server running these tests using the webdriver with htmlunit. As we build or fix the app, we will upload the tests to make out test library.
Record a test with Selenium IDE is okay. But getting it running is the problem. The machine we intend to let the tests is an linux amazon server. No front-end stuff, no kde, gtk, so no firefox, chrome, etc... This is why I've specified the htmlunit driver.
So far I wasn't able to get this task running even into my machine - Ubuntu 12.04 x86_64.
I downloaded the selenium-server tarball, and tried running:
java -jar selenium-server.jar -htmlSuite "*webdriver" "our.site.org" "/path/to/testsuite1.html" "/path/to/report1.html"
No success. Even changing the "*webdriver" (using other pops-up a browser screen).
I've tried running the server and the standalone server and connecting via browser.
I've tried PHP bindings by facebook.
I've tried PHPUnit and Testing Selenium classes - along with their respectives exported scripts from Selenium Formatters.
I really do not know where I'm slipping. Can anyone give me a safe direction, tutorial, etc, to follow with?
--- EDIT
Okay, my question may be resumed to:
What si the command line that would allow me to run selenese scripts with selenium-server, using the HtmlUnit driver?
Are you using Continuous Integration?
If so, you should consider getting a plugin to have your CI software run the Selenium tests. Works like a charm for me with Jenkins.
Considering your particular setup, you could both have the amazon linux server run the tests with HTMLUnitDriver, and declare other machines (with a GUI and proper browser) as "nodes" to run your test on other browsers.
Link to a tutorial
Have you read this blog post by David Burns (Automated Tester):
http://www.theautomatedtester.co.uk/tutorials/selenium/selenium_rc_setup.htm
He describes the way to run selenese tests using HTMLSuite.
We are going to use the HTMLSuite commands of the Selenium Remote
Control. This allows you run your Selenese Test Suites as is. The
command should look like java -jar selenium-servre.jar -htmlsuite
. Browser
could be : -*firefox
-*chrome
-*iexplore
-*iehta
-*safari
-*custom /path/to/browser
The path to the test suite and the results file should be a full path.
Here is an example command; java -jar selenium-server.jar -htmlsuite
*iexplore http://www.theautomatedtester.co.uk c:\testsuite\testsuite.html c:\testsuite\results.html
I would point out that htmlunit does not seem to be a supported option so I would expect to use -*custom and provide a path to htmlunit.
This is legacy functionality so there is a chance it doesn't work as expected any more. HTMLSuite expects the tests to be in Selenese (HTML table) format, you mention trying with the PHP binding, I would not expect this to work. If you do want to use some PHP bindings I would suggest using Adam Saunter's fork of the facebook bindings, they are the most up to date and best supported.
https://github.com/Element-34/saunter.php
With Selenium WebDriver you can point to start a HtmlUnit in a already started node
In Java you'll do something like this:
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), DesiredCapabilities.HtmlUnit());
To start the node just make sure to set browserName to 'htmlunit'.

Running a Selenium2 IDE test case on the command line

I need to use the Selenium IDE to create tests for projects we are working on, but to then take these tests and run them from the command line.
The situation is that we want our developers to be able to use the IDE to test websites using a central repository of test suites using the Selenium IDE. We also need the same tests (i.e. in the IDE HTML format) to be run by a CI server (Jenkins) on Sauce Labs.
I have found that the export from the IDE isn't great (test cases that worked on the IDE don't work from the command line). I also need to use WebDriver, e.g Selenium2.
This must be possible but I just cannot see how to do it.
Try out Selunit it combines Selenium tests in Selenese HTML format with Continuous Integration. Here is a tutorial how to execute Selenium tests directly from Selenium IDE in Hudson builds and to benefit from its reporting capabilities provided for JUnit, where Selunit transforms Selenium reports to.
Selenium provides a command-line test script runner, but it's well hidden. Check out the -htmlsuite option of selenium-server.jar.
In windows system you have to download selenium-server-standalone-2.32.0.jar and Browser(IE, chrome) driverserver after downlaod you have to open CMD and run command
java -jar selenium-server-standalone-2.0b3.jar -Dwebdriver.ie.driver=.\IEDriverServer32.exe