RestAssured API Automation Framework Structure


Component of Framework
1) Java
2) RestAssured
3) Maven
4) TestNG
5) Log4J
6) Jenkins
7) Eclipse


Dependencies require for RestAssured API Automation :-
1)rest-assured
2)testng
3)json-simple
4)log4j
5)extentreports
6)maven-compiler-plugin
7)maven-surefire-plugin


We can run the project in the following ways
1)testng.xml
2)POM.xml
3)mvn clean test through cmd
4)Through batch file
5)Through Jenkins



How to build BDD Framework using Java, Selenium, Maven, Cucumber, Junit

1) Following Prerequisite required into the system
     a) Java should be installed. 
     b) Maven should be installed  ( System and eclipse)
     c) Environment variables should be set. JAVA_HOME and MAVEN_HOME. The path should be set.
      
     d) In Eclipse should be installed, Maven, Cucumber, Cucumber, Natural, Gherkin 

2)Create a Maven Project in the following structure



3)Add the following dependencies into POM.xml
info.cukes cucumber-java 1.2.5 info.cukes cucumber-junit 1.2.5 info.cukes cucumber-jvm-deps 1.0.5 provided net.masterthought cucumber-reporting 5.0.2 info.cukes gherkin 2.12.2 provided junit junit 4.13 org.seleniumhq.selenium selenium-java 3.141.59
4)Create login.feature file Feature: Test Greenlam smoke scenario Scenario: Test login with valid credentials Given Open Google Chrome and start application When I enter valid "vaibhavkhachane11235@gmail.com" and valid "123456789" Then User should be able to login successfully 5)Create TestRunner.java package Runner; import org.junit.runner.RunWith; import cucumber.api.CucumberOptions; import cucumber.api.junit.Cucumber; @RunWith(Cucumber.class) @CucumberOptions(features= "E:\\Automation\\SimpleMavenProject\\src\\main\\java \\Feature\\login.feature",glue={"stepDefination"}) public class TestRunner { } 6)Create stepDefination.java import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import cucumber.api.PendingException; import cucumber.api.java.en.Given; import cucumber.api.java.en.Then; import cucumber.api.java.en.When; public class LoginStepDefination { public String baseUrl = "https://www.greenlam.com/india/"; public WebDriver driver; @Given("^Open Google Chrome and start application$") public void open_Google_Chrome_and_start_application() throws Throwable { System.setProperty("webdriver.chrome.driver", "E:\\Automation\\All Supporting Jars\\chromedriver.exe"); driver = new ChromeDriver(); driver.manage().window().maximize(); driver.get(baseUrl); } @When("^I enter valid \"([^\"]*)\" and valid \"([^\"]*)\"$") public void i_enter_valid_and_valid(String arg1, String arg2) throws Throwable { driver.findElement(By.xpath("/html/body/section/section/section[5]/section/div[1]/div[3]/a[1]")).click(); driver.findElement(By.xpath("/html/body/section/section/section[1]/div[1]/div/div/div[5]/div[3]/a/i")).click(); driver.findElement(By.id("email")).sendKeys("vaibhavkhachane11235@gmail.com"); driver.findElement(By.id("pass")).sendKeys("123456789"); } @Then("^User should be able to login successfully$") public void user_should_be_able_to_login_successfully() throws Throwable { driver.findElement(By.id("send2")).click(); driver.quit(); } } 7)Run project in the following ways 1)testng.xml 2)POM.xml 3)mvn clean test through cmd 4)Through batch file 5)Through Jenkins While Running above Test using TestNG, We need the following snippet into TestRunner.java and some dependencies into POM.xml TestRunner.java import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; import org.testng.annotations.Test; import cucumber.api.CucumberOptions; import cucumber.api.testng.CucumberFeatureWrapper; import cucumber.api.testng.TestNGCucumberRunner; @CucumberOptions( features = "E:\\Automation\\SimpleMavenBDDwithTestNG\\src\\main\\java\\Feature\\login.feature", glue = {"stepDefination"}, tags = {"~@Ignore"}, format = { "pretty", "html:target/cucumber-reports/cucumber-pretty", "json:target/cucumber-reports/CucumberTestReport.json", "rerun:target/cucumber-reports/rerun.txt" },plugin = "json:target/cucumber-reports/CucumberTestReport.json") public class TestRunner { private TestNGCucumberRunner testNGCucumberRunner; @BeforeClass(alwaysRun = true) public void setUpClass() throws Exception { testNGCucumberRunner = new TestNGCucumberRunner(this.getClass()); } @Test(groups = "cucumber", description = "Runs Cucumber Feature", dataProvider = "features") public void feature(CucumberFeatureWrapper cucumberFeature) { testNGCucumberRunner.runCucumber(cucumberFeature.getCucumberFeature()); } @DataProvider public Object[][] features() { return testNGCucumberRunner.provideFeatures(); } @AfterClass(alwaysRun = true) public void tearDownClass() throws Exception { testNGCucumberRunner.finish(); } } Dependencies are :- 1)All above Junit POM file dependencies 2)TestNg dependency 3)
4)cucumber-reporting 5) Following dependecies require to run proejct through Maven