*************
Deck of Cards [http://deckofcardsapi.com/] - with Intellij
*****************************
POM file
*****************************
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>deckofCardsAPI</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.9</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.poi/poi-ooxml-schemas -->
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml-schemas</artifactId>
<version>4.0.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>com.relevantcodes</groupId>
<artifactId>extentreports</artifactId>
<version>2.41.2</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-testng</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>net.masterthought</groupId>
<artifactId>cucumber-reporting</artifactId>
<version>5.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/info.cukes/cucumber-java -->
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-java</artifactId>
<version>1.2.6</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-jvm-deps</artifactId>
<version>1.0.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-picocontainer</artifactId>
<version>1.2.6</version>
</dependency>
<dependency>
<groupId>info.cukes</groupId>
<artifactId>cucumber-junit</artifactId>
<version>1.2.6</version>
</dependency>
</dependencies>
</project>
Feature File
******************
Feature: API Testing
I want to do API Testing using RestAssured
Scenario: Create a new deck of cards
Given Input to new Deck of Cards
Then Get the success results of Deck of Cards
Scenario: Shuffle the Cards
Given Input to Shuffle the cards
Then Get the success Shuffle the Cards resultsRunner File******************package APIRunner;
import cucumber.api.CucumberOptions;
import cucumber.api.testng.AbstractTestNGCucumberTests;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import APIReport.ReportHelp;
@CucumberOptions(strict = true, monochrome = true, features = "src/test/Features", glue = "APIStepDef", plugin = {
"pretty", "json:target/cucumber.json", "html:target/cucumber-reports/report.html" })
public class CucumberRunner extends AbstractTestNGCucumberTests {
@BeforeClass(alwaysRun = true)
public void beforeClass() throws Exception {
}
@AfterClass(alwaysRun = true)
public void takeScreenshot() throws Exception {
}
@AfterSuite(alwaysRun = true)
public void generateHTMLReports() {
ReportHelp.generateCucumberReport();
}
}StepDef File******************package APIStepDef;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import ReusableFiles.Utilities;
import static io.restassured.RestAssured.given;
public class APIStepDef {
@Given("Input to new Deck of Cards")
public void GivenDeckofCards() throws Exception{
System.out.println("@GivenDeckofCards");
}
@Then("Get the success results of Deck of Cards")
public void ThenDeckofCards() throws Exception{
try {
System.out.println("@ThenDeckofCards");
given().queryParam("jokers_enabled","true").when()
.post(Utilities.ReadPropertiesFile("NewDeckCards")).then().log().body();
System.out.println("Deck of Cards Response");
} catch (Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
};
}
@Given("Input to Shuffle the cards")
public void GivenShuffleCards() throws Exception{
System.out.println("@GivenShuffleCards");
}
@Then("Get the success Shuffle the Cards results")
public void ThenShuffleCards() throws Exception{
try {
System.out.println("@Then");
given().queryParam("deck_count","2").when()
.post(Utilities.ReadPropertiesFile("ShuffleCards")).then().log().body();
System.out.println("Shuffle Cards Response");
} catch (Exception e){
// TODO Auto-generated catch block
e.printStackTrace();
};
}
}Report File******************package APIReport;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import net.masterthought.cucumber.*;
public class ReportHelp {
public static void generateCucumberReport() {
File reportOutputDirectory = new File("target");
ArrayList<String> jsonFiles = new ArrayList<String>();
jsonFiles.add("target/cucumber.json");
String projectName = "Deck of Cards API";
Configuration configuration = new Configuration(reportOutputDirectory, projectName);
configuration.addClassifications("Platform", System.getProperty("os.name"));
List<String> classificationFiles = new ArrayList<String>();
classificationFiles.add("src/test/Config/config.properties");
configuration.addClassificationFiles(classificationFiles);
ReportBuilder reportBuilder = new ReportBuilder(jsonFiles, configuration);
reportBuilder.generateReports();
}
}Utilities File******************package ReusableFiles;
import java.io.IOException;
import java.util.Properties;
import java.io.FileInputStream;
public class Utilities {
static Properties prop;
static FileInputStream input = null;
/************
* Reading values from Properties file
*
* @param KeyName
* @return KeyValue
* @throws IOException
*/
public static String ReadPropertiesFile(String KeyName) throws IOException {
prop=new Properties();
String KeyValue = null;
input = new FileInputStream("src/test/Config/myConfig.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
KeyValue = prop.getProperty(KeyName);
return KeyValue;
}
}config.properties File******************ToolUsed=RestAssured
baseUrl=http://deckofcardsapi.com/
myConfig.properties File******************NewDeckCards=https://deckofcardsapi.com/api/deck/new/
ShuffleCards=https://deckofcardsapi.com/api/deck/new/shuffle/
No comments:
Post a Comment