Skip to content

Commit 4b8fc5c

Browse files
authored
Merge pull request #9 from browserstack/custom_commands
Support for Custom Commands
2 parents 5b60913 + 537f52e commit 4b8fc5c

File tree

6 files changed

+88
-47
lines changed

6 files changed

+88
-47
lines changed

README.md

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,14 @@
99
- [License](#license)
1010

1111
# BrowserStack Cypress CLI
12-
You can now run your Cypress tests in BrowserStack using our browserstack-cypress-cli. BrowserStack currently supports Cypress 4 and you can start testing on the following browser combinations.
12+
You can now run your Cypress tests in BrowserStack using our `browserstack-cypress-cli`. BrowserStack currently supports Cypress 4 and you can start testing on the following browser combinations:
1313

1414

1515
| Windows 10 | OS X Mojave | OS X Catalina |
16-
|---------------------|:---------------------:|--------------------:|
17-
| chrome 66.0 to 79.0 | chrome 66.0 to 79.0 | chrome 66.0 to 79.0 |
18-
| edge 80.0 | edge 80.0 | edge 80.0 |
19-
| firefox 60.0 to 72.0| firefox 60.0 to 72.0 | firefox 60.0 to 72.0|
16+
|:---------------------:|:---------------------:|:--------------------:|
17+
| Chrome 66.0 to 79.0 | Chrome 66.0 to 79.0 | Chrome 66.0 to 79.0 |
18+
| Edge 80.0 | Edge 80.0 | Edge 80.0 |
19+
| Firefox 60.0 to 72.0| Firefox 60.0 to 72.0 | Firefox 60.0 to 72.0|
2020

2121

2222
We are actively working on supporting other browsers and will start adding other browsers to this list.
@@ -26,24 +26,26 @@ We are actively working on supporting other browsers and will start adding other
2626

2727
### Installing browserstack-cypress
2828
```bash
29-
# Install cypress(ignore if already done)
29+
# Install cypress (ignore if already done)
3030
$ npm install -g [email protected]
31-
# Install dependencies
31+
32+
# Install the BrowserStack Cypress CLI
3233
$ npm install -g browserstack-cypress-cli
3334
```
3435

3536
### Configuring your tests
3637
```bash
37-
# create a sample configuration file for configurations and capabiltiies
38+
# create a sample configuration file for configurations and capabilities
3839
$ browserstack-cypress init
3940
```
40-
This will create a sample browserstack.json file. This file can be used to configure your tests on BrowserStack. Below is the sample file that is generated for your reference.
41+
42+
This will create a sample `browserstack.json` file. This file can be used to configure your test runs on BrowserStack. Below is the sample file that is generated for your reference.
4143

4244
```json
4345
{
4446
"auth": {
45-
"username": "<username>",
46-
"access_key": "<access-key>"
47+
"username": "<your-browserstack-username>",
48+
"access_key": "<your-browserstack-access-key>"
4749
},
4850
"browsers": [
4951
{
@@ -53,30 +55,31 @@ This will create a sample browserstack.json file. This file can be used to confi
5355
}
5456
],
5557
"run_settings": {
56-
"specs": ["folder_path_with_files/*.js"],
57-
"project": "test",
58-
"customBuildName": "cypress build"
58+
"cypress_proj_dir": "/path/to/directory-that-contains-<cypress.json>-file",
59+
"project": "my first project",
60+
"customBuildName": "build 1"
5961
},
6062
"connection_settings": {
6163
"local": false
6264
}
6365
}
6466
```
6567

66-
The following table provides a reference for all the options that can be provided in browserstack.json shown above.
68+
The following table provides a reference for all the options that can be provided in `browserstack.json` shown above.
6769

6870

6971
| Option | Description | Possible values |
7072
|-----------------|---------------------------------------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------|
71-
| username | These are the BrowserStack credentials that need to be provided to run a test on BrowserStack. You can find this in your [automate dashboard](https://automate.browserstack.com/) | - |
72-
| access_key | These are the BrowserStack credentials that need to be provided to run a test on BrowserStack. You can find this in your [automate dashboard](https://automate.browserstack.com/) | - |
73-
| os (case-sensitive) | The operating system in which you want to run your test. | The following three strings are supported."OS X Mojave" , "OS X Catalina", "Windows 10" |
74-
| browser (case-sensitive) | The browser in which you want to run your tests on. | Right now only "chrome", "firefox", and "edge" are supported. We are actively working on supporting other browsers. |
75-
| versions | A list of browser versions that you need to run your tests on | Example: To run on versions 69, 67 and 65 provide ["69", "67", "65"]. Right now edge 80 and all chrome versions from 66 to 78 are supported |
76-
| specs | The path to the spec files that need to be run on BrowserStack | Takes a list of strings that point to location of the spec files |
77-
| project | Name of the project | A string providing the name of the project |
78-
| customBuildName | Helps in providing a custom name for the build | A string providing the name of the build |
79-
| local(boolean: true/false) | Helps in testing websites that cannot be accessed in public network | Set this to true if you need to test a local website. Set this to false if the website is accessible publically. |
73+
| `username` | This is your BrowserStack username. You can find this in your [Automate dashboard](https://automate.browserstack.com/) | - |
74+
| `access_key` | This is your BrowserStack access key. You can find this in your [Automate dashboard](https://automate.browserstack.com/) | - |
75+
| `os` <br/> (_case-sensitive_) | The operating system on which you want to run your test. | `OS X Mojave`, <br/> `OS X Catalina`, and <br/> `Windows 10` |
76+
| `browser` <br/> (case-sensitive) | The browser on which you want to run your tests. | `chrome`, <br/> `firefox`, and <br/> `edge` |
77+
| `versions` | A list of browser versions that you want to run your tests on. <br/><br/> **Example:** To run on versions 69, 67 and 65 provide `["69", "67", "65"]` | Right now edge 80 and all chrome versions from 66 to 78 are supported |
78+
| `specs` <br/> (_deprecated_) | This param is deprecated in favour of a more complete `cypress_proj_dir` param. The path to the spec files that need to be run on BrowserStack | Takes a list of strings that point to location of the spec files |
79+
| `cypress_proj_dir` | Path to the folder which contains `cypress.json` file. This path will be considered as the root path of the project. |- |
80+
| `project` | Name of your project. This will be displayed in your Automate dashboard, and you'll be able to search & filter your tests based on the project name. | A string providing the name of the project |
81+
| `customBuildName` | Helps in providing a custom name for the build. This will be displayed in your Automate dashboard, and you'll be able to search & filter your tests based on the build name. | A string providing the name of the build |
82+
| `local` | Helps in testing websites that cannot be accessed in public network. If you set this to `true`, please download the Local binary and establish a local connection first (you can learn how to do so [here](https://www.browserstack.com/local-testing/automate#command-line)) | Boolean: `true` / `false`. Set this to `true` if you need to test a local website. Set this to `false` if the website is accessible publicly. |
8083

8184
### Running the tests
8285
You can start running your test build using the following command.
@@ -85,7 +88,7 @@ You can start running your test build using the following command.
8588
$ browserstack-cypress run
8689
```
8790

88-
Output :
91+
Sample output :
8992

9093
```bash
9194
[2/20/2020, 2:58:31 PM] Reading browserstack.json from /browserstack.json
@@ -97,7 +100,9 @@ Output :
97100
[2/20/2020, 2:58:34 PM] Test suite: bs://15f90b540b8cbc47929782f35bb7db20fe1c4709
98101
[2/20/2020, 2:58:34 PM] Local is set to: false
99102
[2/20/2020, 2:58:34 PM] Build name is: cypress build
103+
[2/20/2020, 2:58:34 PM] Success
100104
[2/20/2020, 2:58:36 PM] Build created with build id: 06f28ce423d10314b32e98bb6f68e10b0d02a49a
105+
[2/20/2020, 2:58:36 PM] File deleted successfully.
101106
```
102107

103108
### Getting build information
@@ -175,19 +180,18 @@ Output:
175180
}
176181
```
177182

178-
**Note** that individual version represents a session. It is advised to validate your account's parallel before running multiple versions.
183+
**Note:** Each browser version represents a session. It is advised to validate your account's parallel limit before running multiple versions.
179184

180185
### Limitations
181186

182187
- `exec` and `task` are not allowed.
183-
- `baseUrl` is not supported at the moment.
184-
- Environment variables and configuration files are not supported yet.
185-
- While using local, please make sure to create /etc/hosts entry pointing to a URL. The `localhost` is not working at the moment.
188+
- While using local, please make sure to create `/etc/hosts` entry pointing to some URL, and use that URL in the tests. The `localhost` URI doesn't work at the moment.
189+
- Installing custom npm packages are not supported at this moment.
186190

187191
# Accessing test results
188192

189193
You can access your test results in [BrowserStack Automate dashboard](https://automate.browserstack.com/). The dashboard provides test details along with video, console logs and screenshots to help you debug any issues.
190194

191195
# License
192196

193-
This project is released under MIT License. Please refer the [LICENSE.md](LICENSE.md) for more detail.
197+
This project is released under MIT License. Please refer the [LICENSE.md](LICENSE.md) for more details.

bin/commands/runs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ function runCypress(args) {
2121
capabilityHelper.validate(bsConfig).then(function (validated) {
2222
logger.log(validated);
2323
// Archive the spec files
24-
archiver.archive(bsConfig.run_settings.specs, config.fileName).then(function (data) {
24+
archiver.archive(bsConfig.run_settings, config.fileName).then(function (data) {
2525
// Uploaded zip file
2626
zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
2727
// Create build

bin/helpers/archiver.js

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11

2-
var fs = require('fs');
3-
var archiver = require('archiver');
4-
var request = require('request')
5-
var config = require('./config');
6-
var logger = require("./logger")
2+
const fs = require('fs'),
3+
archiver = require('archiver'),
4+
logger = require("./logger");
75

8-
9-
const archiveSpecs = (specs, filePath) => {
6+
const archiveSpecs = (runSettings, filePath) => {
107
return new Promise(function (resolve, reject) {
118
var output = fs.createWriteStream(filePath);
129

10+
var cypressFolderPath = runSettings.cypress_proj_dir
11+
1312
var archive = archiver('zip', {
1413
zlib: { level: 9 } // Sets the compression level.
1514
});
@@ -36,10 +35,7 @@ const archiveSpecs = (specs, filePath) => {
3635

3736
archive.pipe(output);
3837

39-
specs.forEach(function (item, index) {
40-
logger.log("Adding " + item + " to zip");
41-
archive.glob(item);
42-
});
38+
archive.directory(cypressFolderPath, false);
4339

4440
archive.finalize();
4541
});

bin/helpers/capabilityHelper.js

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
var logger = require("./logger");
2-
const Constants = require('./constants');
1+
const logger = require("./logger"),
2+
Constants = require('./constants'),
3+
glob = require("glob");
34

45
const caps = (bsConfig, zip) => {
56
return new Promise(function (resolve, reject) {
@@ -67,12 +68,51 @@ const validate = (bsConfig) => {
6768

6869
if (!bsConfig.run_settings) reject(Constants.validationMessages.EMPTY_RUN_SETTINGS);
6970

70-
if(!bsConfig.run_settings.specs || bsConfig.run_settings.specs.length === 0) reject(Constants.validationMessages.EMPTY_SPEC_FILES);
71+
if(!bsConfig.run_settings.cypress_proj_dir) reject(Constants.validationMessages.EMPTY_SPEC_FILES);
72+
73+
if(invalidFiles(bsConfig.run_settings.cypress_proj_dir)) reject(Constants.validationMessages.INVALID_EXTENSION);
7174

7275
resolve(Constants.validationMessages.VALIDATED);
7376
});
7477
}
7578

79+
const invalidFiles = (testFolder)=> {
80+
var options = {
81+
dot: true
82+
}
83+
files = glob.sync(testFolder + "/**/*", options)
84+
var invalidFiles = []
85+
files.forEach(file => {
86+
if(isHiddenPath(file) || invalidExtension(file)){
87+
invalidFiles.push(file)
88+
}
89+
});
90+
91+
if(invalidFiles.length > 0) {
92+
logger.log("These files are not valid: " + invalidFiles.toString())
93+
return true
94+
} else {
95+
return false
96+
}
97+
}
98+
99+
var isHiddenPath = (path) => {
100+
return (/(^|\/)\.[^\/\.]/g).test(path);
101+
};
102+
103+
var invalidExtension = (file) => {
104+
let ext = file.split('.').pop();
105+
if (isFile(file) && !["js", "json", "txt"].includes(ext)) {
106+
return true;
107+
}
108+
109+
return false;
110+
}
111+
112+
var isFile = (path) => {
113+
return path.split('/').pop().indexOf('.') > -1;
114+
}
115+
76116
module.exports = {
77117
caps,
78118
validate

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const validationMessages = {
2020
EMPTY_RUN_SETTINGS: "Empty run settings",
2121
EMPTY_SPEC_FILES: "No spec files specified in run_settings",
2222
VALIDATED: "browserstack.json file is validated",
23-
NOT_VALID: "browerstack.json is not valid"
23+
NOT_VALID: "browerstack.json is not valid",
24+
INVALID_EXTENSION: "Invalid files, please remove these files and try again."
2425
};
2526
const cliMessages = {
2627
VERSION: {

bin/templates/configTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ module.exports = function () {
1212
}
1313
],
1414
"run_settings": {
15-
"specs": ["folder_path_with_files/*.js"],
15+
"cypress_proj_dir" : "/path/to/cypress.json",
1616
"project": "project-name",
1717
"customBuildName": "build-name"
1818
},

0 commit comments

Comments
 (0)