Commit 21d47bb6 authored by Sonia's avatar Sonia

Guardo Tutorial Cucumber y Selenium.

parents
Pipeline #4914 failed with stages
in 1 second
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<annotationProcessing>
<profile name="Maven default annotation processors profile" enabled="true">
<sourceOutputDir name="target/generated-sources/annotations" />
<sourceTestOutputDir name="target/generated-test-sources/test-annotations" />
<outputRelativeToContentRoot value="true" />
<module name="Selenide_Prueba_Login" />
</profile>
</annotationProcessing>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="RemoteRepositoriesConfiguration">
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Central Repository" />
<option name="url" value="https://repo.maven.apache.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="central" />
<option name="name" value="Maven Central repository" />
<option name="url" value="https://repo1.maven.org/maven2" />
</remote-repository>
<remote-repository>
<option name="id" value="jboss.community" />
<option name="name" value="JBoss Community repository" />
<option name="url" value="https://repository.jboss.org/nexus/content/repositories/public/" />
</remote-repository>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ExternalStorageConfigurationManager" enabled="true" />
<component name="MavenProjectsManager">
<option name="originalFiles">
<list>
<option value="$PROJECT_DIR$/pom.xml" />
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_15" project-jdk-name="openjdk-15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$" vcs="Git" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />
\ No newline at end of file
<html><head><script type="text/javascript">alert(Resource id #7);</script><script type="text/javascript"> window.location.href = 'manager/Managerhomepage.php';</script></head></html>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>CucumberWithSeleniumPOM</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-java</artifactId>
<version>6.10.1</version>
<scope>com.guru99.website.tuto.test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-junit</artifactId>
<version>6.10.1</version>
<scope>com.guru99.website.tuto.test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>com.guru99.website.tuto.test</scope>
</dependency>
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>cucumber-core</artifactId>
<version>6.10.1</version>
<scope>com.guru99.website.tuto.test</scope>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-api</artifactId>
<version>3.141.59</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.21</version>
</dependency>
<dependency>
<groupId>com.codeborne</groupId>
<artifactId>selenide</artifactId>
<version>5.18.1</version>
</dependency>
</dependencies>
<properties>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
</properties>
</project>
\ No newline at end of file
package com.guru99.website.tuto.TestRunner;
import com.codeborne.selenide.WebDriverRunner;
import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
@RunWith(Cucumber.class)
@CucumberOptions(
features={"src/test/resources/MyTest.feature"},
glue={"com/guru99/website/tuto/test"},
plugin = {"pretty","html:target/cucumber-reports.html"}, monochrome = true)
public class Runner {
}
package com.guru99.website.tuto.constantes;
public class Constantes {
public static final String URL_GURU = "https://demo.guru99.com/v4";
public static final String GURU99_BANK = "Welcome To Manager's Page of Guru99 Bank";
public static final String MANGER_ID = "Manger Id : mgr123";
public static final String INVALIDE_USER = "User or Password is not valid";
public static final String EMPTY_USER = "User-ID must not be blank";
public static final String EMPTY_PASSWORD = "Password must not be blank";
}
package com.guru99.website.tuto.pages;
import com.codeborne.selenide.SelenideElement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import static com.codeborne.selenide.Selenide.$;
public class HomePages {
WebDriver driver;
public HomePages(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver,this);
}
/////////////////////////////////////////////HOMEPAGES-ELEMENTOS////////////////////////////////////////////////
public static SelenideElement getTitleWelcome(){ return $(By.cssSelector("marquee[class='heading3']")); }
public static SelenideElement getManger_Id(){ return $(By.cssSelector("td[style='color: green']")); }
}
package com.guru99.website.tuto.pages;
import com.codeborne.selenide.SelenideElement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.PageFactory;
import static com.codeborne.selenide.Selenide.$;
public class LoginPage {
WebDriver driver;
public LoginPage(WebDriver driver) {
this.driver = driver;
PageFactory.initElements(driver,this);
}
////////////////////////////////////////////LOGINPAGES-ELEMENTOS////////////////////////////////////////////////
public static SelenideElement getUser(){ return $(By.name("uid")); }
public static SelenideElement getPassword(){ return $(By.name("password")); }
public static SelenideElement btnReset(){ return $(By.name("btnReset")); }
public static SelenideElement btnLogin(){ return $(By.name("btnLogin")); }
public static SelenideElement hiddenUser(){ return $(By.id("message23")); }
public static SelenideElement hiddenPassword(){ return $(By.id("message18")); }
}
package com.guru99.website.tuto.steps;
import com.guru99.website.tuto.pages.HomePages;
public class HomeSteps {
////////////////////////////////////////////////////////////HOMEPAGES-ACCIONES//////////////////////////////////////////////////
//Mensajes de bienvenida según nos logeamos:
static public String Title(){
return HomePages.getTitleWelcome().getText();
}
static public String Manger(){ return HomePages.getManger_Id().getText(); }
}
package com.guru99.website.tuto.steps;
import com.codeborne.selenide.Condition;
import com.guru99.website.tuto.pages.LoginPage;
import org.openqa.selenium.Alert;
import static com.codeborne.selenide.WebDriverRunner.driver;
import static com.guru99.website.tuto.pages.LoginPage.*;
public class LoginSteps {
////////////////////////////////////////////////////////////LOGINPAGES-ACCIONES///////////////////////////////////////////////////////////////////////////////////////
//Meter nombre y contrseña del usuario:
static public void SendKeysForLogin(String userID, String password){
getUser().should(Condition.visible).sendKeys(userID);
getPassword().should(Condition.visible).sendKeys(password);
}
//Hacer click en reset y cerrar la página:
static public void ClickReset(){ btnReset().should(Condition.visible).click(); }
// Hacer clicK en el botón de inicio de sesión:
static public void ClickLogin(){ btnLogin().should(Condition.visible).click(); }
//Recuperamos lo que escribimos en los campos de Usuario y contraseña:
static public String input_getUser() { return getUser().should(Condition.visible).getText(); }
static public String input_getPassword() { return getPassword().should(Condition.visible).getText(); }
//Aceptar alerta cuando nos equivocamos con la contraseña o con el usuario (Vuelve a login):
static public void Alert_ok(){ Alert alert = driver().switchTo().alert(); alert.accept(); }
//Mensajes en los Labels, haciendo visible los hidden de que hay que tener rellenos los input:
static public String VisibilityHiddenUser(){ return hiddenUser().should(Condition.visible).getText(); }
static public String VisibilityHiddenPassword(){ return hiddenPassword().should(Condition.visible).getText(); }
//Mensajes de error cuando los input pierden el foco:
static public void ClickUid(){
getUser().should(Condition.visible).click();
getPassword().should(Condition.visible).click();
getUser().should(Condition.visible).click();
}
}
package com.guru99.website.tuto.test;
import com.codeborne.selenide.Selenide;
import io.cucumber.java.en.Then;
import static com.guru99.website.tuto.constantes.Constantes.GURU99_BANK;
import static com.guru99.website.tuto.constantes.Constantes.MANGER_ID;
import static com.guru99.website.tuto.steps.HomeSteps.Manger;
import static com.guru99.website.tuto.steps.HomeSteps.Title;
import static com.guru99.website.tuto.steps.LoginSteps.ClickLogin;
import static org.junit.Assert.assertEquals;
public class HomeTest {
@Then("Enter the home")
public void enterTheHome() {
ClickLogin();
//Comprobar que la frase animada es la esperada, y que la frase estatica es la esperada tambien:
assertEquals(GURU99_BANK,Title());
assertEquals(MANGER_ID,Manger());
Selenide.clearBrowserCookies();
Selenide.closeWebDriver();
}
}
package com.guru99.website.tuto.test;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideConfig;
import io.cucumber.java.en.Given;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import static com.guru99.website.tuto.constantes.Constantes.*;
import static com.guru99.website.tuto.steps.LoginSteps.*;
import static com.guru99.website.tuto.test.TestHelper.*;
import static org.junit.Assert.*;
public class LoginTest {
@Given("^Open the Chrome and launch the application$")
public void open_the_Chrome_and_launch_the_application() throws Throwable
{
//Abriendo con el chromeDriver de Selenide:
SelenideConfig config = new SelenideConfig();
config.baseUrl(URL_GURU);
config.startMaximized(true);
Selenide.open(config.baseUrl());
}
@When("^Enter the Username (.*) and Password (.*)$")
public void enterTheUsernameUsernameAndPasswordPassword(String username,String password) throws Throwable{ SendKeysForLogin(username,password); }
@Then("^Reset the credential$")
public void Reset_the_credential() throws Throwable
{
ClickReset();
//Comprobar que el boton de reset funciona dejando los campos vacios:
assertEquals("", input_getUser());
assertEquals("",input_getPassword());
Selenide.clearBrowserCookies();
Selenide.closeWebDriver();
}
@Then("Do not enter the house")
public void doNotEnterTheHouse() {
ClickLogin();
assertEquals(INVALIDE_USER,RespAlert());
Selenide.sleep(2000);
Alert_ok();
Selenide.sleep(2000);
Selenide.clearBrowserCookies();
Selenide.closeWebDriver();
}
@When("We click on the text boxes to log in but we don't put anything")
public void weClickOnTheTextBoxesToLogInButWeDonTPutAnything() {
ClickUid();
}
@Then("user field focus error")
public void userFieldFocusError() {
assertEquals(EMPTY_USER, VisibilityHiddenUser());
assertEquals(EMPTY_PASSWORD, VisibilityHiddenPassword());
Selenide.clearBrowserCookies();
Selenide.closeWebDriver();
}
}
package com.guru99.website.tuto.test;
import org.openqa.selenium.Alert;
import static com.codeborne.selenide.WebDriverRunner.driver;
public class TestHelper {
//Recuperamos el texto que lanza la Alerta al logearnos incorrectamente:
static public String RespAlert(){ Alert alert = driver().switchTo().alert(); return alert.getText(); }
}
Feature: Reset functionality on login page of Application and Login and Hidden tag verification
Scenario Outline: Verification of reset button with numbers of credential
Given Open the Chrome and launch the application
When Enter the Username <username> and Password <password>
Then Reset the credential
Examples:
|username |password |
|User1 |password1 |
|User2 |password2 |
|User3 |password3 |
Scenario Outline: Verification of login button with numbers of credential
Given Open the Chrome and launch the application
When Enter the Username <username> and Password <password>
Then Enter the home
Examples:
|username |password |
|mgr123 |mgr!23 |
Scenario Outline: Verification of login button with numbers of credential
Given Open the Chrome and launch the application
When Enter the Username <username> and Password <password>
Then Do not enter the house
Examples:
|username |password |
|TestUser |password |
Scenario: Hidden tag verification
Given Open the Chrome and launch the application
When We click on the text boxes to log in but we don't put anything
Then user field focus error
This diff is collapsed.
Feature: Reset functionality on login page of Application and Login and Hidden tag verification
Scenario Outline: Verification of reset button with numbers of credential
Given Open the Chrome and launch the application
When Enter the Username <username> and Password <password>
Then Reset the credential
Examples:
|username |password |
|User1 |password1 |
|User2 |password2 |
|User3 |password3 |
Scenario Outline: Verification of login button with numbers of credential
Given Open the Chrome and launch the application
When Enter the Username <username> and Password <password>
Then Enter the home
Examples:
|username |password |
|mgr123 |mgr!23 |
Scenario Outline: Verification of login button with numbers of credential
Given Open the Chrome and launch the application
When Enter the Username <username> and Password <password>
Then Do not enter the house
Examples:
|username |password |
|TestUser |password |
Scenario: Hidden tag verification
Given Open the Chrome and launch the application
When We click on the text boxes to log in but we don't put anything
Then user field focus error
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment