Skip to content

Instantly share code, notes, and snippets.

@shaunabandu
shaunabandu / test.java
Created April 24, 2024 07:42
Selenium xpath
//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')]";
@shaunabandu
shaunabandu / commands.js
Created April 24, 2024 05:45
Call an API request with an alias
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;
@shaunabandu
shaunabandu / commands.js
Last active April 24, 2024 05:34
How to handle an API request
//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);
@shaunabandu
shaunabandu / convertDateFormat.js
Last active April 24, 2024 07:51
Javascript gists
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) {
@shaunabandu
shaunabandu / test.cy.js
Created April 22, 2024 05:12
How to check if a URL contains a keyword
cy.url().then(($url) => {
if ($url.includes("new") == false) {
//do something here
} else {
//do something else
}
}