Completed
Push — master ( 2d8abe...e6d75a )
by Neil
03:16
created

require.stat   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
1
require('dotenv').config()
2
const PKG = require('../../package.json'); // so we can get the version of the project
3
const BINPATH = './node_modules/nightwatch/bin/'; // change if required.
4
const SCREENSHOT_PATH = "./node_modules/nightwatch/screenshots/" + PKG.version + "/";
5
6
const config = { // we use a nightwatch.conf.js file so we can include comments and helper functions
7
  "src_folders": [
8
    "./test/functional"     // we use '/test' as the name of our test directory by default. So 'test/e2e' for 'e2e'.
9
  ],
10
  "output_folder": "./node_modules/nightwatch/reports", // reports (test outcome) output by Nightwatch
11
  "selenium": {
12
    "start_process": true,
13
    "server_path": BINPATH + "selenium.jar", // downloaded by selenium-download module (see below)
14
    "log_path": "",
15
    "host": "127.0.0.1",
16
    "port": 4444,
17
    "cli_args": {
18
      "webdriver.chrome.driver" : BINPATH + "chromedriver" // also downloaded by selenium-download
19
    }
20
  },
21
  "test_workers" : {"enabled" : true, "workers" : "auto"}, // perform tests in parallel where possible
22
  "test_settings": {
23
    "default": {
24
      "launch_url": "http://localhost", // we're testing a Public or "staging" site on Saucelabs
25
      "selenium_port": 80,
26
      "selenium_host": "ondemand.saucelabs.com",
27
      "silent": true,
28
      "screenshots": {
29
        "enabled": true, // save screenshots to this directory (excluded by .gitignore)
30
        "path": SCREENSHOT_PATH
31
      },
32
      "username" : "${SAUCE_USERNAME}",     // if you want to use Saucelabs remember to
33
      "access_key" : "${SAUCE_ACCESS_KEY}", // export your environment variables (see readme)
34
      "globals": {
35
        "waitForConditionTimeout": 10000    // wait for content on the page before continuing
36
      }
37
    },
38
    "local": {
39
      "launch_url": "http://localhost",
40
      "selenium_port": 4444,
41
      "selenium_host": "127.0.0.1",
42
      "silent": true,
43
      "screenshots": {
44
        "enabled": true, // save screenshots taken here
45
        "path": SCREENSHOT_PATH
46
      }, // this allows us to control the
47
      "globals": {
48
        "waitForConditionTimeout": 15000 // on localhost sometimes internet is slow so wait...
49
      },
50
      "desiredCapabilities": {
51
        "browserName": "chrome",
52
        "chromeOptions": {
53
          "args": [
54
            `Mozilla/5.0 (iPhone; CPU iPhone OS 5_0 like Mac OS X) AppleWebKit/534.46
55
            (KHTML, like Gecko) Version/5.1 Mobile/9A334 Safari/7534.48.3`,
56
            "--window-size=640,1136" // iphone 5
57
          ]
58
        },
59
        "javascriptEnabled": true,
60
        "acceptSslCerts": true
61
      }
62
    },
63
    "chrome": { // your local Chrome browser (chromedriver)
64
      "desiredCapabilities": {
65
        "browserName": "chrome",
66
        "javascriptEnabled": true,
67
        "acceptSslCerts": true
68
      }
69
    },
70
    "chromemac": { // browsers used on saucelabs:
71
      "desiredCapabilities": {
72
        "browserName": "chrome",
73
        "platform": "OS X 10.11",
74
        "version": "47"
75
      }
76
    },
77
    "ie11": {
78
      "desiredCapabilities": {
79
        "browserName": "internet explorer",
80
        "platform": "Windows 10",
81
        "version": "11.0"
82
      }
83
    },
84
    "firefox" : {
85
      "desiredCapabilities": {
86
        "platform": "XP",
87
        "browserName": "firefox",
88
        "version": "33"
89
      }
90
    },
91
    "internet_explorer_10" : {
92
      "desiredCapabilities": {
93
        "platform": "Windows 7",
94
        "browserName": "internet explorer",
95
        "version": "10"
96
      }
97
    },
98
    "android_s4_emulator": {
99
      "desiredCapabilities": {
100
        "browserName": "android",
101
        "deviceOrientation": "portrait",
102
        "deviceName": "Samsung Galaxy S4 Emulator",
103
        "version": "4.4"
104
      }
105
    },
106
    "iphone_6_simulator": {
107
      "desiredCapabilities": {
108
        "browserName": "iPhone",
109
        "deviceOrientation": "portrait",
110
        "deviceName": "iPhone 6",
111
        "platform": "OSX 10.10",
112
        "version": "8.4"
113
      }
114
    }
115
  },
116
  "local": {
117
      "launch_url": "http://localhost:3000/",
118
      "selenium_port": 4444,
119
      "selenium_host": "127.0.0.1",
120
      "silent": false,
121
      "screenshots": {
122
        "enabled": true, // if you want to keep screenshots
123
        "path": './screenshots' // save screenshots here
124
      },
125
      "globals": {
126
        "waitForConditionTimeout": 5000 // sometimes internet is slow so wait.
127
      },
128
      "desiredCapabilities": { // use Chrome as the default browser for tests
129
        "browserName": "chrome"
130
      }
131
    },
132
    "chrome": {
133
      "desiredCapabilities": {
134
        "browserName": "chrome",
135
        "javascriptEnabled": true // turn off to test progressive enhancement
136
      }
137
    }
138
}
139
module.exports = config;
140
141
/**
142
 * selenium-download does exactly what it's name suggests;
143
 * downloads (or updates) the version of Selenium (& chromedriver)
144
 * on your localhost where it will be used by Nightwatch.
145
 */
146
require('fs').stat(BINPATH + 'selenium.jar', function (err, stat) { // got it?
147
  if (err || !stat || stat.size < 1) {
148
    require('selenium-download').ensure(BINPATH, function(error) {
149
      if (error) throw new Error(error); // no point continuing so exit!
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
150
      console.log('✔ Selenium & Chromedriver downloaded to:', BINPATH);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
151
    });
152
  }
153
});
154
155
function padLeft (count) { // theregister.co.uk/2016/03/23/npm_left_pad_chaos/
156
  return count < 10 ? '0' + count : count.toString();
157
}
158
159
var FILECOUNT = 0; // "global" screenshot file count
160
/**
161
 * The default is to save screenshots to the root of your project even though
162
 * there is a screenshots path in the config object above! ... so we need a
163
 * function that returns the correct path for storing our screenshots.
164
 * While we're at it, we are adding some meta-data to the filename, specifically
165
 * the Platform/Browser where the test was run and the test (file) name.
166
 */
167
function imgpath (browser) {
168
  var a = browser.options.desiredCapabilities;
169
  var meta = [a.platform];
170
  meta.push(a.browserName ? a.browserName : 'any');
171
  meta.push(a.version ? a.version : 'any');
172
  meta.push(a.name); // this is the test filename so always exists.
173
  var metadata = meta.join('~').toLowerCase().replace(/ /g, '');
174
  return SCREENSHOT_PATH + metadata + '_' + padLeft(FILECOUNT++) + '_';
175
}
176
177
module.exports.imgpath = imgpath;
178
module.exports.SCREENSHOT_PATH = SCREENSHOT_PATH;