Skip to content

Commit ae57abf

Browse files
authored
Set display resolution trough BROWSERSTACK_DISPLAY_RESOLUTION (#44)
1 parent a8f7d4f commit ae57abf

7 files changed

Lines changed: 97 additions & 13 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
language: node_js
22
node_js:
33
- stable
4-
- '4'
4+
- '6'

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,5 +62,10 @@ Browserstack offers two APIs for browser testing:
6262
TestCafe uses the JS Testing API by default. In order to use Browserstack Automate,
6363
set the `BROWSERSTACK_USE_AUTOMATE` environment variable to `1`.
6464

65+
## Setting display resolution
66+
67+
To set the display resolution, use the `BROWSERSTACK_DISPLAY_RESOLUTION` environment variable.
68+
Valid resolutions can be found [here](https://github.com/browserstack/api#resolution).
69+
6570
## Author
6671
Developer Express Inc. (https://devexpress.com)

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "browserstack TestCafe browser provider plugin.",
55
"repository": "https://github.com/DevExpress/testcafe-browser-provider-browserstack",
66
"engines": {
7-
"node": ">=4.0.0"
7+
"node": ">=6.0.0"
88
},
99
"homepage": "https://github.com/DevExpress/testcafe-browser-provider-browserstack",
1010
"author": {
@@ -48,7 +48,7 @@
4848
"chai": "^3.5.0",
4949
"del": "^2.2.2",
5050
"execa": "^0.9.0",
51-
"gulp": "^3.9.0",
51+
"gulp": "^3.9.1",
5252
"gulp-babel": "^6.1.2",
5353
"gulp-eslint": "^3.0.1",
5454
"gulp-sequence": "^0.4.6",

src/index.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ import JSTestingBackend from './backends/js-testing';
66
import AutomateBackend from './backends/automate';
77
import BrowserProxy from './browser-proxy';
88

9-
10-
const BUILD_ID = process.env['BROWSERSTACK_BUILD_ID'];
11-
const PROJECT_NAME = process.env['BROWSERSTACK_PROJECT_NAME'];
12-
139
const ANDROID_PROXY_RESPONSE_DELAY = 500;
1410

1511
function isAutomateEnabled () {
@@ -30,6 +26,21 @@ export default {
3026
platformsInfo: [],
3127
browserNames: [],
3228

29+
_addEnvironmentPreferencesToCapabilities (capabilities) {
30+
const BUILD_ID = process.env['BROWSERSTACK_BUILD_ID'];
31+
const PROJECT_NAME = process.env['BROWSERSTACK_PROJECT_NAME'];
32+
const DISPLAY_RESOLUTION = process.env['BROWSERSTACK_DISPLAY_RESOLUTION'];
33+
34+
if (PROJECT_NAME)
35+
capabilities.project = PROJECT_NAME;
36+
37+
if (BUILD_ID)
38+
capabilities.build = BUILD_ID;
39+
40+
if (DISPLAY_RESOLUTION)
41+
capabilities.resolution = DISPLAY_RESOLUTION;
42+
},
43+
3344
_getConnector () {
3445
this.connectorPromise = this.connectorPromise
3546
.then(async connector => {
@@ -157,11 +168,7 @@ export default {
157168
pageUrl = 'http://' + browserProxy.targetHost + ':' + browserProxy.proxyPort + parsedPageUrl.path;
158169
}
159170

160-
if (PROJECT_NAME)
161-
capabilities.project = PROJECT_NAME;
162-
163-
if (BUILD_ID)
164-
capabilities.build = BUILD_ID;
171+
this._addEnvironmentPreferencesToCapabilities(capabilities);
165172

166173
capabilities.name = `TestCafe test run ${id}`;
167174
capabilities.localIdentifier = connector.connectorInstance.localIdentifierFlag;

test/mocha/browser-names-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ describe('Browser names', function () {
2727
'ie@9.0:Windows 7',
2828
'ie@10.0:Windows 8',
2929
'ie@11.0:Windows 8.1',
30-
'edge@14.0:Windows 10',
30+
'edge@15.0:Windows 10',
3131
'iPhone 6@8.3',
3232
'iPhone SE@11.2',
3333
'iPad Pro@11.2',
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
const expect = require('chai').expect;
2+
const createTestCafe = require('testcafe');
3+
4+
5+
const NULL_STREAM = { write: () => {}, end: () => {} };
6+
const LOW_RESOLUTION = '1024x768';
7+
const HIGH_RESOLUTION = '1920x1080';
8+
9+
10+
describe('Resolution Changing', function () {
11+
this.timeout(2 * 60 * 1000);
12+
13+
let testcafe = null;
14+
15+
const prevDisplayResolution = process.env.BROWSERSTACK_DISPLAY_RESOLUTION;
16+
17+
function runTest (testName) {
18+
return testcafe
19+
.createRunner()
20+
.browsers('browserstack:chrome')
21+
.src('test/mocha/data/change-resolution-fixture.js')
22+
.filter(currentTestName => currentTestName === testName)
23+
.reporter('minimal', NULL_STREAM)
24+
.run();
25+
}
26+
27+
before(function () {
28+
return createTestCafe()
29+
.then(function (tc) {
30+
testcafe = tc;
31+
});
32+
});
33+
34+
after(function () {
35+
if (prevDisplayResolution)
36+
process.env.BROWSERSTACK_DISPLAY_RESOLUTION = prevDisplayResolution;
37+
else
38+
delete process.env.BROWSERSTACK_DISPLAY_RESOLUTION;
39+
40+
return testcafe.close();
41+
});
42+
43+
it('Should change the VM display resolution according to the BROWSERSTACK_DISPLAY_RESOLUTION environment variable', function () {
44+
process.env.BROWSERSTACK_DISPLAY_RESOLUTION = LOW_RESOLUTION;
45+
46+
return runTest('Low resolution')
47+
.then(failedCount => {
48+
expect(failedCount).eql(0);
49+
50+
process.env.BROWSERSTACK_DISPLAY_RESOLUTION = HIGH_RESOLUTION;
51+
52+
return runTest('High resolution');
53+
})
54+
.then(failedCount => {
55+
expect(failedCount).eql(0);
56+
});
57+
});
58+
});
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { ClientFunction } from 'testcafe';
2+
3+
fixture `Changing resolution`
4+
.page `example.com`;
5+
6+
const getAvailWidth = ClientFunction(() => window.screen.availWidth);
7+
8+
test('Low resolution', async t => {
9+
await t.expect(getAvailWidth()).eql(1024);
10+
});
11+
12+
test('High resolution', async t => {
13+
await t.expect(getAvailWidth()).eql(1920);
14+
});

0 commit comments

Comments
 (0)