Skip to content

Commit

Permalink
βœ… : stabilize users page tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Dec 31, 2020
1 parent 9cd2588 commit 5fcd987
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/main/client/app/pages/users/users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

<div class="block mt-3">
<b-table
id="usersTable"
:items="users"
:fields="fields"
striped
Expand Down
1 change: 1 addition & 0 deletions src/test/features/io/gaia_app/e2e/basic_navigation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ Feature: Basic Navigation

Scenario: View users list
When I go on the users page
Then I can see 5 users
Then Percy takes a snapshot named 'Users'
29 changes: 29 additions & 0 deletions src/test/java/io/gaia_app/e2e/pages/UsersPage.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package io.gaia_app.e2e.pages

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.ExpectedConditions.titleIs
import org.openqa.selenium.support.ui.WebDriverWait

class UsersPage(private val webDriver: WebDriver) {

private lateinit var usersRows: List<WebElement>

init {
val wait = WebDriverWait(webDriver, 10)
wait.until(titleIs("Gaia - Users"))
}

fun usersCount() = usersRows.size

fun waitForPageLoaded() {
val wait = WebDriverWait(webDriver, 10)
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("usersTable")))

val usersTable = webDriver.findElement(By.id("usersTable"))
usersRows = usersTable.findElement(By.tagName("tbody")).findElements(By.tagName("tr"))
}

}
14 changes: 13 additions & 1 deletion src/test/java/io/gaia_app/e2e/stepDefs/UsersStepDefs.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
package io.gaia_app.e2e.stepDefs;

import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.gaia_app.e2e.pages.JobPage;
import io.gaia_app.e2e.pages.UsersPage;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;

import static org.assertj.core.api.Assertions.assertThat;

public class UsersStepDefs extends StepDefs {

UsersPage page;

@When("I go on the users page")
public void iGoOnTheUsersPage() {
driver.get(baseUrl()+"/users");

page = new UsersPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
page.waitForPageLoaded();
}

@Then("I can see {int} users")
public void iCanSeeUsers(int expectedUsersCount) {
assertThat(page.usersCount()).isEqualTo(expectedUsersCount);
}
}

0 comments on commit 5fcd987

Please sign in to comment.