Skip to content

Commit

Permalink
native click and type [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
kuceb committed Dec 6, 2018
1 parent 913ccac commit 9bc2ff7
Show file tree
Hide file tree
Showing 10 changed files with 1,181 additions and 1,128 deletions.
568 changes: 314 additions & 254 deletions packages/driver/src/cy/commands/actions/click.js

Large diffs are not rendered by default.

186 changes: 102 additions & 84 deletions packages/driver/src/cy/commands/actions/type.js

Large diffs are not rendered by default.

666 changes: 387 additions & 279 deletions packages/driver/src/cypress/UsKeyboardLayout.js

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions packages/driver/src/cypress/cy.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ create = (specWindow, Cypress, Cookies, state, config, log) ->
contentWindow.HTMLElement.prototype.focus = (focusOption) ->
focused.interceptFocus(this, contentWindow, focusOption)

contentWindow.HTMLInputElement.prototype.select = ->
$selection.interceptSelect.call(this)
## no longer needed since we no longer keep state on cy.type
# contentWindow.HTMLInputElement.prototype.select = ->
# $selection.interceptSelect.call(this)

contentWindow.document.hasFocus = ->
top.document.hasFocus()
Expand Down
501 changes: 142 additions & 359 deletions packages/driver/src/cypress/keyboard.js

Large diffs are not rendered by default.

90 changes: 39 additions & 51 deletions packages/driver/src/cypress/native_events.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const Promise = require('bluebird')
const elements = require('../dom/elements')

// eslint-disable-next-line
window.criRequest = function () {}
window.criRequest = function() {}

let client

Expand All @@ -29,43 +29,44 @@ const init = () => {
.then((cri_client) => {
client = cri_client
})
.catch(() => { })
.catch(() => {})
})
}

const click = ($elToClick, coords) => {
return init()
.then(() => {
const { coordsFromAutIframe, autIframe } = calculateAutIframeCoords(coords, $elToClick)
const click = ($elToClick, coords, modifiers) => {
return init().then(() => {
const { coordsFromAutIframe, autIframe } = calculateAutIframeCoords(
coords,
$elToClick
)
// TODO: import Cypress correctly
// eslint-disable-next-line
Cypress.action('cy:before:native:event', coordsFromAutIframe)
const coordsToClick = calculateCoordsToClick(coordsFromAutIframe, autIframe)

return Promise.all([
mouseMoved(coordsToClick),
mouseDown(coordsToClick),
mouseUp(coordsToClick),
])
.finally(() => {
mouseMoved(coordsToClick, modifiers),
mouseDown(coordsToClick, modifiers),
mouseUp(coordsToClick, modifiers),
]).finally(() => {
// TODO: import Cypress correctly
// eslint-disable-next-line
Cypress.action('cy:after:native:event')
})
})
}

const mouseMoved = (coords) => {
return mouseEvent(coords, 'mouseMoved')
const mouseMoved = (coords, modifiers) => {
return mouseEvent(coords, 'mouseMoved', modifiers)
}
const mouseDown = (coords) => {
return mouseEvent(coords, 'mousePressed')
const mouseDown = (coords, modifiers) => {
return mouseEvent(coords, 'mousePressed', modifiers)
}
const mouseUp = (coords) => {
return mouseEvent(coords, 'mouseReleased')
const mouseUp = (coords, modifiers) => {
return mouseEvent(coords, 'mouseReleased', modifiers)
}

const mouseEvent = (coords, type) => {
const mouseEvent = (coords, type, modifiers) => {
const { x, y } = coords

return client.send('Input.dispatchMouseEvent', {
Expand All @@ -74,19 +75,13 @@ const mouseEvent = (coords, type) => {
type,
button: 'left',
clickCount: 1,
modifiers,
})
}

const keypress = (keyInfo) => {

return init()
.then(() => {
return Promise.all([
keyDown(keyInfo),
keyUp(keyInfo),
]).then(() => {
console.log('keypress')
})
return init().then(() => {
return Promise.all([keyDown(keyInfo), keyUp(keyInfo)])
})
}

Expand All @@ -95,34 +90,29 @@ function keypressAll (keyInfoArray) {
return Promise.all(
_.flatten(
keyInfoArray.map((keyInfo) => {
return [
keyDown(keyInfo),
keyUp(keyInfo),
]
return [keyDown(keyInfo), keyUp(keyInfo)]
})
)
).then(() => {
console.log('keypressAll')
})
)
})
}

const keyDown = (keyInfo) => {
return Promise.resolve(client.send('Input.dispatchKeyEvent', {
// type: text ? 'keyDown' : 'rawKeyDown',
type: keyInfo.text ? 'keyDown' : 'rawKeyDown',
// modifiers: this._modifiers,
windowsVirtualKeyCode: keyInfo.keyCode,
code: keyInfo.code,
key: keyInfo.key,
text: keyInfo.text,
// unmodifiedText: text,
// autoRepeat,
location: keyInfo.location,
isKeypad: keyInfo.location === 3,
}).then(() => {
return console.log('keydown')
}))
return Promise.resolve(
client.send('Input.dispatchKeyEvent', {
// type: text ? 'keyDown' : 'rawKeyDown',
type: keyInfo.text ? 'keyDown' : 'rawKeyDown',
modifiers: keyInfo.modifiers,
windowsVirtualKeyCode: keyInfo.keyCode,
code: keyInfo.code,
key: keyInfo.key,
text: keyInfo.text,
// unmodifiedText: text,
// autoRepeat,
location: keyInfo.location,
isKeypad: keyInfo.location === 3,
})
)
}

const keyUp = (keyInfo) => {
Expand All @@ -138,8 +128,6 @@ const keyUp = (keyInfo) => {
// autoRepeat,
location: keyInfo.location,
isKeypad: keyInfo.location === 3,
}).then(() => {
return console.log('keyup')
})
}

Expand Down
14 changes: 12 additions & 2 deletions packages/driver/src/dom/elements.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ fixedOrStickyRe = /(fixed|sticky)/
focusable = "body,a[href],link[href],button,select,[tabindex],input,textarea,[contenteditable]"

inputTypeNeedSingleValueChangeRe = /^(date|time|month|week|datetime|datetime-local)$/
canSetSelectionRangeElementRe = /^(text|search|URL|tel|password)$/

canSetSelectionRangeElementRe = /^(text|search|url|tel|password)$/

## TODO: enable for ie
canSetSelectionRangeOnNumberInput = false
canSetSelectionRangeOnNumberInputElementRe = /^(text|search|url|tel|password|number)$/

## rules for native methods and props
## if a setter or getter or function then add a native method
Expand Down Expand Up @@ -126,6 +131,7 @@ nativeGetters = {
type: _getType
frameElement: Object.getOwnPropertyDescriptor(window, "frameElement").get
activeElement: descriptor("Document", "activeElement").get
'nodeListLength': descriptor("NodeList", "length").get
}

nativeSetters = {
Expand Down Expand Up @@ -200,7 +206,11 @@ isNeedSingleValueChangeInputElement = (el) ->
return inputTypeNeedSingleValueChangeRe.test(el.type)

canSetSelectionRangeElement = (el) ->
isTextarea(el) or (isInput(el) and canSetSelectionRangeElementRe.test(getNativeProp(el, 'type')))
if canSetSelectionRangeOnNumberInput
return isTextarea(el) or (isInput(el) and canSetSelectionRangeOnNumberInputElementRe.test(getNativeProp(el, 'type')))

return isTextarea(el) or (isInput(el) and canSetSelectionRangeElementRe.test(getNativeProp(el, 'type')))


getTagName = (el) ->
tagName = el.tagName or ""
Expand Down
Loading

0 comments on commit 9bc2ff7

Please sign in to comment.