Skip to content

Instantly share code, notes, and snippets.

@pettomartino
Last active Mar 9, 2018
Embed
What would you like to do?
<html>
<head>
<script>
function myFunc() {
var email = document.getElementById("email").value
var e = document.getElementById("select")
var selectedOption = e.options[e.selectedIndex].value
var checkBox = document.getElementById('defaultCheck1').checked
if (email == 'foo@bar' && checkBox && selectedOption == "audi") {
document.getElementById('button').innerText = "Sending..."
}
return false;
}
</script>
</head>
<body>
<form onsubmit="return myFunc()">
<div class="form-group">
<label for="email">Email address</label>
<input type="email" class="form-control" id="email" placeholder="name@example.com">
</div>
<div class="form-group">
<label for="exampleFormControlSelect1">Example select</label>
<select id="select">
<option>Select an option</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
</div>
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="defaultCheck1">
<label class="form-check-label" for="defaultCheck1">
Default checkbox
</label>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Example textarea</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3"></textarea>
</div>
<button type="submit" id="button" class="btn btn-primary">Send</button>
</form>
</body>
</html>
module.exports = {
'Show sending message just when default checkbox and Audi are selected': (browser) => {
browser
.url("http://localhost:8080/teste.html")
.waitForElementVisible('body', 50)
.useXpath()
.setValue("//*[contains(text(), 'Email address')]/following-sibling::input", 'foo@bar') // select input next to a label "Email address"
.click("//*[contains(text(), 'Default checkbox')]")
.click("//*[text()='Select an option']")
.click("//*[text()='Audi']")
.click("//*[text()='Send']")
.expect.element("//*[contains(text(), 'Sending...')]").to.be.present
}
}
@pettomartino
Copy link
Author

pettomartino commented Mar 9, 2018

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment