Search code examples
testinggrailsseleniumfunctional-testing

Functional tests of Selenium fail on Grails


I'am trying to integrate selenium tests with a grails project and some problems are appearing.

I am using the selenium-rc plugin

grails install-plugin selenium-rc

Here are the errors in the tests:

ERROR: Element username not found

com.thoughtworks.selenium.SeleniumException: ERROR: Element username not found
    at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:97)
    at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:91)
    at com.thoughtworks.selenium.DefaultSelenium.type(DefaultSelenium.java:291)
    at com.thoughtworks.selenium.Selenium$type$0.call(Unknown Source)
    at grails.plugins.selenium.SeleniumWrapper.type(SeleniumWrapper.groovy)
    at com.thoughtworks.selenium.Selenium$type.call(Unknown Source)
    at com.example.DashboardTests.testTeste(DashboardTests.groovy:25)

This is just a test that log in my application.

Here is the test code:

import static org.hamcrest.Matchers.*
import static org.junit.Assert.*
import com.thoughtworks.selenium.*
import grails.plugins.selenium.*

import org.junit.*


@Mixin(SeleniumAware)
class DashboardTests extends GroovySeleneseTestCase{

    void testTeste() throws Exception {
        selenium.open("http://localhost:8080/login/auth")
        selenium.type("username", "user")
        selenium.type("password", "12345")
        selenium.clickAndWait("button")
    }
}

I don't know what is happening, I thought that can be the configuration, here is the code:

selenium {

    slow = false                                    // true to run tests in slow resources mode
    singleWindow = true                             // true for single window mode, false for multi-window mode
    browser = "*googlechrome"                       // can include full path to executable, default value is *firefox or *iexplore on Windows
    url = "http://localhost:8080/"                      // the base URL for tests, defaults to Grails server url
    defaultTimeout = 60000                          // the timeout after which selenium commands will fail
    windowMaximize = false                          // true to maximize browser on startup
    screenshot {
        dir = "./target/test-reports/screenshots"   // directory where screenshots are placed relative to project root
        onFail = false                              // true to capture screenshots on test failures
    }
    server {
        host = "localhost"                          // the host the selenium server will run on
        port = 4444                                 // the port the selenium server will run on
    }
    userExtensions = ""                             // path to user extensions javascript file

}

I am using chrome as the browser because firefox was causing errors in my project.

How to resolve it?


Solution

  • I resolved the issue.

    The error occurred because my test environment was without context, thats why selenium can`t access the data.

    thanks all.