onbeforeunload.js 947 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. /**
  2. * Sample automated test scenario for Nightwatch.js
  3. *
  4. * > it navigates to page that has onbeforeunload handler
  5. */
  6. module.exports = {
  7. 'go to page with unload handler': function(client) {
  8. client
  9. .url('http://www.4guysfromrolla.com/demos/OnBeforeUnloadDemo1.htm')
  10. .waitForElementVisible('body', 1000);
  11. },
  12. 'navigate away from page WITH unload handler': function(client) {
  13. var hasDialog = false;
  14. client
  15. .hasOnBeforeUnload(function(result) {
  16. this.verify.equal(result, true, 'The page should have an onbeforeunload handler');
  17. hasDialog = result;
  18. })
  19. .url('http://google.com', function() {
  20. if (hasDialog) {
  21. this.acceptAlert();
  22. }
  23. })
  24. .waitForElementVisible('body', 1000);
  25. },
  26. 'go to nightwatch' : function(c) {
  27. c.url('http://nightwatchjs.org')
  28. .waitForElementVisible('body', 1000);
  29. },
  30. after : function(c) {
  31. c.end();
  32. }
  33. };