Last active
August 23, 2018 12:40
-
-
Save dobiedad/21f005a3d5ba9319991dae4422e9b60f to your computer and use it in GitHub Desktop.
This file contains hidden or 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
function set(label, value) { | |
const labels = Array.prototype.slice.call(document.getElementsByTagName('label')) | |
const matches = labels.filter((e)=>e.textContent === label) | |
if (matches.length === 0) { | |
return | |
} | |
if (matches.length > 1) { | |
throw new Error('Got more than one match for "' + label + '"') | |
} | |
const matchedLabel = matches[0] | |
const elementName = matchedLabel.getAttribute('for') | |
const element = document.getElementById(elementName) | |
if (element) { | |
const elementType = element.getAttribute('type') | |
if (element.tagName === "INPUT" && elementType === "date") { | |
element.value = value | |
element.dispatchEvent(new Event('keyup')) | |
element.dispatchEvent(new Event('change')) | |
} else if (element.tagName === "INPUT" && elementType === "checkbox") { | |
if (element.checked !== value) { | |
element.click() | |
} | |
} else if (element.tagName === "TEXTAREA" || element.tagName === "INPUT") { | |
enterTextIntoElement(value, element) | |
} else if (element.tagName === "SELECT") { | |
element.value = value | |
element.dispatchEvent(new Event('keyup')) | |
element.dispatchEvent(new Event('change')) | |
} else if (element.tagName === 'CANVAS') { | |
element.signaturePad.fromData(value) | |
} | |
} | |
} | |
function randomId() { | |
return Math.random() | |
} | |
function randomName() { | |
const names = ["Andrew", "Josh", "Andrei", "Artem"] | |
return names[Math.floor(Math.random() * names.length)] | |
} | |
function randomLastName() { | |
const names = ["Vos", "Chisholm", "Campbell"] | |
return names[Math.floor(Math.random() * names.length)] | |
} | |
function randomText(length) { | |
var text = ""; | |
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for (var i = 0; i < length; i++) | |
text += possible.charAt(Math.floor(Math.random() * possible.length)); | |
return text; | |
} | |
function enterTextIntoElement(text, element) { | |
function elementTriggerEvent(element, eventType, value) { | |
var creator = eventCreatorsByType[eventType] | |
if (!creator) { | |
throw new Error('event type ' + JSON.stringify(eventType) + ' not recognised') | |
} | |
var event = creator(value) | |
element.dispatchEvent(event) | |
} | |
function createMouseEvent(type) { | |
return new MouseEvent(type,{ | |
bubbles: true, | |
cancelable: true | |
}) | |
} | |
function createEvent(type) { | |
return new Event(type,{ | |
bubbles: true, | |
cancelable: false | |
}) | |
} | |
function createKeyboardEvent(type, key) { | |
return new KeyboardEvent(type,{ | |
bubbles: true, | |
cancelable: true, | |
key: key | |
}) | |
} | |
var eventCreatorsByType = { | |
mousedown: function() { | |
return createMouseEvent('mousedown') | |
}, | |
mouseup: function() { | |
return createMouseEvent('mouseup') | |
}, | |
change: function() { | |
return createEvent('change') | |
}, | |
input: function() { | |
return createEvent('input') | |
}, | |
keydown: function(key) { | |
return createKeyboardEvent('keydown', key) | |
}, | |
keyup: function(key) { | |
return createKeyboardEvent('keyup', key) | |
}, | |
keypress: function(key) { | |
return createKeyboardEvent('keypress', key) | |
}, | |
submit: function() { | |
return new Event('submit',{ | |
bubbles: true, | |
cancelable: true | |
}) | |
} | |
} | |
element.focus() | |
if (element.value !== '') { | |
elementTriggerEvent(element, 'keydown') | |
elementTriggerEvent(element, 'keypress') | |
element.value = '' | |
elementTriggerEvent(element, 'input') | |
elementTriggerEvent(element, 'keyup') | |
} | |
if (text.length > 0) { | |
// update the value to the value except for the last character | |
element.value = text.substring(0, text.length - 1) | |
// trigger the key events for just the last character | |
var lastChar = text[text.length - 1] | |
elementTriggerEvent(element, 'keydown', lastChar) | |
elementTriggerEvent(element, 'keypress', lastChar) | |
element.value = text | |
elementTriggerEvent(element, 'input') | |
elementTriggerEvent(element, 'keyup', lastChar) | |
} | |
elementTriggerEvent(element, 'change') | |
} | |
function clickLinkWithText(text) { | |
const anchors = Array.prototype.slice.call(document.getElementsByTagName('a')) | |
const matches = anchors.filter((e)=>e.textContent === text) | |
if (matches.length === 0) { | |
return | |
} | |
if (matches.length > 1) { | |
throw new Error('Got more than one match for "' + text + '"') | |
} | |
const matchedAnchor = matches[0] | |
matchedAnchor.click() | |
} | |
function setAccountDetails() { | |
set("Member ID", randomId()) | |
set('Membership Plan', { | |
membershipPlanId: 'basic-plan', | |
name: 'Basic Plan', | |
freeShipping: false | |
}) | |
set("First Name", randomName()) | |
set("Last Name", randomLastName()) | |
set("Date of Birth", "1983-10-23") | |
set("Telephone", '2222222222') | |
set("Cell", '2222222222') | |
var email = randomText(6).toLowerCase() + "@mailinator.com" | |
set("Email", email) | |
set("Confirm Email", email) | |
set("Full Name", randomName() + " " + randomLastName()) | |
set("Address 1", "The House") | |
set("City", "Beverly Hills") | |
set("State", "Colorado") | |
set("Zip Code", "90210") | |
set("Country", "United States") | |
} | |
function setPrescription() { | |
set("Doctor's Office", "Big Doctor Place") | |
set("Doctor's Name", "Dr. Doc") | |
set("Telephone", '2222222222') | |
set("State", 'Alaska') | |
setTimeout(function() { | |
clickLinkWithText("Alaska") | |
set("Prescription Start Date", new Date().toJSON().substring(0, 10)) | |
set("Product Name", 'Acuvue Moist') | |
setTimeout(function() { | |
clickLinkWithText("Acuvue Moist") | |
setTimeout(function() { | |
set("Power", '1') | |
set("BC", '-2') | |
set("DIA", '12.4') | |
}, 200) | |
}, 200) | |
}, 200) | |
} | |
function setSchedule() { | |
set('Patient Signature', [{ | |
color: 'black', | |
points: [{ | |
time: 1531751671367, | |
x: 65.125, | |
y: 68 | |
}, { | |
time: 1531751671427, | |
x: 65.125, | |
y: 75 | |
}, { | |
time: 1531751671444, | |
x: 64.125, | |
y: 81 | |
}, { | |
time: 1531751671460, | |
x: 64.125, | |
y: 92 | |
}, { | |
time: 1531751671477, | |
x: 64.125, | |
y: 98 | |
}, { | |
time: 1531751671511, | |
x: 64.125, | |
y: 106 | |
}, { | |
time: 1531751671527, | |
x: 67.125, | |
y: 111 | |
}, { | |
time: 1531751671560, | |
x: 70.125, | |
y: 118 | |
}, { | |
time: 1531751671594, | |
x: 72.125, | |
y: 126 | |
}, { | |
time: 1531751671719, | |
x: 78.125, | |
y: 122 | |
}, { | |
time: 1531751671736, | |
x: 83.125, | |
y: 116 | |
}, { | |
time: 1531751671753, | |
x: 91.125, | |
y: 105 | |
}, { | |
time: 1531751671770, | |
x: 94.125, | |
y: 98 | |
}, { | |
time: 1531751671787, | |
x: 96.125, | |
y: 90 | |
}, { | |
time: 1531751671804, | |
x: 98.125, | |
y: 85 | |
}, { | |
time: 1531751671820, | |
x: 100.125, | |
y: 80 | |
}, { | |
time: 1531751671837, | |
x: 102.125, | |
y: 74 | |
}, { | |
time: 1531751671853, | |
x: 103.125, | |
y: 69 | |
}] | |
}, { | |
color: 'black', | |
points: [{ | |
time: 1531751672297, | |
x: 149.125, | |
y: 72 | |
}, { | |
time: 1531751672386, | |
x: 140.125, | |
y: 78 | |
}, { | |
time: 1531751672403, | |
x: 135.125, | |
y: 83 | |
}, { | |
time: 1531751672420, | |
x: 131.125, | |
y: 87 | |
}, { | |
time: 1531751672437, | |
x: 125.125, | |
y: 93 | |
}, { | |
time: 1531751672468, | |
x: 123.125, | |
y: 100 | |
}, { | |
time: 1531751672500, | |
x: 128.125, | |
y: 114 | |
}, { | |
time: 1531751672532, | |
x: 135.125, | |
y: 121 | |
}, { | |
time: 1531751672565, | |
x: 148.125, | |
y: 131 | |
}, { | |
time: 1531751672581, | |
x: 157.125, | |
y: 134 | |
}, { | |
time: 1531751672598, | |
x: 163.125, | |
y: 135 | |
}, { | |
time: 1531751672614, | |
x: 169.125, | |
y: 135 | |
}, { | |
time: 1531751672646, | |
x: 177.125, | |
y: 125 | |
}, { | |
time: 1531751672663, | |
x: 181.125, | |
y: 120 | |
}, { | |
time: 1531751672696, | |
x: 185.125, | |
y: 112 | |
}, { | |
time: 1531751672712, | |
x: 186.125, | |
y: 106 | |
}, { | |
time: 1531751672729, | |
x: 184.125, | |
y: 101 | |
}, { | |
time: 1531751672745, | |
x: 178.125, | |
y: 94 | |
}, { | |
time: 1531751672762, | |
x: 173.125, | |
y: 89 | |
}, { | |
time: 1531751672778, | |
x: 168.125, | |
y: 84 | |
}, { | |
time: 1531751672795, | |
x: 161.125, | |
y: 80 | |
}, { | |
time: 1531751672828, | |
x: 152.125, | |
y: 76 | |
}, { | |
time: 1531751672862, | |
x: 143.125, | |
y: 74 | |
}, { | |
time: 1531751672928, | |
x: 138.125, | |
y: 70 | |
}] | |
}, { | |
color: 'black', | |
points: [{ | |
time: 1531751673505, | |
x: 232.125, | |
y: 73 | |
}, { | |
time: 1531751673562, | |
x: 227.125, | |
y: 76 | |
}, { | |
time: 1531751673579, | |
x: 221.125, | |
y: 80 | |
}, { | |
time: 1531751673596, | |
x: 214.125, | |
y: 84 | |
}, { | |
time: 1531751673612, | |
x: 203.125, | |
y: 98 | |
}, { | |
time: 1531751673629, | |
x: 199.125, | |
y: 104 | |
}, { | |
time: 1531751673646, | |
x: 199.125, | |
y: 110 | |
}, { | |
time: 1531751673663, | |
x: 199.125, | |
y: 116 | |
}, { | |
time: 1531751673679, | |
x: 201.125, | |
y: 124 | |
}, { | |
time: 1531751673716, | |
x: 205.125, | |
y: 128 | |
}, { | |
time: 1531751673747, | |
x: 211.125, | |
y: 129 | |
}, { | |
time: 1531751673764, | |
x: 217.125, | |
y: 130 | |
}, { | |
time: 1531751673782, | |
x: 224.125, | |
y: 131 | |
}, { | |
time: 1531751673799, | |
x: 230.125, | |
y: 133 | |
}, { | |
time: 1531751673816, | |
x: 237.125, | |
y: 135 | |
}, { | |
time: 1531751673833, | |
x: 243.125, | |
y: 138 | |
}, { | |
time: 1531751673882, | |
x: 246.125, | |
y: 143 | |
}, { | |
time: 1531751673931, | |
x: 241.125, | |
y: 145 | |
}, { | |
time: 1531751673981, | |
x: 230.125, | |
y: 146 | |
}, { | |
time: 1531751674014, | |
x: 222.125, | |
y: 150 | |
}, { | |
time: 1531751674064, | |
x: 216.125, | |
y: 152 | |
}] | |
}]) | |
} | |
function setCardPayment() { | |
set("Card Number", "4111111111111111") | |
set("Expiry Date", "10/99") | |
set("I have read and accepted the Terms & Conditions", true) | |
} | |
setAccountDetails() | |
setPrescription() | |
setSchedule() | |
setCardPayment() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment