digg.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * =============================================================================
  3. * Demo of Facebook Connect automated login with Nightwatch.js.
  4. * The test navigates to digg.com and tries to perform a Facebook connect login.
  5. *
  6. * This test requires a fbcredentials.json file to be placed in the same
  7. * folder, containing the facebook username and password in the form below:
  8. * -----
  9. * {
  10. * "username" : "",
  11. * "password" : ""
  12. * }
  13. * -----
  14. * The test only works if you have the permissions ALREADY enabled for digg.com
  15. * in your facebook account.
  16. * =============================================================================
  17. */
  18. module.exports = {
  19. disabled : true,
  20. 'digg facebook login' : function (client) {
  21. var fbcredentials;
  22. try {
  23. fbcredentials = require('./fbcredentials.json');
  24. } catch (err) {
  25. console.error('Couldn\'t load the facebook credentials file. Please ensure that ' +
  26. 'you have the fbcredentials.json in the same folder as the test.');
  27. process.exit();
  28. }
  29. client
  30. .url('http://digg.com')
  31. .waitForElementVisible('body', 1000)
  32. .click('#nav-signin')
  33. .click('#btn-facebook-auth-topnav')
  34. .windowHandles(function(result) {
  35. client.assert.equal(result.value.length, 2, 'There should be two windows open.');
  36. var fbWindowHandle = result.value[1];
  37. client.switchWindow(fbWindowHandle);
  38. })
  39. .waitForElementVisible('#facebook body', 1000)
  40. .setValue('input#email', fbcredentials.username)
  41. .setValue('input#pass', fbcredentials.password)
  42. .click('#loginbutton input')
  43. .windowHandles(function(result) {
  44. client.assert.equal(result.value.length, 1, 'There should be only one window open.');
  45. client.switchWindow(result.value[0]);
  46. })
  47. .waitForElementVisible('#digg-header.authenticated', 3000)
  48. .end();
  49. }
  50. };