Integrating shell scripts with selenium - selenium

I have a situation where we would like to run our Selenium test suite, but
at certain points in the process we would like to execute a shell command
on our machine.
Does Selenium have the capability of executing a shell command and to
receive a response and then to act on those results? Is this possible? If
so, how?
thanks in advance.

You tagged it TestNG meaning you write your Selenium tests in Java. The Selenium framework itself does not have a method to run shell scripts. But Java does, you can just execute commands in your tests and later use the output or input from/for Selenium actions.
Runtime.getRuntime().exec()
Read more:
In the Java documentation: https://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html#exec(java.lang.String[])
How to Run a Shell Command in Java: https://www.baeldung.com/run-shell-command-in-java
Using the output of the Shell command: java runtime.getruntime() getting output from executing a command line program

Selenium is just a library for interacting with web browsers. To strictly answer your question.. the answer is "No, it can not". However, you can easily integrate execution of shell scripts from your test code or framework. How you do that will depend on the language you are using.

Yes you can, but you have to use certain specific libraries along with it in addition to the language you choose eg. If you choose java, you either have to provide repo url via maven or gradle but if you just use python instead since it's highly interpreted, it can pull dynamic content that do pose limitation in Java Selenium, TestNG, PDFBox, POI lib etc. You can deploy a js library of your choice and include that function inside your python code to be invoked via the commands or action that you set your application to.
In short, use Python for purely less troubling dynamic meta extractions, string manipulation, piping output to any other file. Hope that helps.

Related

Is it possible to package Selenium test cases into a runnable appliction

I am creating selenium test to test a web app. I also want to be able to use these test cases as a way for non technical users to automate the first few steps of the process. ~Is this possible?
If you are using testng, generate command to run XML from the command line and then copy the same command to .bat or .cmd file. By a click any user can run those tests/suite.
Of course you can, Selenium automates browsers, it is not a 'test library' you can use it in any program. Just write java program where you use selenium.
You can also write tests (in JUnit or TestNG or any other test runner) and run tests programmatically.

Trying to use Selenium RC

I'm pretty newbie to selenium.
Im trying to configure selenium for a project in my university like the one configured with phppgadmin.
There is no .jar file, I dont need to run anything, dont even need to install libraries, etc... I dont know if this is a RC Server or Webdriver.
Also, I want to use the PHPUnit format, cause this way I can just export test cases from the Firefox Selenium IDE plugin. There is a way to do that?
There is a lot of information, webdrivers, etc in Internet but I believe the way phppgadmin do this is the best way.
If you're just looking for something quick and dirty Selenium 1 imported off of the IDE is probably for you. If in the future you plan on continuing your university project I would highly recommend learning about Selenium Webdriver (Selenium 2).
Just as a small aside: You can export your tests from the selenium IDE in any language you desire, PHP is just one of the many choices that include (Java (JUnit), Java (TestNG), Ruby, and Python). If you're interested in PHPUnit look here http://www.phpunit.de/manual/3.1/en/selenium.html, this will give you the back drop on how to start coding your Selenium Tests.
If you're going to be using the selenium RC you want to go to http://seleniumhq.org/download/. Download Selenium server. You start the server with a java -jar command. So java -jar /path/to/sel/selenium-server-standalone-2.24.1.jar. This will start the RC server and when you're interested in running some tests execute the tests and then selenium server will take care of the rest

How to export Sikuli scripts to java?

I am new to automation and have to use Sikuli, can you all tell me how to export Sikuli script in java also is it possible to integrate those scripts with Selenium....
Thanks in advance.....
"export" scripts to Java is not possible in this sense, since Sikuli scripts are written in Python scripting language and the scripts itself are run using the Jython interpreter (Java base implementation of Python language).
But since the the essential Sikuli features are implemented using Java, you might transcript/translate a script to Java code, since the Sikuli functions are nearly identical on the Python API level and the Java API level.
But if you have more complex Sikuli Scripts, that you want to run from Java code, there are options to do that:
run the script like from command line, but in a subprocess
run the script using Sikuli's ScriptRunner

Selenium: Is there any JS (JavaScript) code coverage tool which we can integrate with Selenium Server/RC

Selenium: Is there any JS (JavaScript) code coverage tool which we can integrate with Selenium Server/RC
Hi,
I want to JS code coverage done by my Selenium Test Suite
Is there any code coverage tool which can be integrated with my existing selenium rc framework??
In theory, you can use any coverage tool that instruments JavaScript code to collect coverage data.
For example, you can use JSCoverage either in proxy mode (for real-time instrumentation) or for static instrumentation to run your Selenium tests off the instrumented code.
One technical hurdle could be to devise a way to accumulate coverage data across multiple pages. The coverage tool of your choice could already have support for accumulation of data from multiple page runs. If not, you might have to handle that bit yourself, but this is probably not something trivial.
I have found the solution for my need, there are multiple tools available but I want a tool which can be integrated with my existing automation easily
Tool is JSCover
http://tntim96.github.io/JSCover/
Just run the Server
Run Server
java -cp JSCover-all.jar jscover.server.SimpleWebServer . 8080
Run Proxy Server
java -jar target/dist/JSCover-all.jar -ws --proxy --port=3128 --report-dir=target
Add Proxy in your Webdriver for port specified, 3128 in my case
After execution of test Generate Reports using
((JavascriptExecutor) driver).executeScript("jscoverage_report();");
You can add this line where you exit WebDriver or Test Case
Not aware of a tool for Selenium, but JsTestDriver has a design very similar to Selenium RC (can launch tests from the command line and they are run on a server that drives browsers headlessly) and provides code coverage information.
IntelliJ integrates with JsTestDriver and provides a visual display of coverage information.
Take a look at https://github.com/yui/yuitest/wiki/Code-Coverage
I've integrated this tool in my Selenium tests a time ago. You need a bit of work to gather coverage info before page changes (in any case js trigger a page reload, link etc...)
Once you set up everything, it will fully coverage any js executed while Selenium load and test your website pages.
PS : Even if it was specially adapted for YUI test, you can use it with selenium.
I don't know what you are trying to achieve, but:
Selenium is testing the final output, as seen on the page itself.
So it really does not matter if its PHP, HTML, JSP, ASP or .NET - the Selenium is designed to mimick the end user and click the final application - the final HTML code generated by whatever is under the hood.
Selenium is also not that good for code coverage tests - one piece code can be on many pages - so better approach with selenium is to do the "user" coverage - try to cover all the possible actions which living human could possibly do with your page
There is no particular tool that can integrate with Selenium to do JS coverage. However there are lots of tools which test JS on every page which can tell if the JS that executing on your web page had any errors. This may not ideal solution but on each page you will have the measure of uptil which point JS executed properly on your webpage under test. There are two solutions for that:
1.) JSErrorCollector API: It will integrate directly with Selenium and let you know if there were any error on the page. Can be found at: http://mguillem.wordpress.com/2011/10/11/webdriver-capture-js-errors-while-running-tests/
2.) Full fledged JS coverage tools: There is an excellent list of tools here which will essentially help you in covering JS on on your web pages. Can be found at: JavaScript unit test tools for TDD

Unable to use few Selenium commands while writing scripts

There are some Selenium commands that I am unable to use in a script that I'm writing and I do not have any idea as to whether I am missing an import of required library files or packages.
For example - selenium.browserbot, selenium.waitForElementPresent.
I am using Selenium IDE to record the script and working in Eclispe Junit platform.
Use isElementPresent instead of waitForElementPresent.