Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>2.3.7</version>
<version>4.0.12</version>
</dependency>
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>2.3.7</version>
<version>4.0.12</version>
</dependency>

</dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import org.junit.Before;
import org.junit.BeforeClass;
import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.ExpectedConditions;

Expand All @@ -15,18 +17,22 @@
public abstract class WithWebdriverSupport {

@FindBy
private final String SELENIUM_EASY_DEMO_SITE = "https://www.seleniumeasy.com/test/";
private final String SELENIUM_EASY_DEMO_SITE = "https://demo.seleniumeasy.com/";

protected WebDriver driver;

@BeforeClass
static public void setupWebDriver() {
WebDriverManager.chromedriver().setup();
// WebDriverManager.chromedriver().setup();
WebDriverManager.firefoxdriver().setup();

}

@Before
public void openBrowser() {
driver = new ChromeDriver();
//driver = new ChromeDriver();
driver = new FirefoxDriver();
//driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}

@After
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import serenitylabs.tutorials.seleniumeasy.selenium.WithWebdriverSupport;

import java.time.Duration;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.assertj.core.api.Assertions.assertThat;
import static org.openqa.grid.common.SeleniumProtocol.WebDriver;
import static org.openqa.selenium.support.ui.ExpectedConditions.*;
import static org.openqa.selenium.support.ui.ExpectedConditions.not;
import static org.openqa.selenium.support.ui.ExpectedConditions.textToBePresentInElementLocated;

Expand All @@ -26,9 +29,18 @@ public void openPage() {

@Test
public void enteringASingleInputForm() {
// TODO: Enter a name and comment, and wait until the success message appears

String resultMessage = null;
driver.findElement(By.id("title")).sendKeys("Harry");
driver.findElement(By.id("description")).sendKeys("The comment is here");
driver.findElement(By.id("btn-submit")).click();
//Creating an instance of WebDriverWait specifying the maximum time you want to wait:
WebDriverWait wait = new WebDriverWait(driver, 5);

String expectedText = "Form submited Successfully!";
wait.until(textToBePresentInElementLocated(By.id("submit-control"), expectedText));
//OR
//wait.until(not(textToBePresentInElementLocated(By.id("submit-control"), "Ajax Request is Processing!")));

String resultMessage = driver.findElement(By.id("submit-control")).getText();
assertThat(resultMessage).contains("Form submited Successfully!");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@ public void openPage() {

@Test
public void singleCheckbox() {
// TODO: Click on the first checkbox and check that a success message is displayed

String result = ""; // TODO: Fix me
driver.findElement(By.id("isAgeSelected")).click();
String result = driver.findElement(By.id("txtAge")).getText();
assertThat(result).isEqualTo("Success - Check box is checked");
}

@Test
public void multipleCheckboxes() {
// TODO: Click on all the checkboxes and ensure that the button text is "Uncheck All"

String result = ""; // TODO: Fix me
driver.findElements(By.cssSelector(".cb1-element")).forEach(WebElement::click);
String result = driver.findElement(By.id("check1")).getAttribute("value");
assertThat(result).isEqualTo("Uncheck All");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,26 @@ public void openPage() {
@Test
public void simpleSelectList() {
// TODO: Select a day and check that the result is correctly displayed
new Select(driver.findElement(By.id("select-demo"))).selectByVisibleText("Monday");

String selectedValue = "";
assertThat(selectedValue).isEqualTo("Day selected :- Monday");
assertThat(driver.findElement(By.cssSelector(".selected-value")).getText()).isEqualTo("Day selected :- Monday");
}

@Test
public void multiSelect() {
// TODO: Select California","New York",and "Washington" in the dropdown

List<String> selectedOptions = null;
new Select(driver.findElement(By.id("multi-select"))).selectByVisibleText("California");
new Select(driver.findElement(By.id("multi-select"))).selectByVisibleText("New York");
new Select(driver.findElement(By.id("multi-select"))).selectByVisibleText("Washington");


List<String> selectedOptions = new Select(driver.findElement(By.id("multi-select"))).
getAllSelectedOptions().stream()
.map(element -> element.getAttribute("value"))
.collect(Collectors.toList());

assertThat(selectedOptions).containsExactly("California","New York","Washington");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import org.openqa.selenium.By;
import serenitylabs.tutorials.seleniumeasy.selenium.WithWebdriverSupport;

import static io.vavr.API.$;
import static org.assertj.core.api.Assertions.assertThat;

public class TestingInputForms extends WithWebdriverSupport {
Expand All @@ -17,19 +18,23 @@ public void openPage() {

@Test
public void enteringASingleInputForm() {
// TODO: Enter a message in the Single Input Field and check that it is shown
// DONE: Enter a message in the Single Input Field and check that it is shown -
driver.findElement(By.id("user-message")).sendKeys("Selenium easy");
driver.findElement(By.cssSelector("#get-input button")).click();
String displayedText = driver.findElement(By.id("display")).getText();

String displayedText = ""; // TODO: Fix me

assertThat(displayedText).isEqualTo("Hello world");
assertThat(displayedText).isEqualTo("Selenium easy");
}

@Test
public void enterTwoValues() {
// TODO: Enter a number in each input field and verify the calculated total
// DONE: Enter a number in each input field and verify the calculated total
driver.findElement(By.id("value1")).sendKeys("3");
driver.findElement(By.id("value2")).sendKeys("2");
driver.findElement(By.cssSelector("#gettotal button")).click();

String displayedValue = ""; // TODO: Fix me
String displayedValue = driver.findElement(By.id("displayvalue")).getText();

assertThat(displayedValue).isEqualTo("3");
assertThat(displayedValue).isEqualTo("5");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.Select;
import serenitylabs.tutorials.seleniumeasy.selenium.WithWebdriverSupport;

Expand All @@ -21,17 +22,31 @@ public void openPage() {
@Test
public void selectingInADropdownWithASearchBox() {
// TODO: Click on the dropdown and enter 'Ne', then select 'New Zealand' in the dropdown
//the locator is not unique, needs to be researched

String selectedCountry = "";
//driver.findElement(By.id("select2-country-container")).click();
// driver.findElement(By.cssSelector("span.select2-selection.select2-selection--single")).click();
driver.findElement(By.xpath("//span[@aria-labelledby='select2-country-container']")).click();
driver.findElement(By.cssSelector(".select2-search__field")).sendKeys("Ne");
driver.findElement(By.xpath("//ul[@class='select2-results__options']//li[contains(.,'New Zealand')]")).click();

assertThat(selectedCountry).isEqualTo("New Zealand");
// String selectedCountry = driver.findElement(By.id("select2-country-container")).getText();
// assertThat(selectedCountry).isEqualTo("New Zealand");
}

@Test
public void selectingInAMultiValueDropdownWithASearchBox() {
// TODO Enter 'Ca' and select California, then enter 'Ari' and select Arizona. Check that both appear as selected in the list
// DONE Enter 'Ca' and select California, then enter 'Ari' and select Arizona. Check that both appear as selected in the list
driver.findElement(By.cssSelector(".select2-selection--multiple")).click();
driver.findElement(By.cssSelector(".select2-search__field")).sendKeys("Ca");
driver.findElement(By.xpath("//li[.='California']")).click();

List<String> selectedValues = null;
driver.findElement(By.cssSelector(".select2-selection--multiple")).click();
driver.findElement(By.cssSelector(".select2-search__field")).sendKeys("Ari");
driver.findElement(By.xpath("//li[.='Arizona']")).click();

List<String> selectedValues = driver.findElements(By.cssSelector(".select2-selection__choice"))
.stream().map(value -> value.getAttribute("title")).collect(Collectors.toList());

assertThat(selectedValues).containsExactlyInAnyOrder("California","Arizona");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,15 @@ public class TestingRadioButtons extends WithWebdriverSupport {
public void openPage() {
open("basic-radiobutton-demo.html");
}

@Test
public void singleRadio() {
// TODO: Click on the second radio and click on 'Get Checked Value' - check that the correct text is displayed.
// DONE: Click on the second radio and click on 'Get Checked Value' - check that the correct text is displayed.
driver.findElement(By.cssSelector("input[value='Female']")).click();
//OR by xpath
//driver.findElement(By.xpath("//input[@value='Female']")).click();
driver.findElement(By.id("buttoncheck")).click();

String checkedValue = "";
String checkedValue = driver.findElement(By.cssSelector(".radiobutton")).getText();
assertThat(checkedValue).isEqualTo("Radio button 'Female' is checked");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

public class WithSerenity extends UIInteractionSteps {

private final String SELENIUM_EASY_DEMO_SITE = "https://www.seleniumeasy.com/test/";
private final String SELENIUM_EASY_DEMO_SITE = "https://demo.seleniumeasy.com/";

protected void openDemoPage(String page) {
this.openUrl(SELENIUM_EASY_DEMO_SITE + page);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,14 @@ public void openPage() {
@Test
public void singleRadio() {
// TODO: Click on the second radio and click on 'Get Checked Value' - check that the correct text is displayed.
$("input[value='Female']").click();
$("#buttoncheck").click();

String checkedValue = "";
assertThat(checkedValue).isEqualTo("Radio button 'Female' is checked");
// $("css:input[value='Female']").click();
// $("#buttoncheck").click();

// String checkedValue = $(".radiobutton").getText();
// assertThat(checkedValue).isEqualTo("Radio button 'Female' is checked");
}

}
}