Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First steps with serenity #29

Open
wants to merge 4 commits into
base: first-steps-with-serenity
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: starter.CukesRunner

45 changes: 32 additions & 13 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
defaultTasks 'clean','test','aggregate'
defaultTasks 'clean', 'test', 'aggregate'

repositories {
mavenLocal()
Expand All @@ -11,36 +11,55 @@ buildscript {
jcenter()
}
dependencies {
classpath("net.serenity-bdd:serenity-gradle-plugin:1.8.3")
// classpath("net.serenity-bdd:serenity-gradle-plugin:${serenityCoreVersion}")
classpath("net.serenity-bdd:serenity-gradle-plugin:2.2.0")
}
}

apply plugin: 'java'
apply plugin: 'eclipse'
apply plugin: 'idea'
apply plugin: 'net.serenity-bdd.aggregator'
apply from: "$rootDir/gradle/libraries.gradle"


sourceCompatibility = 1.8
targetCompatibility = 1.8

ext {
slf4jVersion = '1.7.7'
serenityCoreVersion = '2.2.13'
serenityCucumberVersion = '2.2.6'
junitVersion = '4.12'
assertJVersion = '3.8.0'
logbackVersion = '1.2.3'
}

dependencies {
compile libs.slf4jApi,
libs.logback

testCompile libs.test.serenity.core,
libs.test.serenity.screenplay,
libs.test.serenity.screenplayWebdriver,
libs.test.serenity.junit,
libs.test.junit,
libs.test.assertj
compile "ch.qos.logback:logback-classic:${logbackVersion}"

// implementation "net.serenity-bdd:serenity-cucumber:${serenityCucumberVersion}"

testCompile "net.serenity-bdd:serenity-core:${serenityCoreVersion}",
"net.serenity-bdd:serenity-cucumber5:${serenityCucumberVersion}",
"net.serenity-bdd:serenity-screenplay:${serenityCoreVersion}",
"net.serenity-bdd:serenity-screenplay-webdriver:${serenityCoreVersion}",
"junit:junit:${junitVersion}",
"org.assertj:assertj-core:${assertJVersion}"
}

test {
testLogging.showStandardStreams = true
systemProperties System.getProperties()
}
jar {
from {
// Package all dependencies in the .jar
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
}
manifest {
// Indicate the main class for the .jar file
attributes 'Main-Class': 'CukesRunner'
}
}

gradle.startParameter.continueOnFailure = true

Expand Down
Binary file not shown.
60 changes: 60 additions & 0 deletions src/test/java/Tasks/BookClass.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package Tasks;

import Utils.SwitchFrame;
import Utils.SwitchPage;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.actions.Switch;
import net.serenitybdd.screenplay.waits.WaitUntil;
import starter.login.LoginForm;

import static net.serenitybdd.screenplay.Tasks.instrumented;
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isClickable;
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isVisible;
import static starter.login.LoginForm.FRAME_2;
import static starter.login.LoginForm.FRAME_3;

public class BookClass implements Task {

@Override
public <T extends Actor> void performAs(T actor) {
actor.attemptsTo(
WaitUntil.the(LoginForm.PROGRAM_BUTTON, isClickable()),
Click.on(LoginForm.PROGRAM_BUTTON),
WaitUntil.the(LoginForm.SELECT_PROGRAM, isClickable()),
Click.on(LoginForm.SELECT_PROGRAM),
Click.on(LoginForm.BEGIN),
WaitUntil.the(FRAME_2,isVisible()),
SwitchFrame.switchToFrame(FRAME_2),
WaitUntil.the(LoginForm.DROPDOWN_LIST,isClickable()),
Click.on(LoginForm.DROPDOWN_LIST),
WaitUntil.the(LoginForm.PENDINGS,isClickable()),
Click.on(LoginForm.PENDINGS),
WaitUntil.the(LoginForm.NUMBER_CLASS,isClickable()),
Click.on(LoginForm.NUMBER_CLASS),
WaitUntil.the(LoginForm.SCHEDULE_BUTTON,isClickable()),
Click.on(LoginForm.SCHEDULE_BUTTON),
Switch.toParentFrame(),
WaitUntil.the(FRAME_3,isClickable()),
SwitchFrame.switchToFrame(FRAME_3),
// WaitUntil.the(LoginForm.DAY_LIST,isClickable()),
// Click.on(LoginForm.DAY_LIST),
WaitUntil.the(LoginForm.SELECT_DAY,isClickable()),
Click.on(LoginForm.SELECT_DAY),
// WaitUntil.the(LoginForm.HOUR,isClickable()),
Click.on(LoginForm.HOUR),
Click.on(LoginForm.ENTER_BUTTON)


// WaitUntil.the(LoginForm.SCHEDULE_BUTTON, isClickable()),
// Click.on(LoginForm.SCHEDULE_BUTTON)
);

}

public static Performable bookClass(){
return instrumented(BookClass.class);
}
}
42 changes: 42 additions & 0 deletions src/test/java/Tasks/DoLogin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package Tasks;

import Utils.SwitchPage;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.actions.Enter;
import net.serenitybdd.screenplay.waits.WaitUntil;
import starter.login.LoginForm;

import static net.serenitybdd.screenplay.Tasks.instrumented;
import static net.serenitybdd.screenplay.matchers.WebElementStateMatchers.isClickable;

public class DoLogin implements Task {

private final String username;
private final String password;

public DoLogin(String username, String password) {
this.username = username;
this.password = password;
}

public static Performable withCredentials(String username, String password){
return instrumented(DoLogin.class, username, password);
}
@Override
public <T extends Actor> void performAs(T actor) {
// String defaultHandle = BrowseTheWeb.as(actor).getDriver().getWindowHandle();
actor.attemptsTo(
// Switch.toActiveElement(),
WaitUntil.the(LoginForm.LOGIN_FIELD, isClickable()),
Click.on(LoginForm.LOGIN_FIELD),
SwitchPage.switchBetweenPages(),
WaitUntil.the(LoginForm.USERNAME_FIELD,isClickable()),
Enter.theValue(username).into(LoginForm.USERNAME_FIELD),
Enter.theValue(password).into(LoginForm.PASSWORD_FIELD),
Click.on(LoginForm.ENTER_BUTTON)
);
}
}
13 changes: 13 additions & 0 deletions src/test/java/Tasks/NavigateTo.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package Tasks;

import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Open;
import starter.login.EnglishPage;

public class NavigateTo {
public static Performable theLoginEnglishPage() {
return Task.where("{0} opens the login english page",
Open.browserOn().the(EnglishPage.class));
}
}
44 changes: 44 additions & 0 deletions src/test/java/Utils/SwitchFrame.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package Utils;

import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.actions.Switch;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

import static net.serenitybdd.screenplay.Tasks.instrumented;



public class SwitchFrame implements Task {
private final By locatorFrame;

public SwitchFrame(By locatorFrame){
this.locatorFrame = locatorFrame;
}
public WebElement SwitchDoubleTap(By locator_frame, Actor actor){
WebElement frame= BrowseTheWeb.as(actor).find(locator_frame);
return frame;
}



@Override
public <T extends Actor> void performAs(T actor) {

actor.attemptsTo(
Switch.toFrame(SwitchDoubleTap(locatorFrame, actor))

);


}

public static Performable switchToFrame(By locatorFrame) {
return instrumented(SwitchFrame.class,locatorFrame);
}
}


40 changes: 40 additions & 0 deletions src/test/java/Utils/SwitchPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package Utils;


import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.actions.Switch;


import static net.serenitybdd.screenplay.Tasks.instrumented;


public class SwitchPage implements Task {


public static String getNewWindowHandle(Actor actor, String currentWindowHandle){
for(String windowHandle : BrowseTheWeb.as(actor).getDriver().getWindowHandles()){
if(!windowHandle.equals(currentWindowHandle)){
// System.out.println("+++++++++++++++++++++++ "+windowHandle);
return windowHandle;
}
}
return null;
}

@Override
public <T extends Actor> void performAs(T actor) {
String currentHandle = BrowseTheWeb.as(actor).getDriver().getWindowHandle();
actor.attemptsTo(
Switch.toWindow(getNewWindowHandle(actor,currentHandle))

);


}
public static Performable switchBetweenPages(){
return instrumented(SwitchPage.class);
}
}
23 changes: 7 additions & 16 deletions src/test/java/starter/ASimpleTest.java
Original file line number Diff line number Diff line change
@@ -1,27 +1,18 @@
package starter;

import net.serenitybdd.junit.runners.SerenityRunner;
import io.cucumber.junit.CucumberOptions;
import net.serenitybdd.cucumber.CucumberWithSerenity;
//import net.serenitybdd.junit.runners.SerenityRunner;
import net.thucydides.core.annotations.Pending;
import net.thucydides.core.annotations.Steps;
import org.junit.Test;
import org.junit.runner.RunWith;
import starter.steps.MathWizSteps;

@RunWith(SerenityRunner.class)
public class ASimpleTest {

@Steps
MathWizSteps michael;

@Test
public void addingSums() {
// Given
michael.startsWith(1);
@RunWith(CucumberWithSerenity.class)
@CucumberOptions(features = "src/test/resources/features/login",
glue="starter.stepdefinitions")
public class ASimpleTest {

// When
michael.adds(2);

// Then
michael.shouldHave(3);
}
}
12 changes: 12 additions & 0 deletions src/test/java/starter/CukesRunner.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package starter;


public class CukesRunner {
public static void main(String[] args) throws Throwable {
final String[] arguments = new String[]{
"--glue", "starter",
"src/test/resources/features/login"// This will look for the classpath inside the jar file
};
io.cucumber.core.cli.Main.main(arguments);
}
}
8 changes: 8 additions & 0 deletions src/test/java/starter/login/EnglishPage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package starter.login;

import net.thucydides.core.annotations.DefaultUrl;
import net.thucydides.core.pages.PageObject;

@DefaultUrl("https://smart.edu.co/estudiante")
public class EnglishPage extends PageObject {
}
36 changes: 36 additions & 0 deletions src/test/java/starter/login/LoginForm.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package starter.login;


import net.serenitybdd.screenplay.targets.Target;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;

public class LoginForm {

public static By LOGIN_FIELD = By.xpath("//a[@href='https://schoolpack.smart.edu.co/idiomas/alumnos.aspx' and @target]");
public static By USERNAME_FIELD = By.id("vUSUCOD");
public static By PASSWORD_FIELD = By.id("vPASS");
public static By ENTER_BUTTON = By.id("BUTTON1");

public static By PROGRAM_BUTTON = By.xpath("//img[@src='Resources/PROGRAMACION.png']");

public static By SELECT_PROGRAM = By.xpath("//span[@id='span_W0030TMPDESART_0001']");
public static By BEGIN = By.xpath("//input[@id='W0030BUTTON1']");
public static By BACK = By.xpath("//input[@id='BUTTON3']");
public static By FRAME_2= By.id("gxp0_ifrm");
public static By DROPDOWN_LIST = By.xpath("//select[@name='vTPEAPROBO']");

public static By PENDINGS = By.xpath("//option[@value='2']");
public static By NUMBER_CLASS = By.id("span_vPRONOMPRO_0002");
public static By SCHEDULE_BUTTON = By.xpath("//input[@value='Asignar' ]");
// public static By DAY_LIST = By.xpath("//select[@name='vDIA']");
public static By SELECT_DAY = By.xpath("//*[@name='vDIA']//child::option[2]");

public static By FRAME_3= By.id("gxp1_ifrm");

public static By HOUR = By.xpath("//td[@data-colindex='2']//child::span[@id='span_W0030TMPCODART_0001']");

public static By CONFIRMATION_TEXT = By.xpath("//div[@class='gx-warning-message']");

public static By CLOSE = By.xpath("//span[@id='gxp1_cls']");
}
Loading