SiKing

January 6, 2012

dynamically create elements in a SoapUI request

Filed under: automation — siking @ 11:44 am
Tags:

I got this problem – took me like 8 hours to solve, so that qualifies it as a problem. In SoapUI I have a call that responds with something like <night ratePlanID="A" stayDate="B" availCodeID="C" regularPrice="D" totalPrice="E" />. There are multiple of these, the number can change depending on the inputs to this call. I need to create the same number of elements for my next call, and change the attributes around a bit to make it look something like: <hot:night ratePlanID="A" resDate="B" quotedPrice="E" />. Luckily Groovy abstracts away the need for counting things, and I naively thought that manipulating the XML would be a breeze too…

version 1.0

The first useful hints that I got were from the SoapUI tips & tricks. After that getting at the individual attributes is done with attributes.getNamedItem(). After that I just brute-forced my way through it.

// create groovyUtils and XmlHolder for response of my "find room" call
def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
def holder = grUtils.getXmlHolder("find room#Response")

// place for my final result
def entireXmlFragment = new StringBuilder()

// get only the nodes that I am interested in, and iterate over all of them
holder.getDomNodes("//*:hotel/*:roomType/*:guestCount[1]/*:night").each {

	// create a new node one piece of string at a time
	def oneXmlFragment = new StringBuilder()
	oneXmlFragment << "<hot:night ratePlanID='"
	oneXmlFragment << it.attributes.getNamedItem("ratePlanID").getNodeValue()
	oneXmlFragment << "' resDate='"
	oneXmlFragment << it.attributes.getNamedItem("stayDate").getNodeValue()
	oneXmlFragment << "' quotedPrice='"
	oneXmlFragment << it.attributes.getNamedItem("totalPrice").getNodeValue()
	oneXmlFragment << "' />"
	oneXmlFragment << System.getProperty("line.separator")

	// add the new node to my final result
	entireXmlFragment << oneXmlFragment
}

// push the final result into a property
testRunner.testCase.setPropertyValue("entireXmlFragment", entireXmlFragment.toString())

Now in my next call I just insert ${#TestCase#entireXmlFragment} where I want this XML fragment to be placed. Works, but seems kinda neanderthal.

version 2.0

There has to be a way to manipulate my XmlFragments as XML objects, and there has to be a way to push them directly into the next call? The grUtils.getXmlHolder() led me to holder.getDomNodes(), which gives you back a org.w3c.dom.Node.

// create groovyUtils and XmlHolder for response of my "find room" call
def grUtils = new com.eviware.soapui.support.GroovyUtils(context)
def responseHolder = grUtils.getXmlHolder("find room#Response")

// create XmlHolder for request of my "bookHotelRes" call
def requestHolder = grUtils.getXmlHolder("bookHotelRes#Request")
// find the Node that I am interested in
def requestNode = requestHolder.getDomNode("//*:bookHotelResInput/*:room")
// the Document object is used to create new nodes
def requestDoc = requestNode.getOwnerDocument()

// get only the nodes that I am interested in, and iterate over all of them
responseHolder.getDomNodes("//*:hotel/*:roomType/*:guestCount[1]/*:night").each {

	// create a new Element in the Document
	def oneElement = requestDoc.createElementNS(requestNode.getNamespaceURI(), "night")
	// define all the attributes
	oneElement.setAttribute("ratePlanID", it.attributes.getNamedItem("ratePlanID").getNodeValue())
	oneElement.setAttribute("resDate", it.attributes.getNamedItem("stayDate").getNodeValue())
	oneElement.setAttribute("quotedPrice", it.attributes.getNamedItem("totalPrice").getNodeValue())
	// insert the Element
	requestNode.insertBefore(oneElement, requestNode.getFirstChild())
}

// write the Document out to the request
requestHolder.updateProperty(true)

The above will write out the next Element as the first child. Also, and perhaps more importantly, the above will write it out into your request – if you run your test twice in a row, you will end up with both results (old and new) in your request. This is undesirable, but easy to take care of.

// cleanup from a "previous" run
requestHolder.getDomNodes("//*:bookHotelResInput/*:room/*:night").each {
	requestNode.removeChild(it)
}

HTH :)

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.

August 18, 2011

the next phone?

Filed under: noki — siking @ 5:21 pm
Tags:

My old phone is getting … old. So I started looking around at what else to get. I really like the sound of the new N9! However, in a twisty move by Nokia I suspect a lot of people are going to get rich off of this phone. I’m still looking at other possibilities…

August 8, 2011

Groovy Selenium WebDriver and SoapUI, part 2

Filed under: automation — siking @ 2:55 pm
Tags:

I initially assumed that I would have this post up within a week of the previous, but life got in the way as it so often does. :neutral:

Now that I got everything set up, it’s time to move on. In this second part, I am going to concentrate on getting Selenium 2 WebDriver going with Groovy. Selenium 2 out of the box supports .NET and Java, so why Groovy? There are several reasons: 1. SoapUI (to be discussed later) supports Groovy natively, 2. I like scripted languages for test automation better than compiled languages, and 3. why not?

I had been working with Selenium RC and .NET for some time, and had put together the basis of an automation framework. So my first step was to rewrite everything in Java, and just call it Groovy. All this was actually surprisingly easy to accomplish, especially with my very limited knowledge of both Java and Groovy. I want to stress that what I have here (the previous two links) is just the beginnings of a test framework. It meets my initial requirements: that it run in Groovy, and that it use 100% WebDriver. I am certain that it can (and will) be further optimized, but I would hope that anyone starting with this will get a good idea of where this is heading.

still to do:

  • Get everything running from the command line.
  • Use it in a real-world project. :mrgreen:
  • Make everything more Groovy.

couple of surprises along the way:

  • Man, love the lack of Selenium server. No more Java memory crashes. :evil: Yay!
  • In JUnit4 the signature of asserts changed from (NUnit’s) Assert.AreEqual(expected, actual, message) to Assert.assertEquals(message, expected, actual). The message goes at the beginning?
  • In webDriver, getting the value of a textbox changed from selenium.GetValue("name=q") to txtSearch.getAttribute("value"). Nice!

July 23, 2011

Groovy Selenium WebDriver and SoapUI, part 1

Filed under: automation,linux,windows — siking @ 4:13 pm
Tags:

I recently started a new job and a new project that called for me to make use of some things I have used separately over the past few years: combine SoapUI and Selenium into one framework, and make them work together – actually pass information from one to the other and back. While I am at it, I thought I would dust off some skillz from a box that I have not been in for some time: Eclipse and Java (I know the title says Groovy, I’ll get to that).

setting it all up on Windows

Of course at work they must run Windows. :sad:

  1. Download and install (unpack?) Eclipse Classic 3.7, and run the Check for Updates. Mental note: gotta look at Eclipse for Testers, someday.
  2. You need to give it Java: set JAVA_HOME and add %JAVA_HOME%\bin to the PATH. The first one that I tried – there were like half-dozen different versions on my machine :roll: – Eclipse complained that it is missing something called jvm.dll. Better get the real thing.
  3. If you create a shortcut to launch Eclipse from your desktop, I found that it is a good idea to set the “Start in:” field to the same thing as what your workspace is.
    Eclipse shortcut properties
  4. Install SoapUI. This plugin needs some post-install work/commentary. If you also run the SoapUI IDE, especially a different version than what you just downloaded, the two will share one %userProfile%\soapui-settings.xml and there could be collisions; I would really like to find a way to relocate this file for the Eclipse plugin. Also, if you did not start Eclipse from your workspace – point 3 above – then you are going to 1) possibly overwrite your %userProfile%\default-soapui-workspace.xml, and 2) possibly pollute your Eclipse installation with three *.log files that SoapUI always creates on startup. Lastly: what used to be %SOAPUI_HOME%\bin\ext (external jars that should be added to soapUI classpath, for example JDBC drivers) is now %userProfile%\ext; another thing I would really like to relocate for the Eclipse plugin.
  5. Install Groovy. The instructions say to use http://dist.codehaus.org/groovy/distributions/greclipse/snapshot/e3.7/, but if you read between the lines, you will notice this is the development build and as such it changes often, like almost daily. I used http://dist.springsource.org/release/GRECLIPSE/e3.7/ and it seems to have worked right out of the box.
  6. Install SVN. I am not sure why Eclipse still comes pre-installed with CVS; does anyone still use this? When you’re done, make sure it worked. Normally there are problems.

setting it all up on Linux

Of course at home I run Linux. Surprisingly the Linux setup was a little more work. :???:

  1. I run Linux Mint 9 (Ubuntu Lucid Lynx – LTS); the repos have only Eclipse 3.5, which is way too outdated by now. Download and install (unpack?) Eclipse Classic 3.7, and run the Check for Updates.
  2. LM9 comes set up with OpenJDK. Eclipse will run with this, however, when doing this last time, I ran into some problems, like various things kept crashing the JVM. Somewhere on the Eclipse site (unfortunately, I cannot find the link now) they suggested that you use genuine Sun Java. This is accomplished with sudo apt-get install sun-java-jdk, and then you need to modify your eclipse.ini to point to /usr/lib/jvm/java-6-sun/bin/java.
  3. Install SoapUI. I’m still having problems with this one.
  4. Install Groovy. Use the same location as mentioned above, which makes it work right out of the box.
  5. Install SVN. Fix the problems.

July 20, 2011

cross browser testing

Filed under: tech — siking @ 4:21 pm
Tags:

I was asked today to find something that will “test our website in multiple browsers”. At this point there is no concern for functional testing (although I suspect this will come in time), right now we just want to check that the page renders correctly. Here are a couple of solutions that I found and thought were actually usable:

  1. browsershots.org – these guys have, what looks like, every OS/browser combination known to mankind. You pick the browsers you want, give them a URL, and they will send you back a bunch of screenshots. If you’re a non-paying customer, you might have to wait up to an hour for the results. Also, when I was testing this, I often got back a screenshot of a browser that looked like it was still downloading stuff.
  2. netrenderer – same idea as above, but IE-only and one at a time.
  3. IETester – local download. It’s an app that probably has all the IE (only) rendering engines embedded in it, and you can open different tabs with different engine + website. Apparently it goes up to IE10. When I tried to view our website in IE9 in this app, it failed to render. However, when I tried to view our website in actual IE9, it rendered perfectly fine.
  4. Utilu IE Collection – this will install all actual IEs on your machine and allow you to run them side by side. Definitely the best solution out of these, as it allows you to do whatever you need with a browser … including full automation of functional tests. Unfortunately, even though the installer listed versions 1.5 up to 8 (don’t know why nothing beyond), it was not able to install some of the those.
  5. Utilu Mozilla Firefox Collection – same thing as above, but for Firefox. However, this one has some added benefits: it will install all versions up to and including nightly build, and it has one launcher that you pass a URL to and it will open all the browsers to that URL.

Now to get something for Safari. Anyone?

July 18, 2011

Windows 7, downwards compatible NOT!

Filed under: automation,windows — siking @ 3:13 pm
Tags:

I’m currently working on something new – another post coming later – and as usual I try to write scripts for everything which can subsequently serve as a roadmap for full automation. This time I’m doing it on a Win7 machine, which is a 64-bit operating system that is supposedly fully compatible with 32-bit applications. In the file system there are two locations where new programs get installed: c:\Program Files and c:\Program Files (x86). I don’t know if the location of the install actually matters to the operating system – actually makes the system consider the application as a 64- or 32-bit app; I suspect it does not. AFAIK it only serves to further confuse and break stuff. :roll:

May 1, 2011

Rt89A in Arizona

Filed under: rides — siking @ 8:00 pm

I had been neglecting my blog for a while – it is not for lack of riding, I blame entropy. :razz:

This past weekend some friends and I hit up route 89A in Arizona.


View Larger Map

I hooked up with my friends in Phoenix, and Saturday morning we took off towards Wickenburg. If you get a chance – we didn’t – I highly recommend stopping by the Hog Trough Smokehouse BBQ for some great food. Just outside of Wickenburg you pick up highway 89 towards Congress. There is nothing much of interest en route until you get into the mountains climbing up to Prescott. This is a beautiful ride: twisty, very well-built, and wide roads, which allow you to often check the eye-catching scenery.

Prescott is a pretty town worth stopping at and stretching your legs in the picturesque downtown. But don’t waste too much time there.

After our break, we continued climbing the twisties. Jerome is a place worth stopping and spending some serious time in. The town reminded me of some seaside European village, with small brick buildings propped up on the steep hillside, and people and cars navigating the precariously narrow streets – minus the sea of course. Make sure you have reservations well in advance! We had a Haunted Burger, and walked through the town long enough to find out that there are no rooms available for that night.

Onward through the twisties, this time downhill, towards Sedona. That’s where we met the pirate!

pirate

There be pirates in them thar' hills, arrrgggg!

Sedonais another place that I would have like to spend a little more time than just one night. It has all the typical red-rock desert mountains, right in the middle of the town, licensed ATV running down the streets, plenty of tourists, and the whole place shuts down by 10pm to get some decent sleep to start another great day the next morning.

breakfast

A little piece of home?

March 13, 2011

Stop at Nothing

Filed under: rides — siking @ 8:00 pm

Nothing, AZ

I got a purdy new bike, in Arizona, and on the way back we stopped at Nothing. :D It’s in the middle of the desert, and there is actually nothing for miles around.

With my luck, the next day the bike died. :( It was only the primary wire from the battery that rubbed through and shorted against the body, so no biggie, but still a bummer.

The guy who sold me the bike really loved it; he almost cried when I was taking her away. He forwarded me some sites that I do not want to lose:

March 1, 2011

Upgrading to Selenium 2

Filed under: automation — siking @ 9:48 am

Current release (as of 2/28/2011) of Selenium is 2.0b2; there is no proposed final release date, only a list of tasks that must be completed before a final release is considered by the project. Historically, the Selenium project has taken a very long time (years) before any major release.

Impact to existing test suite

One of the goals of Selenium 2 is to maintain downwards compatibility. This is accomplished by providing the same library (ThoughtWorks.Selenium.Core.dll) that was initially shipped with Selenium 1. Java, C#, and Python libraries are all available; other languages appear to have been abandoned.

After replacing this library, our current solution still compiles with no problems.

Replacing the Selenium Server with version 2 and running the test suite, some tests fail. Most problems come from evaluating XPath statements for locating various elements. With minimal effort, I was able to get all the Smoke tests to pass.

New functionality

Selenium 2 comes with two new major features: new browser support and “WebDriver”.

Browser support

Selenium 2 has support for both Android and iPhone. These platforms are currently not supported by any of our software, but are interesting anyway.

It should be noted that some of the browsers that were natively supported by Selenium 1, such as Safari, no longer have native support in Selenium 2. This also has no current impact to us.

Selenium 2 also supports “HtmlUnit”, which is a mode that does not require any browser to be running or even installed on the test machine. The only thing that is required for this is the classic Java Selenium Server. However, in order to take advantage of this mode some parts of the existing framework will have to be rewritten.

WebDriver

This is a new technology that Selenium 2 was built on, which gives the tests direct access to the browser without the need to run an intermediary proxy server – the classic Selenium Server. Tests written using the WebDriver are much friendlier and the resulting code is much more expressive.


        IWebDriver driver = new InternetExplorerDriver();
driver.Navigate().GoToUrl(“http://test.server.local/Processor”);

IWebElement entityBox = driver.FindElement(By.Id(“cgUserName_txtEntityKey”));
IWebElement userBox = driver.FindElement(By.Id(“cgUserName_txtUserName”));
IWebElement submitBtn = driver.FindElement(By.XPath(“//input[@value='Submit']“));
entityBox.SendKeys(“testEntity”);
userBox.SendKeys(“autoghost”);
Console.WriteLine(entityBox.Value);
submitBtn.Click();

IWebElement passwordBox = driver.FindElement(By.Id(“cgPassword_txtPassword”));
IWebElement loginBtn = driver.FindElement(By.XPath(“//input[@value='Login']“));
passwordBox.SendKeys(“qwerty123″);
loginBtn.Click();

driver.Quit();

Additional code examples can be found on the Selenium website. This mode requires browser-specific libraries (currently available for Firefox, Internet Explorer, Chrome, and the above mentioned HtmlUnit). Other browsers can be run in emulation mode. It is possible in Selenium 2, that all these modes, including Selenium 1 tests, can all live side-by-side.

The WebDriver technology is much less bound to the NUnit framework, and in fact any framework including a completely custom in-house can easily be supported.

Existing tests would have to be rewritten in order to take full advantage of the WebDriver functionality.

January 26, 2011

a lawn mower

Filed under: meatspace — siking @ 8:50 pm
Tags: ,

I got me a new lawn mower. I went all out, and got one of the fancy self-powered, fully automated models. Have a look:




Unfortunately, the “lawn mower” is constantly trying to get onto the back deck and into the house, and not taking care of the weeds in the back yard.

So I went down to the local hardware store to price out a chain around his neck (a dog collar is too short), and a 50ft. of steel cable (yes, the coated kind), and some connectors to hook everything up. Bottom line: that setup costs more than the goat, and a low-end BBQ is cheaper.

So I still have some decisions to be made… :razz:

January 15, 2011

Death Valley trip

Filed under: rides — siking @ 8:00 pm

View Larger Map

What an absolutely fantastic weekend for riding! I did not have my GPS, but Google thinks the whole route was 370 miles.

We started with 9 riders and 8 bikes, and headed to Shoshone for breakfast – good food, lousy gas prices. We were joined by 3 more riders and two more bikes there. After breakfast half of our initial group headed back via Pahrump … stressing out about long rides, wind, light, dark, heat, cold, noise, coffee, sugar, and soon to be missing license plates.

First stop for the adventurers was Badwater.

parking

everyone finally relaxes

me

some dork at Badwater with a very cool looking scarf

sea level

that sign stuck up on the mountain says: "Sea Level"

Next was Dante’s View. The ice patches on the ride up freaked out those of us who were on hiatus for the past four months, but we all made it in one piece and the view from the top was awesome.

looking down

this is looking down towards Badwater - essentially the spot where the above picture was taken

Next was Furnace Creek. Those who are not storing as much reserves :razz: had to do lunch here. Last stop was Beatty for candy, and back home by 8 or so.

Additional report and pictures.

Next Page »

Theme: Rubric. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.