Skip to content

Commit

Permalink
use DuckDuckGo instead of Google
Browse files Browse the repository at this point in the history
the html layout of search results doesn't change too often (compared to Google)
  • Loading branch information
asolntsev committed Apr 15, 2024
1 parent 01b05d6 commit b479669
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package org.selenide.examples.cucumber;

import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.openqa.selenium.By;

import static com.codeborne.selenide.CollectionCondition.sizeGreaterThanOrEqual;
import static com.codeborne.selenide.Condition.disappear;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;

import org.openqa.selenium.By;

import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class GoogleImageSearchStepDefinitions {
public class ImageSearchStepDefinitions {
@When("click {string} link")
public void chooseImagesAsSearchTarget(String linkText) {
$(byText(linkText)).click();
if ($(byText("Accept all")).isDisplayed()) {
$(byText("Accept all")).shouldBe(visible).click();
$(byText("Accept all")).should(disappear);
}
$("[data-testid=\"tab-label-images\"]")
.shouldHave(text(linkText))
.click();
}

@When("enter a keyword {string} in input field")
Expand All @@ -29,6 +24,6 @@ public void enterKeyword(String keyword) {

@Then("at least top {int} matching images should be shown")
public void topTenMatchedImagesShouldBeShown(int resultsCount) {
$$(".rg_i").shouldHave(sizeGreaterThanOrEqual(resultsCount));
$$("[data-testid=\"zci-images\"] .tile--img").shouldHave(sizeGreaterThanOrEqual(resultsCount));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
public class GoogleTest {
public class SearchTest {
}
Original file line number Diff line number Diff line change
@@ -1,32 +1,21 @@
package org.selenide.examples.cucumber;

import static com.codeborne.selenide.CollectionCondition.sizeGreaterThanOrEqual;
import static com.codeborne.selenide.Condition.disappear;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Condition.visible;
import static com.codeborne.selenide.Selectors.byText;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
import static com.codeborne.selenide.Selenide.open;
import static com.codeborne.selenide.Selenide.sleep;

import org.openqa.selenium.By;

import com.codeborne.selenide.Configuration;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;

public class GoogleSearchStepDefinitions {
@Given("an open browser with google.com")
public void openGoogleSearch() {
open("https://google.com/ncr");
sleep(500);
if ($(byText("Accept all")).isDisplayed()) {
$(byText("Accept all")).shouldBe(visible).click();
$(byText("Accept all")).should(disappear);
}
public class TextSearchStepDefinitions {
@Given("an open browser with duckduckgo.com")
public void openSearchPage() {
open("https://duckduckgo.com");
}

@When("a keyword {string} is entered in input field")
Expand All @@ -36,11 +25,11 @@ public void enterKeyword(String keyword) {

@Then("at least top {int} matches should be shown")
public void topTenMatchesShouldBeShown(int resultsCount) {
$$("#res .g").shouldHave(sizeGreaterThanOrEqual(resultsCount));
$$("[data-testid=\"result\"]").shouldHave(sizeGreaterThanOrEqual(resultsCount));
}

@Then("the first one should contain {string}")
public void theFirstOneShouldContainKeyword(String expectedText) {
$("#res .g").shouldHave(text(expectedText));
$("[data-testid=\"result\"]").shouldHave(text(expectedText));
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Feature: Image search

Scenario: user can search images by keyword

Given an open browser with duckduckgo.com
When enter a keyword "selenide" in input field
And click "Images" link
Then at least top 10 matching images should be shown
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
Feature: Google text search
Feature: Text search

Scenario: user can search any keyword

Given an open browser with google.com
Given an open browser with duckduckgo.com
When a keyword "selenide" is entered in input field
Then at least top 1 matches should be shown
Then the first one should contain "selenide.org"

Scenario: user can search any keyword in Russian

Given an open browser with google.com
Given an open browser with duckduckgo.com
When a keyword "селенид тесты" is entered in input field
Then at least top 1 matches should be shown
Then the first one should contain "selenide.org"
Then the first one should contain "Selenide"

0 comments on commit b479669

Please sign in to comment.