Saturday, June 12, 2010

String match using Regular expression in both Java and Ruby

sometimes, I will looking for some dynamic data/elements from HTMLsource to make my automation scripts more robust and reliable, so using regular expression to do string match is very useful for me to get them:

Example in Java( for selenium usage):

import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class RegexTestHarness {

public static void main(String[] args){


Pattern pattern =
Pattern.compile("information-abc-([0-9]+)");

Matcher matcher =
pattern.matcher("information-abc-9887234-information-abc-223333889-information-abc-12233");

while (matcher.find()) {
for (int i=1; i<=matcher.groupCount(); i++) {
String groupStr = matcher.group(i);
System.out.println(groupStr);
}
}

}
}


Example in Ruby( for Watir usage):

def regex_match(search_pattern)
source_string = "information-abc-9887234-information-abc-223333889-information-abc-12233";

source_string.scan(/#{search_pattern}/) { |match| puts match;}

end

regex_match("information-abc-([0-9]+)");


Love Ruby, it is simple :)

Friday, June 11, 2010

World CUP 2010 , Right here, Right now!

Two talented team i will support:

- Argentina
- Mexico

Let's enjoy the Game from Today!:)

Wednesday, June 09, 2010

SoapUI MockOperation Dispatching in Groovy script

SoapUI provides several ways to dispatch mock service response, you can find the detail information from: http://www.soapui.org/Service-Mocking/simulating-complex-behaviour.html.

If you want to manage your mock response dispatch more flexible, then the Script way is your choice.

Here is the sample script you can select your mock response according to the different requests:

def groovyUtils = new com.eviware.soapui.support.GroovyUtils(context);
def holder = groovyUtils.getXmlHolder(mockRequest.getRequestContent());

//Get node value from Xpath
def OID1 = holder.getNodeValue("//v2:getRequest[1]/v2:OIDs[1]");
def OID2 = holder.getNodeValue("//v2:getRequest[1]/v2:OIDs[2]");

//if condition 1 is matched, return mockresopnse1
if (OID1 == "C1308C7C-097F"&& OID2 == "") {

mockOperation.setDefaultResponse("mockresopnse1");

}
//else if condition 2 is matched, return mockresopnse2
else if (OID1 == "A097B4E5-0159" && OID2 == "17001212-AABF") {

mockOperation.setDefaultResponse("mockresopnse2");

}


PS: Due to lack of documentation and sample scripts on this, I spent me several hours to do some investigation on it, the only thing to do is "reading the APIs and have a try".
Hope it helps,And Thanks for Lynn and Vance's help on this as well! :)