Advertisement
fhumayun

Basic Selenium Webdriver Code

Jun 21st, 2015
501
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. var webdriver = require('selenium-webdriver');
  2.  
  3. // Input capabilities
  4. var capabilities = {
  5.   'browserName' : 'Chrome',
  6.   'browser_version' : '43.0',
  7.   'os' : 'Windows',
  8.   'os_version' : '7',
  9.   'resolution' : '1024x768',
  10.   'browserstack.user' : '<username>',
  11.   'browserstack.key' : '<access_key>',
  12.   'browserstack.local' : true,
  13.   'browserstack.debug' : true,
  14.   'build' : 'BS Test case',
  15.   'name' : 'Test With Local',
  16.   'project' : 'BS Test case'
  17. }
  18.  
  19. var driver = new webdriver.Builder().
  20.   usingServer('http://hub.browserstack.com/wd/hub').
  21.   withCapabilities(capabilities).
  22.   build();
  23.  
  24. driver.get('<Your_URL>');
  25.  
  26. var WAIT_TIME = 5000;
  27. return driver.sleep(WAIT_TIME).then(function() {
  28. var fs = require('fs');
  29.  
  30. webdriver.WebDriver.prototype.saveScreenshot = function(filename) {
  31.     return driver.takeScreenshot().then(function(data) {
  32.         fs.writeFile(filename, data.replace(/^data:image\/png;base64,/,''), 'base64', function(err) {
  33.             if(err) throw err;
  34.         });
  35.     })
  36. };
  37.  
  38. driver.saveScreenshot('scr_with_local.png');
  39. driver.quit();
  40. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement