Skip to content

Commit bf39d22

Browse files
authored
Merge pull request #14 from gemini-testing/hide-caret
feat: click in facke input to hide caret
2 parents 280ec0d + ce4f41e commit bf39d22

File tree

2 files changed

+93
-8
lines changed

2 files changed

+93
-8
lines changed

lib/index.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,24 @@ const browserCommands = require('./commands');
77
module.exports = (hermione, opts) => {
88
const pluginConfig = parseConfig(opts);
99

10-
if (!pluginConfig.enabled || !hermione.isWorker()) {
10+
if (!pluginConfig.enabled) {
11+
return;
12+
}
13+
14+
if (!hermione.isWorker()) {
15+
hermione.on(hermione.events.SESSION_START, async (browser, {browserId}) => {
16+
// Clicking into the fake input before tests started
17+
// to fix bug with caret-color https://bugs.webkit.org/show_bug.cgi?id=228859
18+
if (Object.keys(pluginConfig.browsers).includes(browserId)) {
19+
await browser.execute(function() {
20+
const input = document.createElement('input');
21+
input.setAttribute('type', 'text');
22+
document.body.append(input);
23+
input.focus();
24+
});
25+
}
26+
});
27+
1128
return;
1229
}
1330

test/lib/index.js

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const commands = require('lib/commands');
77
const {mkConfig_, mkBrowser_} = require('../utils');
88

99
describe('plugin', () => {
10+
let initialDocument;
1011
const mkHermione_ = (opts = {}) => {
1112
opts = _.defaults(opts, {
1213
proc: 'master',
@@ -15,7 +16,7 @@ describe('plugin', () => {
1516

1617
const hermione = new EventEmitter();
1718

18-
hermione.events = {NEW_BROWSER: 'newBrowser'};
19+
hermione.events = {NEW_BROWSER: 'newBrowser', SESSION_START: 'sessionStart'};
1920
hermione.isWorker = sinon.stub().returns(opts.proc === 'worker');
2021
hermione.config = {
2122
forBrowser: (id) => opts.browsers[id] || {desiredCapabilities: {}}
@@ -28,9 +29,21 @@ describe('plugin', () => {
2829
Object.keys(commands).forEach((command) => {
2930
commands[command] = sinon.stub();
3031
});
32+
33+
global.document = {
34+
createElement: sinon.stub(),
35+
body: {
36+
append: sinon.stub()
37+
}
38+
};
39+
40+
initialDocument = global.document;
3141
});
3242

33-
afterEach(() => sinon.restore());
43+
afterEach(() => {
44+
sinon.restore();
45+
global.document = initialDocument;
46+
});
3447

3548
it('should do nothing if plugin is disabled', () => {
3649
const hermione = mkHermione_();
@@ -42,17 +55,72 @@ describe('plugin', () => {
4255
});
4356

4457
describe('master process', () => {
45-
it('should do nothing', () => {
46-
const hermione = mkHermione_({proc: 'master'});
47-
sinon.spy(hermione, 'on');
58+
describe('"SESSION_START" event', () => {
59+
it('should create fake input and focus on it for plugin browsers', () => {
60+
const hermione = mkHermione_({proc: 'master'});
61+
62+
plugin(hermione, mkConfig_({
63+
browsers: {
64+
b1: {
65+
commands: []
66+
}
67+
}
68+
}));
4869

49-
plugin(hermione, mkConfig_());
70+
const fakeInput = {
71+
setAttribute: sinon.stub(),
72+
focus: sinon.stub()
73+
};
74+
global.document.createElement.returns(fakeInput);
75+
76+
const browser = mkBrowser_();
77+
browser.execute.callsFake(() => {
78+
browser.execute.firstCall.args[0]();
79+
});
80+
81+
hermione.emit(hermione.events.SESSION_START, browser, {browserId: 'b1'});
82+
83+
assert.calledWith(document.createElement, 'input');
84+
assert.calledWith(fakeInput.setAttribute, 'type', 'text');
85+
assert.calledWith(document.body.append, fakeInput);
86+
assert.callOrder(fakeInput.setAttribute, global.document.body.append, fakeInput.focus);
87+
});
5088

51-
assert.notCalled(hermione.on);
89+
it('should not create fake input for not plugin browsers', () => {
90+
const hermione = mkHermione_({proc: 'master'});
91+
92+
plugin(hermione, mkConfig_({
93+
browsers: {
94+
b1: {
95+
commands: []
96+
}
97+
}
98+
}));
99+
const browser = mkBrowser_();
100+
101+
hermione.emit(hermione.events.SESSION_START, browser, {browserId: 'b2'});
102+
103+
assert.notCalled(browser.execute);
104+
});
52105
});
53106
});
54107

55108
describe('worker process', () => {
109+
it('should not subscribe on "SESSION_START" event', () => {
110+
const hermione = mkHermione_({proc: 'worker'});
111+
sinon.spy(hermione, 'on');
112+
113+
plugin(hermione, mkConfig_({
114+
browsers: {
115+
b1: {
116+
commands: []
117+
}
118+
}
119+
}));
120+
121+
assert.calledOnceWith(hermione.on, hermione.events.NEW_BROWSER);
122+
});
123+
56124
describe('"NEW_BROWSER" event', () => {
57125
it('should throws if passed command is not implemented', () => {
58126
const hermione = mkHermione_({proc: 'worker'});

0 commit comments

Comments
 (0)