Video Tutorial:
GitHub Repo: https://github.com/akashdktyagi/AutoFratCommonLib
Code:
- Runner File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
package runner; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions ( features="classpath:features", glue="", tags="", plugin = {"pretty", "html:target/html/", "json:target/json/file.json", "com.aventstack.extentreports.cucumber.adapter.ExtentCucumberAdapter:"}, dryRun=false ) public class RunTest { } |
2. Step Defs:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
package stepdefs; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import cucumber.api.Scenario; import cucumber.api.java.Before; import cucumber.api.java.en.Given; public class StepDefs { Scenario scenario; @Before public void SetUp(Scenario s) { scenario = s; } @Given("I open the Browser and Navigate to the URL {string}") public void i_open_the_Browser_and_Navigate_to_the_URL(String string) { WebDriver driver = new ChromeDriver(); driver.get(string); scenario.write("Opened the Browser with URL: " + string); } } |
3. POM File:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.visionit</groupId> <artifactId>CanBeDeleted</artifactId> <version>0.0.1-SNAPSHOT</version> <properties> <cucumber.version>4.2.0</cucumber.version> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.8</maven.compiler.source> <maven.compiler.target>1.8</maven.compiler.target> </properties> <build> <plugins> <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>3.0.0-M1</version> <configuration> <parallel>methods</parallel> <threadCount>2</threadCount> <perCoreThreadCount>false</perCoreThreadCount> <!-- <useUnlimitedThreads>true</useUnlimitedThreads>--> <argLine>-Xmx1024m -XX:MaxPermSize=256m</argLine> </configuration> </plugin> </plugins> </build> <!-- For Cucumber --> <dependencies> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-java</artifactId> <version>${cucumber.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-junit</artifactId> <version>${cucumber.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>4.12</version> <scope>test</scope> </dependency> <!-- For dependency Injection --> <dependency> <groupId>io.cucumber</groupId> <artifactId>cucumber-picocontainer</artifactId> <version>${cucumber.version}</version> <scope>test</scope> </dependency> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>3.141.59</version> </dependency> <!-- For Extent Reports --> <!-- Extent Report Adapter for Cucumber --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports-cucumber4-adapter</artifactId> <version>1.0.7</version> </dependency> <!-- https://mvnrepository.com/artifact/com.aventstack/extentreports --> <dependency> <groupId>com.aventstack</groupId> <artifactId>extentreports</artifactId> <version>4.0.9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.freemarker/freemarker --> <dependency> <groupId>org.freemarker</groupId> <artifactId>freemarker</artifactId> <version>2.3.28</version> </dependency> <!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver --> <dependency> <groupId>org.mongodb</groupId> <artifactId>mongo-java-driver</artifactId> <version>3.10.2</version> </dependency> </dependencies> </project> |