2

My goal is to develop a Gradle script that starts my Wildfly before the tests start running, and stop it after the tests complete, this way, Selenium tests can run.

To achieve this goal, I've decided to do the following at my build.gradle:

Before the test (test.doFirst)

  1. Check if JBOSS_HOME environment variable exists;
  2. If it exists, I run the following to start my Wildfly:

    ext.jbossHome = System.getenv('JBOSS_HOME')
    ext.isWildflyAvailable = (jbossHome != null)
    
    task startWildfly(type:Exec) {
        if (!isWildflyAvailable) {
            return;
        }
    
        println 'Starting Wildfly...'
        println 'JBOSS_HOME: ' + jbossHome
    
        workingDir = file(jbossHome + '\\bin')
        commandLine = ['cmd', '/C', 'standalone.bat']
    }
    
    test.doFirst {
        startWildfly.execute()
    }
    
    // Ommited logic for stopping Wildfly
    

My Wildfly starts as I can read the log on console, but after it's startup, Gradle stuck on it and never proceed with the rest of the build.

Trying to avoid that, I appended an & at the end of the command line, as I would do if I were starting my server manually on console, but Gradle started to raise erros, in both attempts:

commandLine = ['cmd', '/C', 'standalone.bat &']
commandLine = ['cmd', '/C', 'standalone.bat', '&&']

After some googling, I found something about running the commandLine on a different thread, but, I will lost track of the process and won't be able to know when my Wildfly started.

Is there another alternative?

Bruno Gasparotto
  • 671
  • 12
  • 31
  • Manual scripting would be my last resort to be honest. I'm wondering if it would be possible to leverage Arquillian to manage the booting up of a live server for the selenium tests (with the added bonus that you can use arquillian itself for other types of automated tests). That makes it more cross-platform too. http://arquillian.org/ – Gimby Nov 26 '15 at 14:12
  • @Gimby, I considered Arquillian as well, unfortunatelly, I'm not much familiar with it. However, I think it worths the effort of doing some research about it, but, if it happens to fit my needs (work along Gradle and Selenium), I might remove from `build.gradle` all the manual scripting related to Wildfly startup? Besides that, making it cross-platform is a plus I seek. – Bruno Gasparotto Nov 26 '15 at 15:30
  • I believe Arquillian boots containers embedded - so rather than starting the server before you can run tests, it starts the server as part of test suite initialization. Wildfly itself is just another Java program after all, the script you run is basically just booting up another JVM instance to get it going. The bigger question is: can you properly use Arquillian through Gradle? That I really don't know. The documentation seems to only mention Maven. – Gimby Nov 26 '15 at 15:46
  • @Gimby By embedded you mean that I might don't need an external installation of Wildfly anymore? By the way, it looks like I can use Arquillian through Gradle, I've found the following on GitHub: [mmatloka/arquillian-gradle-sample](https://github.com/mmatloka/arquillian-gradle-sample/blob/master/single-module/src/test/java/org/jboss/shrinkwrap/resolver/example/FullGreeterTest.java). I will keep searching. – Bruno Gasparotto Nov 26 '15 at 18:05
  • 1
    Yes, but at this point I'd simply refer to the manual than to me :) – Gimby Nov 27 '15 at 08:14

0 Answers0