Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Unit Testing : Selenium + Maven

    Hello,
    Here are the informations you need :
    Version of smartGWT : 3.0
    Version of maven-gwt-plugin : 2.4.0
    Browser involved : All (using HtmlUnit emulating Firefox)

    Here is my problem : I want to unit test a huge application using Selenium. The fact is that I want to test only the client side (the server side has already a 80% test coverage). I'm actually using maven.

    It's not a problem of code, I understand how to unit test the application, the concepts are quite simple. Only one problem remains :
    How am I supposed to find the widget I want to interract with ?
    The IDs are generated automatically, and ensureDebugId() doesn't effect that. I tried to use the scLocators, but it gives me a beautiful error :
    "scLocator could not be resolved as a type"

    So is there a simple way to implement scLocators in Selenium (using maven) ?
    I know there is something to do with the user-extensions.js you give in your package, but where am I supposed to define this path ? And how will I know if it as loaded ? (And ho Eclipse will know that scLocator is a known type ?)

    Could you help me please ? I'm a trainee so I'm not an expert in Java...
    Thanks a lot for your future answers,
    Sorry for my english I'm not a native so it's quite bad hehe

    -- Depado

    #2
    That error message indicates that you have not loaded the Selenium extensions provided in the SDK during playback. See the user-guide.html in the directory with the Selenium extensions.

    Comment


      #3
      Thanks for your answer.

      This is what I did in my pom.xml :
      Code:
      <configuration>
      		<excludes>
      			<exclude>**/Selenium*.java</exclude>
      		</excludes>
                      <defaultUserExtensionEnabled>true</defaultUserExtensionEnabled>
                      <defaultUserExtension>src/test/resources/user-extensions.js</defaultUserExtension>
      </configuration>
      And this is what maven tells me :
      Code:
      [INFO] User extensions: D:\_AUDIENS\workspace\trunk\project\target\selenium\user-extensions.js
      Do you know how to configure the maven-selenium-plugin ?
      Because it's the only thing left that blocks me on that project...
      (Btw, do you know if I can use scLocators with htmlunit driver ? Or not at all ? Because there will be plenty of tests so the faster, the better)

      Comment


        #4
        Never mind Maven, just make sure user-extensions.js is actually being loaded during your tests. Firebug's Net panel is the definitive test - if it's not being loaded, then you can troubleshoot your Maven configuration to find out why not (wrong directory, etc).

        Comment


          #5
          Well Maven is in the project specification, I can't get rid of it.
          How can I be sure to load the user-extensions.js during my tests ?
          Must I open the selenium-server.jar and replace the existing user-extensions.js in it directly ?

          These tests must be automated, I can't juste modify the selenium-server.jar each time...

          It's been a week since I began searching how to load the user-extensions.js. I still can't get through it. :/

          (Thanks for the time you accordate to me)

          Comment


            #6
            All you need to do is load the .js file successfully during tests. There is no need to modify the Selenium server .jars. If a complex Maven setup exists and you do not know how to do something simple like load a .js file during testing within this complex Maven setup, then we would recommend talking to whomever set up Maven. This should be very simple.

            Comment


              #7
              Well I quite succeed to load the .js, though I put it in the target file. So it will be removed each time I recompile. I'll see that with the maintainer of the maven-selenium-plugin project.
              I'll post the answer here when I'll get it if you want, it could be interesting for people using maven and smartGWT. (even if I feel quite alone right now haha)

              Thanks for your time.
              Regards,
              Depado

              Comment


                #8
                You are not alone. I'm actually studying how to achieve SmartGWT testing with Maven. So please post here any useful information. thanks.

                Comment


                  #9
                  I managed to make everything work fine with maven and smartGWT+Selenium. What do you want to know ?

                  Comment


                    #10
                    Don't even ask, this is a community forum. Feel free to share. If you have a blog, I strongly encourage you to do some tutorial on that.

                    Regards

                    Comment


                      #11
                      Well I could explain everything I know but it would take so long that I won't work the rest of the day, so I'm asking with what you have troubles, I'll answer you the best I can.

                      Are you using Selenium RC or Selenium Webdriver ?
                      If you have RC where does it not work ?

                      Informations :
                      - Your Selenium tests must separated from the rest of your tests (with surefire for example).
                      - To do that make sure you have a distinct pattern name for your tests example : **/Selenium*.java.
                      - You have to load the user-extensions.js in your selenium-maven-plugin.
                      - You have to start the selenium server before executing the tests.
                      - You must ensure you have a clean firefox profile unless you want it to go on recovery mode 1 time out of 10.

                      For information here is the maven lifecycle you should use (if you're working with continuous integration or you want it to be fully automated) :

                      1 - Build war + unit test serve side
                      2 - Deploy the war on a embded container (such as Jetty or Jetty+Cargo)
                      4 - Start the selenium server
                      5 - Execute the tests
                      6 - /!\ CLOSE the selenium-server unless you want it to run forever (use mvn selenum:stop-server to stop it manually)
                      7 - Close the container

                      Comment


                        #12
                        Guys,

                        Has anybody worked on selenium test coverage for client side code???

                        Thanks.

                        Comment


                          #13
                          That's what we are talking about... Server side doesn't need any other stuff than JUnit since you don't have to test the application when it's deployed. What do you want to know ?
                          Oh I didn't read well. Just use Jacoco for your test coverage. As it is launched as a java agent, it is able to calculate the coverage of your code :)
                          Actually I'm making a blog about unit testing with selenium and maven, so if you want to see... It's not complete but it's clear and is like a tutorial. Give me some feedback if you want to : http://noobdevelopper.tumblr.com/
                          Last edited by Depado; 24 May 2012, 00:27.

                          Comment

                          Working...
                          X