-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
122 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
console.log('native events ') | ||
const _ = require('lodash') | ||
|
||
const CRI = require('chrome-remote-interface') | ||
console.log('loaded CRI') | ||
const Promise = require('bluebird') | ||
const debug = require('debug')('cypress:driver') | ||
let client | ||
|
||
const init = () => { | ||
debug('native init') | ||
console.log('native init') | ||
Promise.try(() => { | ||
if (client) return | ||
return CRI.List() | ||
.then((targets) => { | ||
// activate the first available id | ||
console.log(targets) | ||
|
||
// find the first target page that's a real tab | ||
// and not the dev tools | ||
const target = _.find(targets, (t) => { | ||
return t.type === 'page' && t.url.startsWith('http') | ||
}) | ||
|
||
console.log('target is', target) | ||
|
||
return CRI({ target }, (newClient) => client = newClient) | ||
}) | ||
}) | ||
} | ||
|
||
|
||
const mousedown = (coords) => { | ||
|
||
const x = coords.x + coords.width / 2 | ||
const y = coords.y + coords.height / 2 | ||
|
||
return init() | ||
.then(() => { | ||
return client.send('Input.dispatchMouseEvent', { | ||
x, | ||
y, | ||
type: 'mouseMoved', | ||
}) | ||
}) | ||
|
||
.then(() => { | ||
return client.send('Input.dispatchMouseEvent', { | ||
x, | ||
y, | ||
type: 'mousePressed', | ||
button: 'left', | ||
clickCount: 1, | ||
}) | ||
}) | ||
} | ||
|
||
const mouseup = (coords) => { | ||
|
||
const x = coords.x + coords.width / 2 | ||
const y = coords.y + coords.height / 2 | ||
|
||
return init() | ||
.then(() => { | ||
return client.send('Input.dispatchMouseEvent', { | ||
x, | ||
y, | ||
type: 'mouseReleased', | ||
button: 'left', | ||
clickCount: 1, | ||
}) | ||
}) | ||
|
||
|
||
} | ||
console.log('export') | ||
module.exports = { | ||
mousedown, | ||
mouseup, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters