Last updated March 20, 2010 17:34, by Jørgen Austvik
Feedicon  

Example Webapp test suite with Jetty and Selenium WebDriver

Below the jet-example-web directory there is an example web test suite that uses Jetty to serve a simple JSP page, and Selenium WebDriver to test the JSP page.

Running the example

You should be able to run the test by doing the following:

 cd jet-example-web
 ./run.sh

The run.sh script will build everything, and copy .jar files to the correct places before it starts a simple test.

The web application

This is an extremely simple web application, almost straight out of the Maven Webapp archtype. There is only one index.jsp page, which you can look at below the jet-example-web-webapp directory.

The test suite

The test suite is located below the jet-example-web-test directory. Here is a list of files that are of interest, and a short explanation of what they do.

webapptest.xml

This is a simple JET XML test file, which says that we should first start Jetty with the JAR file specified with the name given by the jet.jetty.war binding and installed in the jet.jetty.test.installPath binding. While Jetty is running the SimpleWebTestCase is run.

JettyWebappSetUp.java

This is a Setup that starts a Jetty server with a WAR file in its setUp(), and stops the server in its tearDown(). It gets a free port number, and reads which WAR file to use and which installpath to read it from based on binding. After the server is started, it sets the jet.jetty.protocol and jet.jetty.contextPath so that test cases inside this Setup (in the XML file) knows how to connect to the running Jetty server.

SimpleWebTestCase.java

This is a minimalistic test case with two methods. getUrl(String fileName) returns a URL to a running Jetty instance for a given filename on the running instance. It uses the bindings set in JettyWebappSetUp to get the correct path.

testIndexWebPage() runs a Selenium WebDriver test and uses normal JUnit methods, and is an example on how to run WebDriver from a JET test.

testsuite_jetdefaults.properties

This file ties things together. Two installpaths are declared (testsuite and webapp), and it says which directories should be used below each of these directories. You will see that the location of these installpaths are set in sample_web.properties.

The loghandler lines just tell JET about which log files to use.

There are also two plugins declared. The BindingsValidator let us use binding values that are not declared in this property file. The SoftwareInformation plugin let us give information to the jetreport.xml about what software has been used to run the test.

JettyBindingsValidator.java

This plugin that is declared used in the testsuite_jetdefaults.properties will say that any binding key that starts with jet.jetty should be allowed. It is meant as a simple example on how to add a bindings validator. The reason bindings validators are needed in JET is because we had too many misspelled bindings and that gave us lots of troubleshooting.

JettySoftware.java

This class give us information for jetreport.xml and jetbatchreport.xml about the software used. It is meant as a simple example on how to add software information to your own test suite. It is declared used in testsuite_jetdefaults.properties.

The running script

jet-example-web/run.sh creates two directories; ts_dir and webapp_dir. These are pointed to from sample_web.properties. It then uses maven to build the webapp and test suite, and then copies the correct files to the correct paths. The reason it is so big is that especially Selenium, but also Jetty has many dependencies.

After all the files are in the correct place, JET is started to run the 'webapptest.xml' test'.

sample_web.properties

This file tells us which machines to run the test on, and where the install paths and logs are located.

The logs

After running the tests, you will find a JET-logs/results_webapptest_<date and time> directory with the logs from the test. In jetresult.xml you will find information about the test result, and see the output from JettySoftware. jet*.log will contain logs from JET, including from the test setups and test cases, and jag*.log will contain information from the embedded JAG that is started by JET.

You can see jetWeb0.0.log which was declared in testsuite_jetdefaults.properties as a loghandler, and it should contain information logged from both JettyWebappSetUp and SimpleWebTestCase.

  • Mysql
  • Glassfish
  • Jruby
  • Rails
  • Nblogo
Terms of Use; Privacy Policy;
© 2010, Oracle Corporation and/or its affiliates
(revision 20120127.ac94057)
 
 
Close
loading
Please Confirm
Close