diff --git a/packages/driver/package.json b/packages/driver/package.json index a59c80afb945..b0c1ccce352a 100644 --- a/packages/driver/package.json +++ b/packages/driver/package.json @@ -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", diff --git a/packages/driver/src/cy/commands/actions/click.coffee b/packages/driver/src/cy/commands/actions/click.coffee index 42196b900f1d..b0a1833c403e 100644 --- a/packages/driver/src/cy/commands/actions/click.coffee +++ b/packages/driver/src/cy/commands/actions/click.coffee @@ -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" }, { @@ -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 diff --git a/packages/driver/src/cypress/native_events.js b/packages/driver/src/cypress/native_events.js new file mode 100644 index 000000000000..5535fdf684c7 --- /dev/null +++ b/packages/driver/src/cypress/native_events.js @@ -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, +} diff --git a/packages/launcher/lib/browsers.ts b/packages/launcher/lib/browsers.ts index a87254005e72..25e4e9091693 100644 --- a/packages/launcher/lib/browsers.ts +++ b/packages/launcher/lib/browsers.ts @@ -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', diff --git a/packages/server/lib/browsers/chrome.coffee b/packages/server/lib/browsers/chrome.coffee index 5e41ce0e1aaa..a15bbad62788 100644 --- a/packages/server/lib/browsers/chrome.coffee +++ b/packages/server/lib/browsers/chrome.coffee @@ -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) }