Commit 7ad5413e authored by pfarago's avatar pfarago

add all files for cucumber assignment

parents
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>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</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>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13</version>
<scope>compile</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
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.*;
import org.openqa.selenium.chrome.ChromeDriver;
public class Amazon_search_steps
{
private WebDriver driver;
@Before
public void setUp()
{
System.setProperty("webdriver.chrome.driver", "/usr/local/bin/ChromeDriver");
driver = new ChromeDriver();
}
@After
public void tearDown(Scenario scenario)
{
if(scenario.isFailed())
{
final byte[] screenshot = ((TakesScreenshot)driver).getScreenshotAs(OutputType.BYTES);
scenario.attach(screenshot, "image/png", "amazon");
}
closeBrowser();
}
@Given("^I navigated to Google$")
public void i_navigated_to_google() throws Throwable
{
driver.get("http://www.google.com");
}
@When("^I searched for Amazon$")
public void i_searched_for_amazon()
{
WebElement searchBar = driver.findElement(By.name("q"));
searchBar.sendKeys("Amazon");
searchBar.submit();
}
@Then("the result should show for Amazon")
public void the_result_should_show_for_amazon()
{
Assert.assertTrue(driver.getTitle().contains("Amazon"));
}
void closeBrowser()
{
driver.quit();
}
}
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
{
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
{
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
{
assertEquals(arg1, response.getStatusCode());
}
@Then("^the response has the text$")
public void the_response_has_the_text(DataTable data) throws Throwable
{
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().contains(text));
}
}
}
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: 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. |
\ No newline at end of file
@wip
Feature: Navigate to Google website
As a user
I want to navigate to the Google website
So that I can search for Amazon
Scenario: Search for Amazon
Given I navigated to Google
When I searched for Amazon
Then the result should show for Amazon
\ No newline at end of file
This diff is collapsed.
[
{
"line": 2,
"elements": [
{
"start_timestamp": "2022-02-24T00:09:40.936Z",
"before": [
{
"result": {
"duration": 2208000000,
"status": "passed"
},
"match": {
"location": "Amazon_search_steps.setUp()"
}
}
],
"line": 4,
"name": "User initiates a request to get facts about cats",
"description": "",
"id": "test-cat-facts-api;user-initiates-a-request-to-get-facts-about-cats",
"after": [
{
"result": {
"duration": 100000000,
"status": "passed"
},
"match": {
"location": "Amazon_search_steps.tearDown(io.cucumber.java.Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 1000000,
"status": "passed"
},
"line": 5,
"name": "the client makes a call to the hero ku",
"match": {
"location": "CatFactsSteps.the_client_makes_a_call_to_the_hero_ku()"
},
"keyword": "Given "
},
{
"result": {
"duration": 1475000000,
"status": "passed"
},
"line": 6,
"name": "the user calls the api for facts",
"match": {
"location": "CatFactsSteps.the_user_calls_the_api_with_facts()"
},
"keyword": "When "
},
{
"result": {
"duration": 2000000,
"status": "passed"
},
"line": 7,
"name": "the client receives status of 200",
"match": {
"arguments": [
{
"val": "200",
"offset": 30
}
],
"location": "CatFactsSteps.the_client_receives_status_of(int)"
},
"keyword": "Then "
},
{
"result": {
"duration": 17000000,
"status": "passed"
},
"line": 8,
"name": "the response has the text",
"match": {
"location": "CatFactsSteps.the_response_has_the_text(io.cucumber.datatable.DataTable)"
},
"rows": [
{
"cells": [
"text"
]
},
{
"cells": [
"Cats make more than 100 different sounds whereas dogs make around 10."
]
},
{
"cells": [
"Owning a cat can reduce the risk of stroke and heart attack by a third."
]
}
],
"keyword": "And "
}
],
"tags": [
{
"name": "@wip"
}
]
}
],
"name": "Test Cat Facts API",
"description": "",
"id": "test-cat-facts-api",
"keyword": "Feature",
"uri": "classpath:featureFiles/cat_facts.feature",
"tags": [
{
"name": "@wip",
"type": "Tag",
"location": {
"line": 1,
"column": 1
}
}
]
},
{
"line": 2,
"elements": [
{
"start_timestamp": "2022-02-24T00:09:44.821Z",
"before": [
{
"result": {
"duration": 1324000000,
"status": "passed"
},
"match": {
"location": "Amazon_search_steps.setUp()"
}
}
],
"line": 8,
"name": "Search for Amazon",
"description": "",
"id": "navigate-to-google-website;search-for-amazon",
"after": [
{
"result": {
"duration": 138000000,
"status": "passed"
},
"match": {
"location": "Amazon_search_steps.tearDown(io.cucumber.java.Scenario)"
}
}
],
"type": "scenario",
"keyword": "Scenario",
"steps": [
{
"result": {
"duration": 1830000000,
"status": "passed"
},
"line": 9,
"name": "I navigated to Google",
"match": {
"location": "Amazon_search_steps.i_navigated_to_google()"
},
"keyword": "Given "
},
{
"result": {
"duration": 3709000000,
"status": "passed"
},
"line": 10,
"name": "I searched for Amazon",
"match": {
"location": "Amazon_search_steps.i_searched_for_amazon()"
},
"keyword": "When "
},
{
"result": {
"duration": 7000000,
"status": "passed"
},
"line": 11,
"name": "the result should show for Amazon",
"match": {
"location": "Amazon_search_steps.the_result_should_show_for_amazon()"
},
"keyword": "Then "
}
],
"tags": [
{
"name": "@wip"
}
]
}
],
"name": "Navigate to Google website",
"description": " As a user\n I want to navigate to the Google website\n So that I can search for Amazon",
"id": "navigate-to-google-website",
"keyword": "Feature",
"uri": "classpath:featureFiles/search_for_amazon.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="2" time="11.068">
<testcase classname="Test Cat Facts API" name="User initiates a request to get facts about cats" time="3.865">
<system-out><![CDATA[Given the client makes a call to the hero ku................................passed
When the user calls the api for facts.......................................passed
Then the client receives status of 200......................................passed
And the response has the text...............................................passed
]]></system-out>
</testcase>
<testcase classname="Navigate to Google website" name="Search for Amazon" time="7.014">
<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: 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. |
\ No newline at end of file
@wip
Feature: Navigate to Google website
As a user
I want to navigate to the Google website
So that I can search for Amazon
Scenario: Search for Amazon
Given I navigated to Google
When I searched for Amazon
Then the result should show for Amazon
\ No newline at end of file
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