SiKing

August 22, 2011

Groovy Selenium WebDriver and SoapUI, part 3

Filed under: automation — SiKing @ 4:25 pm
Tags:

So I got my environment set up and I have been busy coding up new Selenium-WebDriver test suite for a few weeks now.

I first wanted to just state that as great of a tool as SoapUI is, their community support just plain sucks! Any time I navigate to their discussion fora, I can actually hear the crickets in the distance. If you need some help, may I recommend the Service Testing using soapUI (needs login) group at LinkedIn.

The next bit of complaint that I have with SoapUI, is how poorly it integrates with Eclipse!

Now back to your regular programming …

the quick and dirty

So the most obvious, and perhaps the easiest way, to get Selenium and SoapUI to cooperate is:

  1. Install SoapUI.
  2. Download Selenium (you need the selenium-server-standalone-2.*.jar) and drop it into your SoapUI installation (into %SOAPUI_HOME%\bin\ext).
  3. Fire up SoapUI; start a new Project; create a new test case; add a new Groovy step; copy-paste the sample code into the step. I made a few modification: drop the package line, drop the class Selenium2Example and void main lines along with the closing brackets, and change the System.out.println to log.info. My final (full) test code is below.
  4. Click Play. You should see Firefox starting up, navigating to Google, and afterwards you should see the SoapUI log entries.
import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
import org.openqa.selenium.firefox.FirefoxDriver
import org.openqa.selenium.support.ui.ExpectedCondition
import org.openqa.selenium.support.ui.WebDriverWait

        // Create a new instance of the Firefox driver
        // Notice that the remainder of the code relies on the interface, 
        // not the implementation.
        WebDriver driver = new FirefoxDriver()

        // And now use this to visit Google
        driver.get("http://www.google.com")

        // Find the text input element by its name
        WebElement element = driver.findElement(By.name("q"))

        // Enter something to search for
        element.sendKeys("Cheese!")

        // Now submit the form. WebDriver will find the form for us from the element
        element.submit()

        // Check the title of the page
        log.info("Page title is: " + driver.getTitle())
        
        // Google's search is rendered dynamically with JavaScript.
        // Wait for the page to load, timeout after 10 seconds
        (new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
            public Boolean apply(WebDriver d) {
                return d.getTitle().toLowerCase().startsWith("cheese!")
            }
        });

        // Should see: "cheese! - Google Search"
        log.info("Page title is: " + driver.getTitle())
        
        //Close the browser
        driver.quit()

Success, the two can talk to each other. :!: You will probably notice some errors, due to Google updating their site and the above code no longer works there; however, the proof of concept is there. For a better example, see my sample code.

the difficult way

I did not get as much chance to play with the SoapUI as I would have liked, but I wanted to get this published. The above will work for simple Selenium steps. However, for more complex steps you probably want a little more.

Unfortunately, I have not had a chance to explore this yet, but the general idea is:

  • SoapUI is a java project, it must be in some .jars somewhere, hopefully in just one.
  • Import that into your Groovy (Java) project.
  • Then you should be able to call appropriate functions from your code.

All this sounds quite easy, but I am certain that it will need more than what I have here. If anyone manages to get this to work, I would be really curious to hear from you.

About these ads

6 Comments »

  1. [...] To Get Selenium and SOAP Ui to cooperate [...]

    Pingback by Selenium Web Driver – SOAP UI Integration for Web Service Testing. | Selenium Script — April 9, 2013 @ 8:53 am | Reply

  2. Is there any way to customize this code to IE or Chrome?

    Comment by Chandrasekaran — September 13, 2012 @ 4:43 am | Reply

  3. No words to say.. Awesome.. i just followed the step..Sweet :)

    Comment by Chandrasekaran — September 12, 2012 @ 1:35 pm | Reply

  4. Nice try.. will try to integrate the 2 testing Giants together having different expertize (UI and Services) to make a robust testing framework.. :)

    OGK…

    Comment by Gaurav — January 10, 2012 @ 11:45 pm | Reply

  5. Thanks for the post, its a good starter for soap UI and Selenium integration

    Regards,
    Rakesh.P

    Comment by rakesh — October 18, 2011 @ 11:03 pm | Reply


RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: