Skip to content

Instantly share code, notes, and snippets.

@joelwatson
Last active June 30, 2017 18:02
Show Gist options
  • Save joelwatson/34863a5d224d51999258bffaf5fd6ab3 to your computer and use it in GitHub Desktop.
Save joelwatson/34863a5d224d51999258bffaf5fd6ab3 to your computer and use it in GitHub Desktop.
Interacting with native modals in Sencha Test
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title></title>
</head>
<body>
<input type="button" id="alert" onclick="onAlert()" value="Alert" />
<input type="button" id="prompt" onclick="onPrompt()" value="Prompt" />
<input type="button" id="confirm" onclick="onConfirm()" value="Confirm" />
<input type="text" id="name" />
<script>
function onAlert() {
alert('Hello world!');
}
function onPrompt() {
var result = prompt('Please enter your name');
document.getElementById('name').value = result;
}
function onConfirm() {
confirm('Do you want a million dollars?');
}
</script>
</body>
</html>
describe("Alerts", function() {
var io, po;
beforeAll(function () {
io = ST.defaultContext.driver;
po = {
alert: function () {
return ST.element('@alert').click();
},
confirm: function () {
return ST.element('@confirm').click()
},
prompt: function () {
return ST.element('@prompt').click()
},
text: function () {
return ST.element('@name');
}
}
});
afterAll(function () {
io = null;
});
describe('alert()', function () {
it('should accept alert()', function () {
po.alert().and(function () {
io.alertAccept();
});
});
});
describe('confirm()', function () {
it('should accept confirm()', function () {
po.confirm().and(function () {
io.alertAccept();
});
});
it('should dismiss confirm()', function () {
po.confirm().and(function () {
io.alertDismiss();
});
});
});
describe('prompt()', function () {
it('should accept', function () {
po.prompt().and(function () {
io.alertAccept();
});
});
it('should dismiss', function () {
po.prompt().and(function () {
io.alertDismiss();
});
});
it('should enter text', function (done) {
io.alertText('Voldemort');
io.alertDismiss();
po.text().expect('value').toBe('Voldemort');
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment