Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Stevia 10 minute Quick Start
In this 10-minute guide we will display the setup of a Stevia project, from zero to a complete test execution with a test report. We have tried to make everything as clear-cut as possible, but feel free to contact us if something is not as obvious to you.
- Basic knowledge of Maven (http://maven.apache.org)
- Familiarity with Java and Spring Framework (http://spring.io)
- Familiarity with an IDE (we will use Eclipse Kepler J2EE as an example)
Project basics - create a new project
In Eclipse, go to the empty area on the left and right-click, select a new Java Project.
In the new project created, you should enable the Maven plugin, this is easily done via the right-click context menu, select "Configure -> Convert to Maven project"
In the dialog that will be presented, add the Group Id, Artifact Id, version in order to create the pom xml of your maven project:
Now, on the pom.xml you must provide as dependency the Stevia project info and the sonatype repository in order to be resolved via maven and downloaded. Also, include the surefire plugin in order for the tests to be included on maven execution cycle. See below the three extracts:
repositories and within the
plugin for the surefire plugin:
<dependencies> <dependency> <groupId>com.persado.oss.quality.stevia</groupId> <artifactId>stevia-core</artifactId> <version>0.9.12-SNAPSHOT</version> </dependency> </dependencies> <repositories> <repository> <id>sonatype-snapshots</id> <name>OSS Sonatype Snapshot Repository</name> <url>https://oss.sonatype.org/content/repositories/snapshots</url> </repository> </repositories> <build> <pluginManagement> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <version>2.14</version> <configuration> <skipTests>false</skipTests> </configuration> <executions> <execution> <id>default-test</id> <phase>test</phase> <configuration> <suiteXmlFiles> <suiteXmlFile>src/test/java/testng.xml</suiteXmlFile> </suiteXmlFiles> </configuration> </execution> </executions> </plugin> </pluginManagement>
The complete pom.xml (with your additions as above) should be looking like the one below:
(We're half-way there. Time for a break; continue below with the interesting stuff...
Create the Page Objects and Test code
Next step is to create the page object which will represent the google home page. (Page Object class will be created under the source folder: src/main/java). Note: Each Page Object class must extend the Stevia “WebComponent” class.
We will create a Page Object (https://code.google.com/p/selenium/wiki/PageObjects) Spring bean with two locators, the google input field and the search button:
Now, we must include this bean under the test beans of the project in order for them to be available when the Spring Framework will load its application context. We will create and then place a spring context xml with name: “META-INF/spring/test-beans-myProject.xml” under the “src/main/resources” path.
Note: Stevia will search all the xml files which name is matched by this search expression: META-INF/spring/test-beans-*.xml.
On the next step we will be creating a Test Class:”SearchSteviaViaGoogle.java” which will go to the google page and search for Stevia on GitHub, then click the result of google search. Note: My Test class must extend the Stevia class “SteviaTestBase” class which is responsible for initializing Stevia contexts on start and shutting down at the end:
Moreover, set the class name of our test on the testng.xml and also the Stevia and HTML Reporter listeners:
- “TestListener” : provides screenshots in case of test failure,
- “HTMLReporter” : provides an html report to view the results
There is no need to start any selenium RC server, just verify that under your testing.xml(you must created under the 'src/test/java/' path) you have set:
parameter name="rcHost" value="localhost" parameter name="driverType" value="webdriver" parameter name="debugging" value="true"
By default tests run on Firefox browser, you just need to install geckoDriver.
In case you need to run it on Chrome, set the value on your testing.xml:
parameter name="browser" value="chrome"
Chrome driver also need to be installed
Finally, right-click on the project area in Eclipse, select "Run As → Maven Build ... → Goals: clean install" and that's it! You just finished the Quick Start guide!. Do not forget that the Test class included on testng.xml will be executed, and on completion, the html report will look like this:
The report is "hidden" inside mavens' /target directory. Search in there for "index.html" and you'll find it.