Skip to content

Commit

Permalink
[skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb committed Sep 5, 2018
1 parent 9d581fd commit 2aa35bd
Show file tree
Hide file tree
Showing 5 changed files with 122 additions and 34 deletions.
1 change: 1 addition & 0 deletions packages/driver/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"chai": "3.5.0",
"chai-as-promised": "6.0.0",
"chokidar-cli": "^1.2.0",
"chrome-remote-interface": "^0.26.1",
"clone": "^2.1.1",
"compression": "^1.1.0",
"cors": "^2.7.1",
Expand Down
68 changes: 36 additions & 32 deletions packages/driver/src/cy/commands/actions/click.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ $utils = require("../../../cypress/utils")
$elements = require("../../../dom/elements")
$selection = require("../../../dom/selection")
$actionability = require("../../actionability")
$native = require("../../../cypress/native_events")

module.exports = (Commands, Cypress, cy, state, config) ->
Commands.addAll({ prevSubject: "element" }, {
Expand Down Expand Up @@ -155,38 +156,41 @@ module.exports = (Commands, Cypress, cy, state, config) ->

el = $elToClick.get(0)

domEvents.mouseDown = $Mouse.mouseDown($elToClick, coords.fromViewport)

## if mousedown was cancelled then or caused
## our element to be removed from the DOM
## just resolve after mouse down and dont
## send a focus event
if domEvents.mouseDown.preventedDefault or not $dom.isAttached($elToClick)
afterMouseDown($elToClick, coords)
else
if $elements.isInput(el) or $elements.isTextarea(el) or $elements.isContentEditable(el)
if !$elements.isNeedSingleValueChangeInputElement(el)
$selection.moveSelectionToEnd(el)

## retrieve the first focusable $el in our parent chain
$elToFocus = $elements.getFirstFocusableEl($elToClick)

if cy.needsFocus($elToFocus, $previouslyFocused)
cy.fireFocus($elToFocus.get(0))

## if we are currently trying to focus
## the body then calling body.focus()
## is a noop, and it will not blur the
## current element, which is all so wrong
if $elToFocus.is("body")
$focused = cy.getFocused()

## if the current focused element hasn't changed
## then blur manually
if $elements.isSame($focused, $previouslyFocused)
cy.fireBlur($focused.get(0))

afterMouseDown($elToClick, coords)
return $native.mousedown(coords.fromViewport)
.then(()=>$native.mouseup(coords.fromViewport))

# domEvents.mouseDown = $Mouse.mouseDown($elToClick, coords.fromViewport)

# ## if mousedown was cancelled then or caused
# ## our element to be removed from the DOM
# ## just resolve after mouse down and dont
# ## send a focus event
# if domEvents.mouseDown.preventedDefault or not $dom.isAttached($elToClick)
# afterMouseDown($elToClick, coords)
# else
# if $elements.isInput(el) or $elements.isTextarea(el) or $elements.isContentEditable(el)
# if !$elements.isNeedSingleValueChangeInputElement(el)
# $selection.moveSelectionToEnd(el)

# ## retrieve the first focusable $el in our parent chain
# $elToFocus = $elements.getFirstFocusableEl($elToClick)

# if cy.needsFocus($elToFocus, $previouslyFocused)
# cy.fireFocus($elToFocus.get(0))

# ## if we are currently trying to focus
# ## the body then calling body.focus()
# ## is a noop, and it will not blur the
# ## current element, which is all so wrong
# if $elToFocus.is("body")
# $focused = cy.getFocused()

# ## if the current focused element hasn't changed
# ## then blur manually
# if $elements.isSame($focused, $previouslyFocused)
# cy.fireBlur($focused.get(0))

# afterMouseDown($elToClick, coords)
})
.catch (err) ->
## snapshot only on click failure
Expand Down
81 changes: 81 additions & 0 deletions packages/driver/src/cypress/native_events.js
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,
}
2 changes: 1 addition & 1 deletion packages/launcher/lib/browsers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const browsers: Browser[] = [
displayName: 'Chrome',
versionRegex: /Google Chrome (\S+)/,
profile: true,
binary: 'google-chrome'
binary: 'google-chrome-beta'
},
{
name: 'chromium',
Expand Down
4 changes: 3 additions & 1 deletion packages/server/lib/browsers/chrome.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -185,8 +185,10 @@ module.exports = {
## by being the last one
args.push("--user-data-dir=#{userDir}")
args.push("--disk-cache-dir=#{cacheDir}")
## TODO: make this a dynamic port
args.push("--remote-debugging-port=9222")

debug("launch in chrome: %s, %s", url, args)

utils.launch(browserName, url, args)
}

0 comments on commit 2aa35bd

Please sign in to comment.