- Simply use this Template Project to get started with one click.
- Create a new Java/Maven project using Eclipse, IntelliJ or your favourite IDE.
- Copy the highlighted contents of this pom.xml file into yours inside the
<project>
tag. - Follow the steps in this footnote in case you are using IntelliJ1.
- Create a new Package
TestPackage
undersrc/test/java
and create a new Java ClassTestClass
under that package. - Copy the below imports into your newly created java class.
import com.shaft.driver.SHAFT;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
- Copy the below code snippet into your newly created java class.
SHAFT.GUI.WebDriver driver;
SHAFT.TestData.JSON testData;
By searchBox = By.name("q");
By resultStats = By.id("result-stats");
@Test
public void test() {
driver.browser().navigateToURL("https://www.google.com/");
driver.verifyThat().browser().title().isEqualTo("Google").perform();
driver.element().type(searchBox, testData.getTestData("searchQuery"))
.keyPress(searchBox, Keys.ENTER);
driver.assertThat().element(resultStats).text().doesNotEqual("")
.withCustomReportMessage("Check that result stats is not empty").perform();
}
@BeforeClass
public void beforeClass() {
driver = new SHAFT.GUI.WebDriver();
testData = new SHAFT.TestData.JSON("simpleJSON.json");
}
@AfterClass
public void afterClass() {
driver.quit();
}
- Create the following file
src/test/resources/testDataFiles/simpleJSON.json
. - Copy the below code snippet into your newly created json file.
{
"searchQuery": "SHAFT_Engine"
}
- Run your
TestClass.java
as a TestNG Test Class. - The execution report will open automatically in your default web browser after the test run is completed.
- Make sure to Star ⭐ the project to get notified when a new release is pushed out.
- After upgrading your Engine it is sometimes recommended to delete the properties
folder
src\main\resources\properties
and allow SHAFT to regenerate the defaults by running any test method.
- You can change the target browser, operating system, timeouts, and other configurations using the ⚙️ Configuration Manager.
- And you can learn more from the 👤 User Guide and 📚 Javadocs.
Who else is using SHAFT? 2
- Join us via Slack & Facebook
- And feel free to create PRs directly. This lovely tutorial will help.
Big thanks to the following organizations for their support to the project with their open source licenses:
Footnotes
-
Due to a known issue with IntelliJ you need to edit your run configuration templates before running your tests by following these steps:
- Open 'Edit Run/Debug Configurations' dialog > Edit Configurations... > Edit configuration templates...
- Select TestNG > Listeners > and add these listeners one by one:io.github.shafthq.shaft.listeners.TestNGListener
- Select Cucumber Java > Program Arguments > and add this argument:--plugin io.github.shafthq.shaft.listeners.CucumberFeatureListener
- After saving the changes, remember to delete any old test runs you may have triggered by mistake before adding the needed config. ↩ -
Company names are collected via anonymous surveys and provided freely by engineers who claimed to be using SHAFT_Engine within these companies. ↩