Skip to content

Commit

Permalink
βœ… : convert SeleniumIT to Cucumber tests
Browse files Browse the repository at this point in the history
  • Loading branch information
juwit committed Sep 14, 2020
1 parent 46c61df commit 469313f
Show file tree
Hide file tree
Showing 13 changed files with 208 additions and 170 deletions.
26 changes: 26 additions & 0 deletions src/test/features/modules.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Basic Navigation

Background:
Given I go on the Gaia login page
# And Percy takes a snapshot named 'Login Page'
And I login with user 'admin' and password 'admin123'

Scenario: View Dashboard
When I arrive on the Dashboard page
Then Percy takes a snapshot named 'Dashboard'

Scenario: View modules
When I go on the modules page
Then Percy takes a snapshot named 'Modules'

Scenario: View module details
When I go on the module 'e01f9925-a559-45a2-8a55-f93dc434c676' page
Then Percy takes a snapshot named 'Module Details'

Scenario: View stack details
When I go on the stack 'de28a01f-257a-448d-8e1b-00e4e3a41db2' page
Then Percy takes a snapshot named 'Stack Details'

Scenario: View job details
When I go on the job '5e856dc7-6bed-465f-abf1-02980206ab2a' for stack 'de28a01f-257a-448d-8e1b-00e4e3a41db2' page
Then Percy takes a snapshot named 'Job Details'
43 changes: 43 additions & 0 deletions src/test/java/io/gaia_app/e2e/CucumberContextConfiguration.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.gaia_app.e2e;

import io.cucumber.java.After;
import io.cucumber.java.Before;
import io.gaia_app.e2e.stepDefs.StepDefs;
import io.gaia_app.test.SharedMongoContainerTest;
import org.openqa.selenium.Dimension;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.springframework.boot.test.context.SpringBootTest;

import java.util.concurrent.TimeUnit;

@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class CucumberContextConfiguration extends SharedMongoContainerTest {

@Before
public void setup_cucumber_spring_context() {
FirefoxOptions options = new FirefoxOptions();
options.addArguments("-headless");

FirefoxDriver firefoxDriver = new FirefoxDriver(options);
firefoxDriver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
firefoxDriver.manage().window().setSize(new Dimension(1280,800));

StepDefs.driver = firefoxDriver;

mongo.emptyDatabase();
mongo.runScript("src/test/resources/db/00_team.js");
mongo.runScript("src/test/resources/db/10_user.js");
mongo.runScript("src/test/resources/db/20_module.js");
mongo.runScript("src/test/resources/db/30_stack.js");
mongo.runScript("src/test/resources/db/40_job.js");
mongo.runScript("src/test/resources/db/50_step.js");
mongo.runScript("src/test/resources/db/60_terraformState.js");
}

@After
public void tearDown(){
StepDefs.driver.close();
}

}
13 changes: 13 additions & 0 deletions src/test/java/io/gaia_app/e2e/CucumberIT.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.gaia_app.e2e;

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.jupiter.api.Tag;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(plugin = "pretty", features = "src/test/features")
@Tag("e2e")
public class CucumberIT {

}
162 changes: 0 additions & 162 deletions src/test/java/io/gaia_app/e2e/SeleniumIT.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package io.gaia_app.e2e
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.FindBy
import org.openqa.selenium.support.ui.ExpectedCondition
import org.openqa.selenium.support.ui.ExpectedConditions
import org.openqa.selenium.support.ui.WebDriverWait

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.gaia_app.e2e
package io.gaia_app.e2e.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.gaia_app.e2e
package io.gaia_app.e2e.pages

import org.junit.jupiter.api.Assertions.assertEquals
import org.openqa.selenium.By
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.gaia_app.e2e
package io.gaia_app.e2e.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.gaia_app.e2e
package io.gaia_app.e2e.pages

import org.openqa.selenium.By
import org.openqa.selenium.WebDriver
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.gaia_app.e2e
package io.gaia_app.e2e.pages

import org.openqa.selenium.WebDriver
import org.openqa.selenium.WebElement
Expand Down
91 changes: 91 additions & 0 deletions src/test/java/io/gaia_app/e2e/stepDefs/ModuleStepDefs.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package io.gaia_app.e2e.stepDefs;

import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import io.gaia_app.e2e.pages.*;
import org.openqa.selenium.By;
import org.openqa.selenium.support.PageFactory;
import org.openqa.selenium.support.pagefactory.AjaxElementLocatorFactory;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;

public class ModuleStepDefs extends StepDefs {

@Given("I go on the Gaia login page")
public void i_go_on_the_gaia_login_page() {
driver.get(baseUrl());

var page = new LoginPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
}

@Given("I login with user {string} and password {string}")
public void i_login_onto_Gaia_with_user_and_password(String login, String password) {
driver.get(baseUrl());

// print html here !
System.out.println(driver.findElement(By.tagName("body")).getAttribute("outerHTML"));

var page = new LoginPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

page.login(login, password);
}

@Then("I arrive on the Dashboard page")
public void i_arrive_on_the_dashboard_page() {
var page = new DashboardPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
page.waitForPageLoaded();

assertEquals(3, page.modulesCount());
assertEquals(1, page.stacksCount());
assertEquals(0, page.stacksToUpdateCount());
}

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

var page = new ModulesPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);
page.waitForPageLoaded();

assertEquals(3, page.modulesCount());
}

@When("I go on the module {string} page")
public void iGoOnTheModulePage(String moduleId) {
driver.get(baseUrl()+"/modules/" + moduleId);

var page = new ModulePage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

assertThat(page.moduleName()).isEqualTo("terraform-docker-mongo");
assertThat(page.moduleDescription()).contains("A sample terraform");
assertThat(page.terraformImageTag()).isEqualTo("0.11.14");
}

@When("I go on the stack {string} page")
public void iGoOnTheStackPage(String stackId) {
driver.get(baseUrl()+"/stacks/"+stackId+"/edit");

var page = new StackPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

assertThat(page.stackName()).isEqualTo("local-mongo");
}

@When("I go on the job {string} for stack {string} page")
public void iGoOnTheJobForStackPage(String jobId, String stackId) {
driver.get(baseUrl()+"/stacks/"+stackId+"/jobs/"+jobId);

var page = new JobPage(driver);
PageFactory.initElements(new AjaxElementLocatorFactory(driver, 10), page);

assertThat(page.jobDetailTitle()).isEqualTo("Job " + jobId);
}

}
12 changes: 12 additions & 0 deletions src/test/java/io/gaia_app/e2e/stepDefs/PercyStepDef.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.gaia_app.e2e.stepDefs;

import io.cucumber.java.en.Then;
import io.percy.selenium.Percy;

public class PercyStepDef extends StepDefs{

@Then("Percy takes a snapshot named {string}")
public void percyTakesASnapshotNamedDashboardPage(String snapshotName) {
new Percy(driver).snapshot(snapshotName);
}
}

0 comments on commit 469313f

Please sign in to comment.