Original URL: https://www.guru99.com/using-soapui-selenium.html
Using SoapUI with Selenium
SoapUI is the most popular open source functionalTesting tool for Api Testing. It provides complete Test coverage and supports all standard protocols and technologies.
What is SOAP?
SOAP is a simple XML-based protocol. It allows applications to exchange information over HTTP. It usesWeb services description language(WSDL) language for communication. Other applications can also interact with web services using WSDL interface.
What is SOAPUI?
SOAPUI is an open source cross-platform web service testing tool. The SOAPUI-Pro has extra functionality for companies dealing with critical web services. Web services play a significant role in Internet applications.
Selenium
- Selenium: - It is a test tool to automate browsers across many platforms.
- Selenium Webdriver: - It makes direct calls to the browsers. It uses browser's native support for automation.
Selenium with SoapUI
The simplest and easiest way to integrate Selenium with Soapui is to use Groovy. SoapUI extensively supports Groovy.
Groovy is an object-oriented scripting language. Groovy includes all the Java libraries. So all Java related keywords and functions can be used in the groovy script directly. It integrates with JVM (Java Virtual Machine).
Pre-requisites for using Selenium with SoapUI
- Download Groovy SDK:
- Install Java SDK
- Install Selenium
- Install SoapUI Pro
Call the SoapUI Testcase runner in Selenium.
The below code will be used to call SoapUI testcase. It will set the properties of city and corresponding zip codes. When the code is executed, it will get the value of cities and zip codes. Also, display the failure count that does not match with the corresponding city and zip code. This code will run in Selenium.
Note: "usePropertyFileFlag=true" here instead of using a static property file to store zip code and city. The information of zip code and city will pass at runtime dynamically by setProjectProperties() method.
Instructions to run the code.
- Start up SoapUI
- Start a new test case
- Add a new groovy step.
- Copy paste the sample code into the step.
- Click on Play.
- You can see Firefox starting up and navigating to Google. After that, you can see SoapUI log entries.
- Code runs using Junit
@when("<I use the weather service to get the weather information") public void i_use_the_weather_service_to_get_the_information() { Set<Entry<String, string>> set = zipAndCities.entrySet(); while (iterator,hasNext)) { Entry<String, String> entry = iterator.next(); String zipCode = entry.getkey(); String city = entry.getValue(); String[] prop = {"usePropertyFileFlag=true","zipCode=" +zipCode, "city=" +city}; try{ SoapUITestCaseRunner soapUITestCaseRunner = new SoapUITestCaseRunner(); soapUITestCaseRunner.setProjectFile("src/test/resources/WeatherSoapTest-soapui-project.xml"); soapUITestCaseRunner.setProjectProperties(prop); soapUITestCaseRunner.setTestSuite("TestSuite1"); soapUITestCaseRunner.setTestCase("TestCase1"); soapUITestCaseRunner.run(); } catch (Exception e) { System.err.println("checking" + zipCode + " failed!"); failureCount++; zipCodes.append(zipCode + " [" + city +"] "); e.printStackTrace(); }finally{ totalCount++; } } } }
The console view enables us to have a glance at all the test cases executed. You will find a list of zip codes, cities fetched and passed into the SoapUI Test Case 1.
View SoapUI Log file
Log files record every action occurred in the operating system or software application. To view, SoapUI log files. Go to the main directory and you will see a file name "soapui.log."
In SoapUI, the log file is located in the bin folder in the installation directory. E.g C:Program filesSmartBearsoapUI-Pro-4.0.1in
When you open this log file by clicking on it, it will look similar to the screenshot below.
Summary
- Soap is simple XML-based protocol. It allows the exchange of information over HTTP.
- SoapUI is an open source cross-platform web service testing tool.
- Selenium is a suite of test tools to automate browsers across many platforms.
- Selenium Webdriver makes direct calls to the browsers. It uses browsers native support for automation.
- Selenium integrates with SoapUI using Groovy.