Commit 82885960 authored by Sowmya Vagicherla's avatar Sowmya Vagicherla

Adding BDD-Cucumber assignment

parent bddb7310
File added
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
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>hellocucumber</groupId>
<artifactId>hellocucumber</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<cucumber.version>6.8.1</cucumber.version>
<junit.version>4.13</junit.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<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>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.3.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.14.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<encoding>UTF-8</encoding>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
File added
package hellocucumber;
import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.cucumber.java.Scenario;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.junit.Assert;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.PageFactory;
public class AmazonSearchSteps {
private WebDriver driver;
@Before
public void setUp() {
System.setProperty("webdriver.chrome.driver", "/Users/svagicherla/Downloads/chromedriver");
driver = new ChromeDriver();
}
@After
public void tearDown(Scenario scenario) {
closeBrowser();
}
@Given("I navigated to Google")
public void i_navigated_to_google() {
// Write code here that turns the phrase above into concrete actions
driver.get("http://www.google.com");
// throw new io.cucumber.java.PendingException();
}
@When("I searched for Amazon")
public void i_searched_for_amazon() {
// Write code here that turns the phrase above into concrete actions
WebElement searchTextBox = driver.findElement(By.name("q"));
searchTextBox.sendKeys("Amazon");
searchTextBox.submit();
}
@Then("^the result should show for Amazon$")
public void the_result_should_show_for_Amazon() throws Throwable {
Assert.assertTrue(driver.getTitle().contains("Amazon"));
}
void closeBrowser() {
driver.quit();
}
}
package hellocucumber;
import io.cucumber.datatable.DataTable;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.restassured.RestAssured;
import io.restassured.response.Response;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
public class CatFactsSteps {
private String url;
private Response response;
@Given("^the client makes a call to the hero ku$")
public void the_client_makes_a_call_to_the_hero_ku() throws Throwable {
// Write code here that turns the phrase above into concrete actions
url="https://cat-fact.herokuapp.com";
}
@When("^the user calls the api for facts$")
public void the_user_calls_the_api_with_facts() throws Throwable {
// Write code here that turns the phrase above into concrete actions
//response = restTemplate.getForEntity(new URI(url+"/facts"), String.class);
response = RestAssured.given().baseUri(url).basePath("/facts").get().then().log().status().extract().response();
}
@Then("^the client receives status of (\\d+)$")
public void the_client_receives_status_of(int arg1) throws Throwable {
// Write code here that turns the phrase above into concrete actions
assertEquals(arg1, response.getStatusCode());
}
@Then("^the response has the text$")
public void the_response_has_the_text(DataTable data) throws Throwable {
// Write code here that turns the phrase above into concrete actions
// For automatic transformation, change DataTable to one of
// List<YourType>, List<List<E>>, List<Map<K,V>> or Map<K,V>.
// E,K,V must be a scalar (String, Integer, Date, enum etc)
List<Map<String, String>> rows = data.asMaps(String.class,String.class);
for (Map<String, String> row : rows) {
String text = row.get("text");
assertTrue(response.getBody().asString().indexOf(text)>0);
}
}
}
package hellocucumber;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@CucumberOptions(plugin = {"pretty",
"html:target/surefire-reports/html",
"json:target/surefire-reports/json/report.json",
"junit:target/surefire-reports/junit/report.xml"},
monochrome = true,
tags = "@wip")
public class RunCucumberTest {
}
@wip
Feature: Google
  As a user
  I want to navigate to Google
  So that I can search for Amazon
Scenario: Search Amazon
Given I navigated to Google
When I searched for Amazon
Then the result should show for Amazon
\ No newline at end of file
@hip
Feature: Test Cat Facts API
Scenario: User initiates a request to get facts about cats
Given the client makes a call to the hero ku
When the user calls the api for facts
Then the client receives status of 200
And the response has the text
| text |
| Cats make more than 100 different sounds whereas dogs make around 10. |
| Owning a cat can reduce the risk of stroke and heart attack by a third. |
#Generated by Maven
#Wed Feb 23 15:39:28 PST 2022
groupId=hellocucumber
artifactId=hellocucumber
version=1.0.0-SNAPSHOT
AmazonSearchSteps.class
HomePage.class
RunCucumberTest.class
CatFactsSteps.class
/Users/svagicherla/Downloads/cucumber-assignment/src/test/java/RunCucumberTest.java
/Users/svagicherla/Downloads/cucumber-assignment/src/test/java/CatFactsSteps.java
/Users/svagicherla/Downloads/cucumber-assignment/src/test/java/HomePage.java
/Users/svagicherla/Downloads/cucumber-assignment/src/test/java/AmazonSearchSteps.java
-------------------------------------------------------------------------------
Test set: RunCucumberTest
-------------------------------------------------------------------------------
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.623 sec
<?xml version="1.0" encoding="UTF-8" ?>
<testsuite tests="0" failures="0" name="RunCucumberTest" time="0" errors="0" skipped="0">
<properties>
<property name="java.runtime.name" value="OpenJDK Runtime Environment"/>
<property name="java.vm.version" value="17.0.2+0"/>
<property name="sun.boot.library.path" value="/usr/local/Cellar/openjdk/17.0.2/libexec/openjdk.jdk/Contents/Home/lib"/>
<property name="maven.multiModuleProjectDirectory" value="/Users/svagicherla/Downloads/cucumber-assignment"/>
<property name="java.vm.vendor" value="Homebrew"/>
<property name="java.vendor.url" value="https://github.com/Homebrew/homebrew-core/issues"/>
<property name="guice.disable.misplaced.annotation.check" value="true"/>
<property name="path.separator" value=":"/>
<property name="java.vm.name" value="OpenJDK 64-Bit Server VM"/>
<property name="user.country" value="US"/>
<property name="sun.java.launcher" value="SUN_STANDARD"/>
<property name="java.vm.specification.name" value="Java Virtual Machine Specification"/>
<property name="user.dir" value="/Users/svagicherla/Downloads/cucumber-assignment"/>
<property name="java.vm.compressedOopsMode" value="Zero based"/>
<property name="java.runtime.version" value="17.0.2+0"/>
<property name="os.arch" value="x86_64"/>
<property name="java.io.tmpdir" value="/var/folders/x9/fccd71z97fv89m4d0kn9zby00000gp/T/"/>
<property name="line.separator" value="
"/>
<property name="java.vm.specification.vendor" value="Oracle Corporation"/>
<property name="os.name" value="Mac OS X"/>
<property name="classworlds.conf" value="/usr/local/Cellar/maven/3.8.4/libexec/bin/m2.conf"/>
<property name="sun.jnu.encoding" value="UTF-8"/>
<property name="java.library.path" value="/Users/svagicherla/Library/Java/Extensions:/Library/Java/Extensions:/Network/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:."/>
<property name="maven.conf" value="/usr/local/Cellar/maven/3.8.4/libexec/conf"/>
<property name="jdk.debug" value="release"/>
<property name="java.class.version" value="61.0"/>
<property name="java.specification.name" value="Java Platform API Specification"/>
<property name="sun.management.compiler" value="HotSpot 64-Bit Tiered Compilers"/>
<property name="os.version" value="10.15.7"/>
<property name="library.jansi.path" value="/usr/local/Cellar/maven/3.8.4/libexec/lib/jansi-native"/>
<property name="http.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="user.home" value="/Users/svagicherla"/>
<property name="user.timezone" value="America/Los_Angeles"/>
<property name="file.encoding" value="UTF-8"/>
<property name="java.specification.version" value="17"/>
<property name="user.name" value="svagicherla"/>
<property name="java.class.path" value="/usr/local/Cellar/maven/3.8.4/libexec/boot/plexus-classworlds-2.6.0.jar"/>
<property name="java.vm.specification.version" value="17"/>
<property name="sun.arch.data.model" value="64"/>
<property name="sun.java.command" value="org.codehaus.plexus.classworlds.launcher.Launcher clean install"/>
<property name="java.home" value="/usr/local/Cellar/openjdk/17.0.2/libexec/openjdk.jdk/Contents/Home"/>
<property name="user.language" value="en"/>
<property name="java.specification.vendor" value="Oracle Corporation"/>
<property name="java.vm.info" value="mixed mode, sharing"/>
<property name="java.version" value="17.0.2"/>
<property name="native.encoding" value="UTF-8"/>
<property name="java.vendor" value="Homebrew"/>
<property name="sun.stderr.encoding" value="UTF-8"/>
<property name="maven.home" value="/usr/local/Cellar/maven/3.8.4/libexec"/>
<property name="file.separator" value="/"/>
<property name="java.version.date" value="2022-01-18"/>
<property name="java.vendor.url.bug" value="https://github.com/Homebrew/homebrew-core/issues"/>
<property name="sun.io.unicode.encoding" value="UnicodeBig"/>
<property name="sun.cpu.endian" value="little"/>
<property name="java.vendor.version" value="Homebrew"/>
<property name="sun.stdout.encoding" value="UTF-8"/>
<property name="socksNonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
<property name="ftp.nonProxyHosts" value="local|*.local|169.254/16|*.169.254/16"/>
</properties>
</testsuite>
\ No newline at end of file
This diff is collapsed.
[
{
"line": 2,
"elements": [
{
"start_timestamp": "2022-02-24T00:57:00.501Z",
"before": [
{
"result": {
"duration": 2090000000,
"status": "passed"
},
"match": {
"location": "hellocucumber.AmazonSearchSteps.setUp()"
}
}
],
"line": 7,
"name": "Search Amazon",
"description": "",
"id": "google;search-amazon",
"after": [
{
"result": {
"duration": 147000000,
"status": "passed"
},
"match": {
"location": "hellocucumber.AmazonSearchSteps.tearDown(io.cucumber.java.Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 1046000000,
"status": "passed"
},
"line": 8,
"name": "I navigated to Google",
"match": {
"location": "hellocucumber.AmazonSearchSteps.i_navigated_to_google()"
},
"keyword": "Given "
},
{
"result": {
"duration": 1576000000,
"status": "passed"
},
"line": 9,
"name": "I searched for Amazon",
"match": {
"location": "hellocucumber.AmazonSearchSteps.i_searched_for_amazon()"
},
"keyword": "When "
},
{
"result": {
"duration": 9000000,
"status": "passed"
},
"line": 10,
"name": "the result should show for Amazon",
"match": {
"location": "hellocucumber.AmazonSearchSteps.the_result_should_show_for_Amazon()"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
}
],
"name": "Google",
"description": "   As a user\n   I want to navigate to Google\n   So that I can search for Amazon",
"id": "google",
"keyword": "Feature",
"uri": "classpath:hellocucumber/amazon_search.feature",
"tags": [
{
"name": "@wip",
"type": "Tag",
"location": {
"line": 1,
"column": 1
}
}
]
}
]
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<testsuite errors="0" failures="0" name="io.cucumber.core.plugin.JUnitFormatter" skipped="0" tests="1" time="5.109">
<testcase classname="Google" name="Search Amazon" time="4.932">
<system-out><![CDATA[Given I navigated to Google.................................................passed
When I searched for Amazon..................................................passed
Then the result should show for Amazon......................................passed
]]></system-out>
</testcase>
</testsuite>
@wip
Feature: Google
  As a user
  I want to navigate to Google
  So that I can search for Amazon
Scenario: Search Amazon
Given I navigated to Google
When I searched for Amazon
Then the result should show for Amazon
\ No newline at end of file
@hip
Feature: Test Cat Facts API
Scenario: User initiates a request to get facts about cats
Given the client makes a call to the hero ku
When the user calls the api for facts
Then the client receives status of 200
And the response has the text
| text |
| Cats make more than 100 different sounds whereas dogs make around 10. |
| Owning a cat can reduce the risk of stroke and heart attack by a third. |
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment