This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//webpage under test: https://www.freemalaysiatoday.com/category/nation/2024/04/24/jpj-fines-3-bus-drivers-for-making-tiktok-videos-calls-while-driving/ | |
//reference: https://www.guru99.com/xpath-selenium.html | |
//1. Basic Xpath | |
Xpath = "//summary[@class='list-none']"; | |
//2. Contains() | |
Xpath = "//input[contains(@type, 'emai')]"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Cypress.Commands.add("getUser", () => { | |
cy.getUserList(); | |
cy.get("@userID").then((userID) => { | |
method: "GET", | |
url: "https://url.com/" + userID, | |
headers: { | |
Authorization: "Bearer " + Cypress.env("token"), | |
} | |
}).then((response) => { | |
let firstName = response.body.data.first_name; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Call an API request | |
Cypress.Commands.add("getUserList", () => { | |
cy.request({ | |
method: "GET", | |
url: "https://url.com", | |
headers: { | |
Authorization: "Bearer " + Cypress.env("token"), | |
} | |
}).then((response) => { | |
let randomInt = getRandomInt(0, response.body.data.length); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function convertDateFormat() { | |
let date = "2020-04-03"; | |
let date_split = date.split("-"); | |
let yyyy = date_split[0]; | |
let mm = date_split[1]; | |
let dd = date_split[2]; | |
let mon; | |
switch (mm) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cy.url().then(($url) => { | |
if ($url.includes("new") == false) { | |
//do something here | |
} else { | |
//do something else | |
} | |
} |