Note: For overall context for this blog please read integration testing with soapUI to understand why extending soapUI to work with Selenium is ever necessary.
A selenium RC groovy script which is one form of customizable edition of the recorded selenium IDE can be invoked in the soapUI. It is useful to perform various tasks in soapUI like as follows:
- As a test step
- To control testcase flow based on output of previous steps
- To trigger the execution of test steps or test cases
- As a data generator
- As extended script libraries for common functionalities.
- To write the results of test steps or test cases to an external source
Selenium RC and IDE
Selenium Remote Control (RC) is a test tool that allows user to write automated web application UI tests in multiple available programming languages against any HTTP website using any mainstream JavaScript-enabled browser.Selenium RC has two processes:
- A server which automatically launches and kills browsers, and acts as a HTTP proxy for web requests from them.
- Client libraries for multiple computer language.
The RC server also bundles Selenium Core, and automatically loads it into the browser.
Firefox extension calling Selenium IDE (Screenshot001) is used to record the functionality of the web site. It is easy to use and powerful tool for controlling, automating or testing web sites. It has record and playback feature that can be used to automate any thing in the web sites.
(Screenshot001)
Selenium IDE has feature to save and export automated task in Groovy script (Screenshot002) which in turn can be used in soapUI.
(Screenshot002)
For Selenium IDE users, Selenium RC is ideal solution to write tests in a more communicative programming language. So, to be more expressive, compatibility and for extra assertions recorded scripts are exported in Groovy Scripts.
Groovy Scripts
Groovy:
- is an agile and dynamic language for the Java Virtual Machine
- builds upon the strengths of Java but has additional power features inspired by other languages.
- supports Domain Specific Languages and other compact syntax so that code is easy to read and maintain
- makes writing shell and build scripts easy with its powerful processing primitives, OO abilities and an Ant DSL
- simplifies testing by supporting unit testing and mocking out-of-the-box
- seamlessly integrates with all existing Java objects and libraries
- compiles straight to Java bytecode so you can use it anywhere you can use Java
Groovy scripts can be widely used in a soapUI for different functionalities.
SoapUI
soapUI is open source desktop application for inspecting, invoking, developing, simulating/mocking and functional/load/compliance testing of web services over HTTP. In a given framework, soapUI is used for testing web service.
Following are the functionalities of the groovy scripts in soapUI:
- As part of a Testcase with the Groovy Script Test Step, allow tests to perform virtually any desired functionality
- Before and after running a Testcase or Test Suite for initializing and cleaning up before or after running the tests.
- When starting/stopping a MockService for initializing or cleaning-up MockService state
- When opening/closing a Project, for initializing or cleaning-up Project related settings
- As a dynamic DataSource or DataSink with the corresponding DataSource/DataSink test steps
- For creating arbitrary assertions with the Script Assertion
- To extend soapUI itself, for adding arbitrary functionality to the soapUI core. User can create his/her own script libraries for common functionality which can be used shared by the Testing team.
Benefits of Groovy Scripts in Test Automation Framework
In Test Automation Framework, we have used groovy scripts mainly:
- As a test steps. (refer below screen)
(Screenshot003)
- As a dynamic DataSink. (refer below screen)
(Screenshot004)
- Before and after running a Testcase or Test Suite for initializing and cleaning up before or after running the tests. (refer below screen)
(Screenshot005)
- To involved Selenium RC scripts for extend soapUI, we have created own script libraries for common functionality which can be used shared by the Testing team. We have further customized it by creating a jar for the same i.e. scripts.jar and kept it in the soapUI setup at “C:\Program Files\eviware\soapUI-Pro-3.0.1\bin\ext”. (refer below screen)
(Screenshot006)
When tester will run the soapUI project either from Test Automation Framework or from soapUI Pro, it will take the extended script libraries from scripts.jar file.
Conclusion
Using test automation framework, a tester can execute the soapUI test suites or test cases automatically segregated by categories and browsers. Framework is customizable by updating the extended soapUI libraries for common functionalities. It will actually help the user to create a groovy script for commonly used functions and then bind those scripts in a jar file so that user can use in soapUI. While executing soapUI, it will automatically use customized selenium groovy scripts with assumption that selenium services are running.