Forum Discussion

Mourasman's avatar
Mourasman
New Contributor
14 years ago

loadUI Groovy problem - Cannot set property 'binding'

Hello guys,

I'm getting this error when trying to run my Groovy script on loadUI:

"Cannot set property 'binding' on null object"

The script is running Selenium 2.0 code. Please let me know if there's anything else you need to know.

EDIT: Do I need to copy any dependencies? I've already did twice, to the folders ..\loadui\lib and I've created a new folder called ext too (..\loadui\ext), but still no good...

Best regards,
Mourasman

6 Replies

  • Hi,

    How are you trying to run the script? Are you using the Script Runner?

    Could you post the contents of the Groovy script?

    Regards,
    Dain
    SmartBear Software
  • Mourasman's avatar
    Mourasman
    New Contributor
    Hi,

    Yes, I'm using the "Script Runner" and the contents of the script are these:

    import java.util.concurrent.TimeUnit;

    import org.junit.Assert;
    import org.junit.Before;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.By;

    private FirefoxDriver driver;
    private String baseUrl = "http://www.somerandomsite.com";

    driver = new FirefoxDriver();
    driver.get(baseUrl);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//a[@href=\"consultancy.html\"]")).click();
    driver.findElement(By.xpath("//a[@href=\"aboutus.html\"]")).click();
    driver.findElement(By.xpath("//a[@href=\"contactus.html\"]")).click();
    driver.quit();

    It's this simple. Am I missing something here?

    EDIT: Just want to add that this script works perfectly fine on SoapUI 4.0.1. (Running this as a "Groovy Script")

    Best regards,
    Mourasman
  • Hi,

    It seems likely to me that the script is failing due to missing imports. It's likely that you will have to use the Grab annotation in Groovy to pull in the Selenium dependencies for this to work.

    Another problem your script has is the private modifier, which isn't allowed for script level variables. I suggest simply removing these.

    After applying both fixes, you should have something simmilar to this:

    @Grab(group='org.seleniumhq.selenium', module='selenium-firefox-driver', version='2.9.0')
    import java.util.concurrent.TimeUnit;

    import org.junit.Assert;
    import org.junit.Before;
    import org.openqa.selenium.firefox.FirefoxDriver;
    import org.openqa.selenium.By;

    FirefoxDriver driver;
    String baseUrl = "http://www.somerandomsite.com";

    driver = new FirefoxDriver();
    driver.get(baseUrl);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//a[@href=\"consultancy.html\"]")).click();
    driver.findElement(By.xpath("//a[@href=\"aboutus.html\"]")).click();
    driver.findElement(By.xpath("//a[@href=\"contactus.html\"]")).click();
    driver.quit();


    Regards,
    Dain
    SmartBear Software
  • Mourasman's avatar
    Mourasman
    New Contributor
    Thanks for the suggestions! I did exactly what you said, also downloaded the latest WebDriver version (2.9.0), put the .jar and all its dependencies inside the \loadui\ext folder (don't even know if this is needed) and still no good... It returns exactly the same error.

    EDIT: It's fixed!! \o/ Deleted the junit imports... Sorry for the trouble and thanks for the help!

    Best regards,
    Mourasman
  • abhishek813's avatar
    abhishek813
    Frequent Contributor
    Hi Henrik,

    I am also facing the same problem and i am hoping you can help me out.

    I am using jxl api to read an excel file and then do something with the values in the cell and it runs perfectly in soapUI but when i import the same script into loadUI's script runner component i get the "Cannot set property 'binding' on null object" error.

    I have copied the jxl jar file in loadUI/ext folder.

    Sorry for posting in an old post. Your suggestions will be really helpful.

    Thanks

    -Abhishek


    import jxl.*;

    Workbook wb;
    Sheet sh;
    int rCount, randomInt;

    wb = Workbook.getWorkbook(new File("somespreashseet.xls"));
    sh = wb.getSheet(0);
    rCount = sh.getRows();

    //get random value
    randomInt = new Random().nextInt(rCount-1)+1;

    S = sh.getCell(0, randomInt).getContents();
    T = sh.getCell(1, randomInt).getContents();
    tr = sh.getCell(2, randomInt).getContents();
    cl = sh.getCell(3, randomInt).getContents();
    ac = sh.getCell(4, randomInt).getContents();
    ev = sh.getCell(5, randomInt).getContents();
    wi = sh.getCell(6, randomInt).getContents();
    ga = sh.getCell(7, randomInt).getContents();
    am = sh.getCell(8, randomInt).getContents();
    wi = sh.getCell(9, randomInt).getContents();
    re = sh.getCell(10, randomInt).getContents();
    wd = sh.getCell(11, randomInt).getContents();
    vd = sh.getCell(12, randomInt).getContents();
    pl = sh.getCell(13, randomInt).getContents();
    gr = sh.getCell(14, randomInt).getContents();
    pu = sh.getCell(15, randomInt).getContents();
    re = sh.getCell(16, randomInt).getContents();
    la = sh.getCell(17, randomInt).getContents();
    nu = sh.getCell(18, randomInt).getContents();
    fr = sh.getCell(19, randomInt).getContents();
    qu = sh.getCell(20, randomInt).getContents();

    wb.close();

    //do something with the values