Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Dec 6th, 2018 72 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. ////////////////////////////////////////////////
  2. // Protractor Browser Capabilities Extensions //
  3. ////////////////////////////////////////////////
  4. "use strict";
  5.  
  6. module.exports = browser.getCapabilities().then(function(s) {
  7.     var browserName, browserVersion;
  8.     var shortName, shortVersion;
  9.     var ie, ff, ch, sa;
  10.     var platform;
  11.     platform = s.caps_.platform;
  12.     browserName = s.caps_.browserName;
  13.     browserVersion = s.caps_.version;
  14.     shortVersion = browserVersion.split('.')[0];
  15.     ie = /i.*explore/.test(browserName);
  16.     ff = /firefox/.test(browserName);
  17.     ch = /chrome/.test(browserName);
  18.     sa = /safari/.test(browserName);
  19.  
  20.     if (ie) {
  21.         shortName = 'ie';
  22.     } else if (ff) {
  23.         shortName = 'ff';
  24.     } else if (ch) {
  25.         shortName = 'ch';
  26.     } else if (sa) {
  27.         shortName = 'sa';
  28.     } else {
  29.         throw new Exception('Unsupported browser: '+ browserName);
  30.     };
  31.  
  32.     // Returns one of these: ['ch', 'ff', 'sa', 'ie']
  33.     browser.getShortBrowserName = function() {
  34.         return shortName;
  35.     };
  36.  
  37.     // Returns one of these: ['ch33', 'ff27', 'sa7', 'ie11', 'ie10', 'ie9']
  38.     browser.getShortNameVersionAll = function() {
  39.         return shortName + shortVersion;
  40.     };
  41.  
  42.     // Returns one of these: ['ch', 'ff', 'sa', 'ie11', 'ie10', 'ie9']
  43.     browser.getShortNameVersion = function() {
  44.         if (ie) {
  45.             return shortName + shortVersion;
  46.         } else {
  47.             return shortName;
  48.         };
  49.     };
  50.  
  51.     // Return if current browser is IE, optionally specifying if it is a particular IE version
  52.     browser.isInternetExplorer = function(ver) {
  53.         if (ver == null) {
  54.             return ie;
  55.         } else {
  56.             return ie && ver.toString() === shortVersion;
  57.         }
  58.     };
  59.  
  60.     // Function alias
  61.     browser.isIE = browser.isInternetExplorer;
  62.  
  63.     browser.isSafari = function() {
  64.         return sa;
  65.     };
  66.  
  67.     browser.isFirefox = function() {
  68.         return ff;
  69.     };
  70.  
  71.     // Return if current browser is Chrome, optionally specifying if it is a particular Chrome version
  72.     browser.isChrome = function(ver) {
  73.         if (ver == null) {
  74.             return ch;
  75.         } else {
  76.             return ch && ver.toString() === shortVersion;
  77.         }
  78.     };
  79.  
  80.     browser.inWindows = function() {
  81.         return /^WIN|XP/.test(platform);
  82.     };
  83.  
  84.     browser.inOSX = function() {
  85.         return /^MAC/.test(platform);
  86.     };
  87.  
  88.     // Save current webdriver session id for later use
  89.     browser.webdriverRemoteSessionId = s.caps_['webdriver.remote.sessionid'];
  90.  
  91.     browser.inSauceLabs = function() {
  92.         return !!(browser.params.inSauceLabs);
  93.     };
  94.  
  95.     browser.inBrowserStack = function() {
  96.         return !!(browser.params.inBrowserStack);
  97.     };
  98.  
  99.     browser.inTheCloud = function() {
  100.         return !!(browser.params.inSauceLabs || browser.params.inBrowserStack);
  101.     };
  102. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top