Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This section lists up several kinds of testing methods to validate behaviour functions of web UI of Tadpole. Please refer the UI Guideline that explains policies to construct consistent pages over all Tadpole features. 
Tadpole includes various UI components such as button, text field, table, and message dialog supporting from Eclipse RAP Platform (Eclipse RAP 3.0)

 In order to test functionality of web elements, test code shall be able to handle followings.

...

Code Block
var pkg = JavaImporter(org.openqa.selenium)
var support_ui = JavaImporter(org.openqa.selenium.support.ui.WebDriverWait)
var conditions = org.openqa.selenium.support.ui.ExpectedConditions
var wait = new support_ui.WebDriverWait(WDS.browser, 1000)
//Open browser and load tadpole homepage
WDS.sampleResult.sampleStart()
WDS.browser.get("http://127.0.0.1:10081/tadpole")
////Test Login as manager
//input email address as Login Id
wait.until(conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'Login')]")))
var loginEmailField = WDS.browser.findElement(pkg.By.ByCssSelector('input[type="text"]:first-of-type'))
loginEmailField.click()
loginEmailField.sendKeys(['manager.tadpole@gmail.com'])
//input password
var loginPasswordField = WDS.browser.findElement(pkg.By.ByCssSelector('input[type="password"]:first-of-type'))
loginPasswordField.click()
loginPasswordField.sendKeys(['manager'])
//click Login button
var loginButton
if(conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'Login as Manager')]"))) {
    loginButton = WDS.browser.findElement(pkg.By.xpath("//div[@tabindex=1][4]/div[contains(text(), 'Login')]"))
} else {
    loginButton = WDS.browser.findElement(pkg.By.xpath("//*[contains(text(), 'Login')]"))
}
var action = new org.openqa.selenium.interactions.Actions(WDS.browser)
action.moveToElement(loginButton).click().build().perform()
//If success, ""Connection Manager"" shall be shown
try {
    //wait 10 seconds for element with "Connection Manager@", it does not exist, so error will be occurred in 10 seconds
    wait.until(conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'Connection Manager')]"))) 
    if(!conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'Connection Manager')]"))) {
        wait.until(conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'New Database Connection')]")))
    }
    if(conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'Connection Manager')]"))
       || conditions.presenceOfElementLocated(pkg.By.xpath("//*[contains(text(), 'New Database Connection')]"))) {
        WDS.log.info('Success')
        WDS.sampleResult.setSuccessful(true)
    }
}
catch(err) {
   WDS.log.error(err.message)
   var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
   screenshot.renameTo(java.io.File('error_screenshot_'+ Java.lang.System.currentTimeMillis() + '.png')) //will be saved under home directory
   WDS.sampleResult.setSuccessful(false) //will be marked as error at view results in table
}
finally
{
   WDS.sampleResult.sampleEnd()
   var screenshot = WDS.browser.getScreenshotAs(pkg.OutputType.FILE)
   screenshot.renameTo(java.io.File('screenshot_'+ Java.lang.System.currentTimeMillis() + '.png')) //will be saved under home directory
}

 

Test code example 2. with Geb + Spock

1. Why Geb + Spock ?

Groovy can be used to write JUnit test case. Groovy supports rich set of testing features in language level;  (e.g.) Variant assert expression which shows improved message about failure of execution. Mocking with MockFor, StubFor and MetaClass. Highly expressive.

Spock is a testing framework for java and groovy application, which extends JUnit and most IDE compatible. It can be used for testing unit, integration or even BDD(Behaviour Driven Development).

...

  • DOM access via a JQuery-like $ function

  • implements the page pattern: http://martinfowler.com/bliki/PageObject.html

  • support for modularization of certain web components (e.g. menu-bars, etc.) with modules

  • integration with JavaScript via the JS variable

1.  Install eclipse plugin: search "Gradle" at Eclipse Marketplace and install the Gradle IDE.

2. Download sample code and import it at Eclipse

3. What is Geb?

 

4. What is Spock?

Example code can be downloaded from at 

Pros 

 

Link of Why Spock

 

Cons

 

...

 You can build project by Refreshing Gradle or type command "./gradlew build" under project directory.

 

Test code example 3. Selenium web driver + JUnit4

http://eclipsesource.com/blogs/2014/04/29/how-to-write-ui-tests-for-rap-with-selenium-2-0/

...