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.

Advertisements

24 Comments »

  1. You could see this video https://youtu.be/9eqSuma6pfQ
    About extending SoapUi with Selenium WebDriver.

    Comment by jcinca — October 5, 2015 @ 1:06 pm | Reply

  2. im getting the following exception “org.openqa.selenium.WebDriverException: Cannot find firefox binary in PATH. Make sure firefox is installed. OS appears to be: VISTA Build info: version: ‘2.45.0’, revision: ’32a636c’, time: ‘2015-03-05 22:01:35’ System info: host: ‘ingbtcpic5nb736’, ip: ‘161.85.88.152’, os.name: ‘Windows 7’, os.arch: ‘amd64’, os.version: ‘6.1’, java.version: ‘1.7.0_40’ Driver info: driver.version: FirefoxDriver error at line: 11” will someone please help me

    Comment by Pramod Holla — June 5, 2015 @ 5:50 am | Reply

  3. Hello!

    Thanks for this great article, SiKing.

    But I have following errors after step-by-step adding needed(as I think) jars to SoapUI/../ext:

    java.lang.NoSuchFieldError: INSTANCE
    for the row of driver init

    I have no idea how to fix it… smth with jars versions?

    I downloaded:
    commons-exec-1.3
    commons-logging-1.2
    gson-2.3.1
    httpclient-4.4
    httpcore-4.4
    log4j-1.2.17
    log4j-1.2.17

    So, that’s the point/problem

    Sincerely,
    Dmitry.

    Comment by Dmitry — March 13, 2015 @ 9:25 am | Reply

    • sorry, instead of last log4j-1.2.17 is selenium-java-2.45.0 used

      Comment by Dmitry — March 13, 2015 @ 9:26 am | Reply

      • So first thing you need selenium-server-standalone; selenium-java is not enough. Second, I have seen this same error. Something in selenium conflicts with some of the libraries that are packaged with SoapUI, I just have not had the time to investigate what it is. selenium version 2.41 is known to work; try upgrading from that, one at a time, until it starts to fail. Of course this is going to be a problem with the version of FF that you want to run.

        Comment by SiKing — March 13, 2015 @ 7:18 pm | Reply

        • Hey guys,

          I had the same problem, but now it works like a charm. Thanks for an example.
          Figures out that SoapUI uses older version of HttpClient and it conflicts with Selenium’s. No need to downgrade FF or Selenium – simply upgrade HttpClient’s jars (and I’m doing this in lib folder as ext for some reason did not work with all this method).

          Comment by Lina — September 17, 2015 @ 3:24 am | Reply

  4. Hi. It does not work anyway… Fu….g error: java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.
    I’ve tried few combinations of selenium…-standalone.jar with few versions of soapUI with no effects – still the same error… – wtf. Help !

    Comment by ed — September 28, 2014 @ 11:39 am | Reply

    • That package is part of selenium-server-standalone. I used version 2.41 with no problems.

      Comment by SiKing — September 29, 2014 @ 7:43 am | Reply

  5. Hi Siking

    I tried the above steps and I am also getting same error as Puru mentioned. java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory.
    I am using SOAP UI 5.1.1 and selenium-server-standalone-2.42.2.jr

    Thanks
    Ashok

    Comment by nashok2000 — September 11, 2014 @ 1:06 pm | Reply

    • Please confirm that you have the server-standlone.jar. If yes, try to downgrade to an earlier version of Selenium.

      Comment by SiKing — September 12, 2014 @ 7:42 am | Reply

  6. Hi,
    I followed the steps defined and it worked.

    But i would like to know the difficult way also… i.e Calling multiple java classes or java code in single selenium main script or driver script.

    Say eg: I have Test1.java and Test2.java. Both these java files are getting called in MainTest.java.
    But all are under same package.

    Now how do i import the Java package. Where I should keep the package in which groovy script will refer.

    Any help would be appreciated.

    Thanks,
    Dheepha V

    Comment by Dheepha — May 5, 2014 @ 12:42 am | Reply

    • Additional information is available here: http://www.soapui.org/Developers-Corner/integrating-with-soapui.html
      Let me know how you get on with it.

      Comment by SiKing — May 5, 2014 @ 7:23 am | Reply

      • Hi Siking
        I tried the above steps , but while running the test case , i am getting java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory error at line: 11, (Webdriver instantiating line). Kindly hellp me out.

        Thank you’
        Puru

        Comment by Puru — September 7, 2014 @ 11:29 pm | Reply

        • Without seeing your code, it would be pure guesswork for me.

          Comment by SiKing — September 8, 2014 @ 7:07 am | Reply

          • Hi Siking,
            I have used the code which was given above. Any ways I will tell the steps I did.

            1. Installed SoapUI 5.0, under Soapui/bin/ext I pasted the selenium-java-2.42.2.
            2.Created a REST projet with random URI, and created Groovy script under test case .
            3. Pasted the below code
            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

            WebDriver driver = new FirefoxDriver()

            WebElement element = driver.findElement(By.name(“q “))
            element.sendKeys(“Cheese!”)

            element.submit()

            log.info(“Pagee is: ” + driver.getTitle())

            (new WebDriverWait(driver, 10)).until(new ExpectedCondition() {
            public Boolean apply(WebDriver d) {
            return d.getTitle().toLowerCase().startsWith(“cheese!”)
            }
            });

            log.info(“Pagee is: ” + driver.getTitle())

            //Close the browser
            driver.quit()

            4. Clickin on Run leads to teh below error.
            java.lang.NoClassDefFoundError: Could not initialize class org.apache.http.impl.conn.ManagedHttpClientConnectionFactory error at line:9

            Kindly tell me if I have donw any mistake.

            Thank you
            Puru

            Comment by Puru — September 9, 2014 @ 4:01 am

          • My instructions say that you need the selenium-server-standalone-2.*.jar, which includes all dependencies.

            Comment by SiKing — September 12, 2014 @ 7:41 am

  7. Thanks for the post, this has helped me completely.. one concern.. i want to get url from the test case custom properties. how can i getProperty in the selenium script?

    Comment by dennis — June 29, 2013 @ 5:11 am | Reply

    • There are two possibilities:
      context.expand( '${#TestCase#property_name}' )
      testRunner.testCase.getPropertyValue("property_name")

      Comment by SiKing — July 1, 2013 @ 7:31 am | Reply

  8. […] 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

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

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

  10. No words to say.. Awesome.. i just followed the step..Sweet 🙂

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

  11. 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

  12. 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 )

Google+ photo

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

Connecting to %s

Create a free website or blog at WordPress.com.

%d bloggers like this: