Skip to content

Commit

Permalink
Update Cypress version & add test for cywrap()
Browse files Browse the repository at this point in the history
  • Loading branch information
Niluka Sripali committed May 22, 2022
1 parent e3a1e83 commit 182d89b
Show file tree
Hide file tree
Showing 3 changed files with 141 additions and 67 deletions.
74 changes: 74 additions & 0 deletions cypress/integration/3-my-scripts/wrap-command-usages.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@

describe('Cypress Cy.wrap() usages', () => {

it('Find an element and Wrap previously yielded jQuery Objects',
{baseUrl: 'https://console.asgardeo.io'}, () => {

cy.visit('/');
cy.get('#usernameUserInput').then($username => {
// jQuery to set Value
// $username.val("[email protected]")

// Using Cypress command
cy.wrap($username).type('[email protected]');
} )
});

it('Cypress Wrap with synchronized Javascript code', () => {

//validate the variable is equal to the expected value
const header = "WSO2 Asgardeo";
cy.wrap(header).should('contains', 'WSO2 Asgardeo');

// Check Object has a certain Property and Value
const pageHeader = { header: "Sign In" }
cy.wrap(pageHeader).should("have.property", "header", "Sign In")

// Check Array contains an Item
const wso2Products = ["WSO2 Enterprise Integratort", "WSO2 API Manager", "WSO2 Identity Server", "Choreo", "Asgardeo", "Ballerinas"]
cy.wrap(wso2Products).should("contains", "Asgardeo")
});

const product = (pname, ms) => {
console.log('Promise begin...')
return new Promise(resolve => {
setTimeout(() => {
console.log('Promise finished...Product '+pname+' is returned...')
resolve({ name: pname })
}, ms)
})
}

it('Cypress Wrap command - JavaScript Promise', {baseUrl: 'https://console.asgardeo.io'}, () => {

// Test Case Completes immediately
// TC doesn't wait for the promise to complete
// Also, couldn't test if the promise has returned the product Object
//const productExpected = product("Asgardeo", 2000)
// Solution :) - WRAP
//cy.wrap(productExpected)

// With Assertions
//cy.wrap(productExpected).should("have.property", "name", "Asgardeo")

// resolved promises are returned immediately
// cy.wrap(productExpected)
// Promise still starts immediately...and Cypress commands are chained
// So if we want this promise to execute after any CYPRESS command, we run promise inside THEN Block
cy.visit('/').then(() => {
const productExpected = product("Asgardeo", 2000)
cy.wrap(productExpected)
})

});
});

/**
* returning false here prevents Cypress from failing the test
* expect(err.message).to.include('Ignoring error for now');
*/
Cypress.on("uncaught:exception", (err, runnable) => {

console.log("Cypress detected uncaught exception", err);
return false;
});
132 changes: 66 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@
},
"homepage": "https://github.com/NilukaSripalim/cypress-automation-niluka#readme",
"devDependencies": {
"cypress": "^9.5.0"
"cypress": "^9.6.1"
}
}

0 comments on commit 182d89b

Please sign in to comment.