Sunday, July 5, 2009

Silk4J Overview & Analysis

Silk4j was introduced from Silktest 2008. Hereafter user can use Java as test scripting language with the help of Silk4J Package. It is supported only with Open Agent. I hope that Borland might target developers too. User can write java unit tests as well as GUI tests.

From Silktest Help - Silk4J Eclipse Plugin

Silk4J enables user to create functional tests using the Java programming language. Silk4J provides a Java runtime library that includes test classes for all the classes that Silk4J supports for testing. This runtime library is compatible with JUnit, which means you can leverage the JUnit infrastructure and run and create tests using JUnit. You can also use all available Java libraries in your testcases.

The testing environments that Silk4J supports include:

  • Adobe Flex applications
  • Java SWT applications
  • Windows Presentation Foundation (WPF) applications
  • Windows API-based client/server applications
  • xBrowser applications


Silk4J with Open Agent - Google Search testcase

I have gone through documents such as Silk4J_QuickStartGuide_en.pdf and Silk4J_AdvancedUserGuide_en.pdf. I created the sample code and it works fine.

package com.palani;
import org.junit.Before;
import org.junit.Test;

import com.borland.silktest.jtf.Desktop;
import com.borland.silktest.jtf.TechDomain;
import com.borland.silktest.jtf.xbrowser.BrowserWindow;
import com.borland.silktest.jtf.xbrowser.DomButton;
import com.borland.silktest.jtf.xbrowser.DomTextField;

public class GoogleSearch {
private Desktop desktop = new Desktop();
private BrowserWindow browser;

@Before
public void setUp() throws Exception {

browser = (BrowserWindow)desktop.executeBaseState(
"C:/Program Files/Internet Explorer/iexplore.exe", null, null,
".//BrowserWindow", TechDomain.XBROWSER);
browser.navigate("http://www.google.co.in/");
}

@Test
public void testSimpleGoogleSearch() throws Exception {

DomTextField searchText = (DomTextField)browser.find (".//DomTextField[@title='Google Search' and @name='q']");
searchText.setText("");
searchText.setText("silk4j tutorial");
DomButton btn = (DomButton)browser.find(
".//DomButton[@type='submit' and @name='btnG']");
btn.click();
}
}


4Test with Open Agent - Google Search testcase
The same case is written in 4Test. SilkTest supports a subset of the XPath query language. It gives dynamic object recognition.

[ ]
[-] testcase GoogleSearch1 () appstate none //DefaultBaseState
[ ] STRING sUrl="http://www.google.co.in/"
[ ]
[-] if (! InternetExplorer.Exists(2))
[ ] InternetExplorer.Invoke ()
[ ] InternetExplorer.SetActive ()
[ ] InternetExplorer.Maximize ()
[ ]
[ ] WINDOW wMain = Desktop.Find(".//BrowserApplication")
[ ] WINDOW wBrowser = wMain.Find(".//BrowserWindow")
[ ]
[ ] wMain.SetActive()
[ ] wBrowser.Navigate (sUrl)
[ ] WINDOW wText1=wBrowser.Find(".//DomTextField[@title='Google Search' and @name='q']")
[ ] wText1.SetText("Silk4j Tutorial")
[ ] wBrowser.Find(".//DomButton[@name='btnG' ]").Click ()
[ ]
[ ] WINDOW wText2=wBrowser.Find(".//DomTextField[@name='q']")
[ ] wText2.SetText("Silktest Extension Kit")
[ ] wBrowser.Find(".//DomButton[@name='btnG' ]").Click ()
[ ]
[ ]


Selenium RC Java format - Google Search testcase

Selenium is a open source tool and can be used only web based applications. But user can choose different languages to develop the suite. Selenium tests can be written with Selenese, PHP, Perl, Python, Ruby, DotNet and Java.

import org.openqa.selenium.server.SeleniumServerTest;
import com.thoughtworks.selenium.*;
import junit.framework.*;
import org.openqa.selenium.server.SeleniumServer;

public class TestSearch extends SeleniumServerTest {
private Selenium browser;
public void setUp() throws Exception {
SeleniumServer seleniumServer = new SeleniumServer();
browser = new DefaultSelenium("localhost", 5555, "*firefox", "http://www.google.com");
seleniumServer.start();
browser.start();
}

public void testGoogle() {
browser.open("/webhp?hl=en");
browser.type("q", "hello world");
browser.click("btnG");
browser.waitForPageToLoad("5000");
assertEquals("hello world - Google Search", browser.getTitle());
}

public void tearDown() {
browser.stop();
}
}


Few Questions

Now Silktest and selenium both supports in Java language. Silktest supports many type of applications. In other end, Selenium supports many Operating Systems and browsers. I have few questions on Silk4J.
  1. Can Silk4J utilize silktest features such as TestcaseEnter,TestcaseExit,scriptEnter and ScriptExit?
  2. Target audience?
  3. Any Success stories (implementations)?

4 comments:

tehlexx said...

hi,
testcase enter/exit map to @Before and @After annotations in junit,

script enter/exit map to @BeforeClass and @AfterClass.

for more information about junit annotation have a look in the junit manual: junit manual

Palani Selvam said...

Thanks for your information. I have to explore JUnit...

Unknown said...

There's really not a whole lot of documentation on Silk4j available, so I was wondering if you might know the answer to a (seemingly) simple question.

I'm simply trying to close an error dialog that pops up when some invalid input is entered into the application. It seems that Silk4J doesn't recognize this although the equivalent in 4test would be the MessageBox object. Any ideas on how to close a MessageBox using Silk4J?

Palani Selvam said...

Gavin,

Honestly I didn't try the popups yet. I hope, atleast it should work with silktest2009.