Skip to content
This repository has been archived by the owner on Nov 24, 2018. It is now read-only.

Implement mouseover #420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,14 @@ export default class Chromeless<T extends any> implements Promise<T> {
return this
}

mouseup(selector: string): Chromeless<T> {
this.queue.enqueue({ type: 'mouseup', selector })
mouseover(selector: string): Chromeless<T> {
this.queue.enqueue({ type: 'mouseover', selector })
return this
}

mouseover(): Chromeless<T> {
throw new Error('Not implemented yet')
mouseup(selector: string): Chromeless<T> {
this.queue.enqueue({ type: 'mouseup', selector })
return this
}

scrollTo(x: number, y: number): Chromeless<T> {
Expand Down
26 changes: 26 additions & 0 deletions src/chrome/local-runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
getAllCookies,
version,
mousedown,
mouseover,
mouseup,
focus,
clearInput,
Expand Down Expand Up @@ -113,6 +114,8 @@ export default class LocalRuntime {
return this.setCookies(command.nameOrCookies, command.value)
case 'mousedown':
return this.mousedown(command.selector)
case 'mouseover':
return this.mouseover(command.selector)
case 'mouseup':
return this.mouseup(command.selector)
case 'focus':
Expand Down Expand Up @@ -245,6 +248,29 @@ export default class LocalRuntime {
this.log(`Mousedown on ${selector}`)
}

private async mouseover(selector: string): Promise<void> {
if (this.chromelessOptions.implicitWait) {
this.log(`mouseover(): Waiting for ${selector}`)
await waitForNode(
this.client,
selector,
this.chromelessOptions.waitTimeout,
)
}

const exists = await nodeExists(this.client, selector)
if (!exists) {
throw new Error(
`mouseover(): node for selector ${selector} doesn't exist`,
)
}

const { scale } = this.chromelessOptions.viewport
await mouseover(this.client, selector, scale)
this.log(`Mouseover on ${selector}`)
}


private async mouseup(selector: string): Promise<void> {
if (this.chromelessOptions.implicitWait) {
this.log(`mouseup(): Waiting for ${selector}`)
Expand Down
4 changes: 4 additions & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,10 @@ export type Command =
type: 'mousedown'
selector: string
}
| {
type: 'mouseover'
selector: string
}
| {
type: 'mouseup'
selector: string
Expand Down
19 changes: 19 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,25 @@ export async function mousedown(
})
}

export async function mouseover(
client: Client,
selector: string,
scale: number,
) {
const clientRect = await getClientRect(client, selector)
const { Input } = client

const options = {
x: Math.round((clientRect.left + clientRect.width / 2) * scale),
y: Math.round((clientRect.top + clientRect.height / 2) * scale),
}

await Input.dispatchMouseEvent({
...options,
type: 'mouseMoved',
})
}

export async function mouseup(client: Client, selector: string, scale: number) {
const clientRect = await getClientRect(client, selector)
const { Input } = client
Expand Down