Skip to content

Commit ad68f2f

Browse files
committed
Initial commit
1 parent 26e0001 commit ad68f2f

File tree

11 files changed

+218
-0
lines changed

11 files changed

+218
-0
lines changed

.idea/.gitignore

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/compiler.xml

+13
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/jarRepositories.xml

+20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pom.xml

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>org.example</groupId>
8+
<artifactId>TestCodeTask</artifactId>
9+
<version>1.0-SNAPSHOT</version>
10+
11+
<properties>
12+
<maven.compiler.source>1.8</maven.compiler.source>
13+
<maven.compiler.target>1.8</maven.compiler.target>
14+
<cucumber.version>7.18.0</cucumber.version>
15+
</properties>
16+
17+
<dependencies>
18+
<dependency>
19+
<groupId>io.cucumber</groupId>
20+
<artifactId>cucumber-java</artifactId>
21+
<version>${cucumber.version}</version>
22+
<scope>test</scope>
23+
</dependency>
24+
<dependency>
25+
<groupId>io.cucumber</groupId>
26+
<artifactId>cucumber-testng</artifactId>
27+
<version>${cucumber.version}</version>
28+
<scope>test</scope>
29+
</dependency>
30+
<dependency>
31+
<groupId>io.cucumber</groupId>
32+
<artifactId>cucumber-core</artifactId>
33+
<version>${cucumber.version}</version>
34+
<scope>test</scope>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.testng</groupId>
38+
<artifactId>testng</artifactId>
39+
<version>7.10.2</version>
40+
<scope>test</scope>
41+
</dependency>
42+
<dependency>
43+
<groupId>org.seleniumhq.selenium</groupId>
44+
<artifactId>selenium-java</artifactId>
45+
<version>4.22.0</version>
46+
</dependency>
47+
<dependency>
48+
<groupId>org.assertj</groupId>
49+
<artifactId>assertj-core</artifactId>
50+
<version>3.22.0</version>
51+
<scope>test</scope>
52+
</dependency>
53+
</dependencies>
54+
55+
</project>
+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package stepdefs;
2+
3+
import io.cucumber.java.After;
4+
import io.cucumber.java.Before;
5+
import io.cucumber.java.en.Given;
6+
import io.cucumber.java.en.Then;
7+
import io.cucumber.java.en.When;
8+
import org.openqa.selenium.By;
9+
import org.openqa.selenium.Keys;
10+
import org.openqa.selenium.WebDriver;
11+
import org.openqa.selenium.WebElement;
12+
import org.openqa.selenium.support.ui.ExpectedConditions;
13+
import org.openqa.selenium.support.ui.WebDriverWait;
14+
15+
import java.time.Duration;
16+
import java.util.List;
17+
18+
import static org.assertj.core.api.Assertions.assertThat;
19+
20+
public class SearchStepDefs {
21+
private WebDriver driver;
22+
23+
@Before
24+
public void setup() {
25+
driver = Setup.setupAndGetDriver();
26+
}
27+
28+
@After
29+
public void teardown() {
30+
driver.quit();
31+
}
32+
33+
@Given("^I am on the Google UK homepage$")
34+
public void iAmOnTheGoogleUkHomepage() {
35+
driver.manage().window().maximize();
36+
driver.get("https://www.google.co.uk");
37+
}
38+
39+
@When("I enter a search term")
40+
public void iEnterASearchTerm() {
41+
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(15));
42+
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@id='L2AGLb2']"))).click();
43+
driver.findElement(By.xpath("//input[@title='Search']")).sendKeys("BBC news");
44+
driver.findElement(By.xpath("//input[@title='Search']")).sendKeys(Keys.ENTER);
45+
}
46+
47+
@Then("results relevant to the search term are returned")
48+
public void resultsRelevantToTheSearchTermAreReturned() {
49+
List<WebElement> resultHeaders = driver.findElements(By.xpath("//a/h3"));
50+
for(WebElement header : resultHeaders) {
51+
assertThat(header.getText()).as("Search results contains search term").contains("BBC");
52+
}
53+
}
54+
}

src/test/java/stepdefs/Setup.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package stepdefs;
2+
3+
import org.openqa.selenium.PageLoadStrategy;
4+
import org.openqa.selenium.WebDriver;
5+
import org.openqa.selenium.chrome.ChromeDriver;
6+
import org.openqa.selenium.chrome.ChromeOptions;
7+
import org.openqa.selenium.logging.LogType;
8+
import org.openqa.selenium.logging.LoggingPreferences;
9+
import org.openqa.selenium.remote.CapabilityType;
10+
11+
import java.util.logging.Level;
12+
13+
public class Setup {
14+
15+
public static WebDriver setupAndGetDriver() {
16+
return new ChromeDriver(getCapabilities());
17+
}
18+
19+
private static ChromeOptions getCapabilities() {
20+
LoggingPreferences logPrefs = new LoggingPreferences();
21+
logPrefs.enable(LogType.BROWSER, Level.ALL);
22+
logPrefs.enable(LogType.DRIVER, Level.ALL);
23+
24+
ChromeOptions options = new ChromeOptions();
25+
26+
options.setCapability(CapabilityType.ACCEPT_INSECURE_CERTS, true);
27+
options.addArguments("--enable-automation");
28+
options.addArguments("--enable-crash-reporter");
29+
options.addArguments("--disable-extensions");
30+
options.addArguments("--disable-gpu");
31+
options.addArguments("--no-sandbox");
32+
options.setPageLoadStrategy(PageLoadStrategy.NORMAL);
33+
options.setAcceptInsecureCerts(true);
34+
return options;
35+
}
36+
}
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Search
2+
As a user
3+
I want to search the internet
4+
So that results appropriate to my interests are returned
5+
6+
@FixMe
7+
Scenario: Relevant search results are returned to the user
8+
Given I am on the Google UK homepage
9+
When I enter a search term
10+
Then results relevant to the search term are returned
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
Feature: Search
2+
As a user
3+
I want to search the internet
4+
So that results appropriate to my interests are returned
5+
6+
@FixMe
7+
Scenario: Relevant search results are returned to the user
8+
Given I am on the Google UK homepage
9+
When I enter a search term
10+
Then results relevant to the search term are returned
Binary file not shown.
1.84 KB
Binary file not shown.

0 commit comments

Comments
 (0)