prepared by: Jed Dayo
https://www.cypress.io/
Test Automation Tool
Designed for the modern web
Operates directly in the browser
Selenium is an open source umbrella project for a range of tools and libraries aimed at supporting browser automation.
public static void main(String[] args) {
// declaration and instantiation of objects/variables
System.setProperty("webdriver.chrome.driver", "D:\\ChromeDriver\\chromedriver.exe");
WebDriver driver=new ChromeDriver();
// Launch website
driver.navigate().to("http://www.google.com/");
// Click on the search text box and send value
driver.findElement(By.id("lst-ib")).sendKeys("javatpoint tutorials");
// Click on the search button
driver.findElement(By.name("btnK")).click();
}
https://www.browserstack.com/guide/cypress-vs-selenium
Performance Comparison
https://docs.cypress.io/guides/references/trade-offs
Example Code
Example Code - Intercept and Mock Response
https://applitools.com/blog/page-objects-app-actions-cypress/
https://executeautomation.medium.com/selenium-page-object-model-vs-cypress-app-action-7e0739eeb672
Sample Page Object in Cypress
Cypress.Commands.add("login", (username, password, { rememberUser = false } = {}) => {
const signinPath = "/signin";
cy.intercept("POST", "/login").as("loginUser");
cy.intercept("GET", "checkAuth").as("getUserProfile");
cy.location("pathname", { log: false }).then((currentPath) => {
if (currentPath !== signinPath) {
cy.visit(signinPath);
}
});
log.snapshot("before");
cy.getBySel("signin-username").type(username);
cy.getBySel("signin-password").type(password);
if (rememberUser) {
cy.getBySel("signin-remember-me").find("input").check();
}
cy.getBySel("signin-submit").click();
cy.wait("@loginUser").then((loginUser: any) => {
log.snapshot("after");
log.end();
});
});
describe('login user',()=>{
it("should error for an invalid user", function () {
cy.login("invalidUserName", "invalidPa$$word");
cy.getBySel("signin-error")
.should("be.visible")
.and("have.text", "Username or password is invalid");
cy.visualSnapshot("Sign In, Invalid Username and Password, Username or Password is Invalid");
});
it("should error for an invalid password for existing user", function () {
cy.database("find", "users").then((user: User) => {
cy.login(user.username, "INVALID");
});
cy.getBySel("signin-error")
.should("be.visible")
.and("have.text", "Username or password is invalid");
cy.visualSnapshot("Sign In, Invalid Username, Username or Password is Invalid");
});
})
Sample App Action Pattern in Cypress
https://docs.cypress.io/guides/guides/parallelization