Forum Discussion

hammer's avatar
hammer
Occasional Contributor
13 years ago

Groovy Script does not work

Hi,

I'm trying to write a small UI for a ID/Password Input. I've got 2 textareas and one Button. When you Click the Button, the Values of the textareas should be written in my TestSuite-Properties. What does not work is my function "write". It seems like it never gets executed, no matter what Operations i put in. I tried a few ways to make my Button b ActionPerfomed, none of it worked.
Anyone got a clue?
Thanks a lot!
hammer

import groovy.swing.SwingBuilder
import java.awt.GridLayout
import javax.swing.JFrame

SwingBuilder swing = new SwingBuilder()
def write(event) {
testRunner.testCase.testSuite.setPropertyValue("ID",textID.getText())
testRunner.testCase.testSuite.setPropertyValue("PW",textPW.getText());
}
f = swing.frame(pack: true, show: true) {
panel(layout: gridLayout(cols: 0, rows: 3)) {

textID = textArea(text:"ID");
textPW = textArea(text:"Passwort");
b = button(text:"OK",actionPerformed:this.&write);
}
}

4 Replies

  • hammer's avatar
    hammer
    Occasional Contributor
    Hi,

    has nobody any ideas? Did anybode here write something with user interaction for soapUI?
    Thx.

    Hammer
  • Hi,

    have you try :

    b = button(text:"OK",actionPerformed: {
    testRunner.testCase.testSuite.setPropertyValue("ID",textID.getText())
    testRunner.testCase.testSuite.setPropertyValue("PW",textPW.getText());
    })

    Hope this helps!

    regards,
  • RJanecek's avatar
    RJanecek
    Regular Contributor
    I dont think you can write inside test step groovy script some UI logic. You can create custom testSuite properties where you can write it.
  • M_McDonald's avatar
    M_McDonald
    Super Contributor
    Sure you can. There are lots of great examples out on the web like this

    http://www.pspaeth.de/index.php/techarea/43-java/72-dialogs-in-groovy.html

    that will run from a Groovy script step. Modifying that example like this works for me:

    import groovy.swing.SwingBuilder
    import java.awt.FlowLayout as FL
    import javax.swing.BoxLayout as BXL

    def s = new SwingBuilder()
    s.setVariable('myDialog-properties',[:]) //-- 1 --//
    def vars = s.variables //-- 2 --//
    def dial = s.dialog(title:'Get Credentials',id:'myDialog',modal:true, pack:true, show:true) { //-- 3 --//
    panel() {
    boxLayout(axis:BXL.Y_AXIS)
    panel(alignmentX:0f) {
    flowLayout(alignment:FL.LEFT)
    label('User ID')
    textField(id:'userid',columns:10) //-- 4 --//
    }
    panel(alignmentX:0f) {
    flowLayout(alignment:FL.LEFT)
    label('Password')
    textField(id:'password',columns:10) //-- 4 --//
    }
    panel(alignmentX:0f) {
    flowLayout(alignment:FL.LEFT)
    button('OK',preferredSize:[80,24],
    actionPerformed:{
    vars.dialogResult = 'OK' //-- 5 --//
    dispose()
    })
    button('Cancel',preferredSize:[80,24],
    actionPerformed:{
    vars.dialogResult = 'cancel'
    dispose()
    })
    }
    }
    }

    log.info 'and the result is: ' + vars.dialogResult
    log.info 'the userID entered is: ' + vars.userid.text
    log.info 'password is: ' + vars.password.text

    testRunner.testCase.testSuite.setPropertyValue("ID",vars.userid.text)
    testRunner.testCase.testSuite.setPropertyValue("PW",vars.password.text);