-
Notifications
You must be signed in to change notification settings - Fork 46
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 IntelliJ IDEA as an example)
- Tested with Java 11 and more - Spring 5
- TestNG
In your IDE (e.g: IntelliJ), create a new maven project provide groupId / artifactId for your 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. Also, include the surefire plugin in order for the tests to be included on maven execution cycle. See below the three extracts: dependencies
, repositories
and within the build
tag, plugin
for the surefire plugin:
<dependencies>
<dependency>
<groupId>com.persado.oss.quality.stevia</groupId>
<artifactId>stevia-core</artifactId>
<version>0.9.51</version>
</dependency>
</dependencies>
<build>
<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>
</plugins>
</build>
(We're half-way there. Time for a break; continue below with the interesting stuff... 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 and the actions that implement these locators:
Now, we must include this bean under the test beans configuration 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.
There you should put the class(es) that you need to be initialized
Note: Stevia will search all the xml files which name is matched by this search expression: META-INF/spring/test-beans-*.xml.
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
Prerequisites: In case you run the test at chrome like the example, ChromeDriver needed to be installed
In case you need Firefox, install GeckoDriver and change the "browser = firefox".
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(under /target/surefire-reports/html/index.html):
The report is "hidden" inside mavens' /target directory. Search in there for "index.html" and you'll find it.