Skip to content

Commit

Permalink
small fixes and add to element API
Browse files Browse the repository at this point in the history
  • Loading branch information
potapovDim committed Nov 10, 2018
1 parent aaa3368 commit 9c18626
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 23 deletions.
10 changes: 10 additions & 0 deletions __specs__/integration/chrome/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,16 @@ describe('client chrome', () => {
expect(await link.isDisplayed()).to.eql(true)
})

it('getComputedStyle', async () => {
const file = 'appear'
const clicker = element('#test_button')
const link = element('a').waitForElement(1700)
await client.goTo(pathResolver(file))
await clicker.click()
expect(await link.isDisplayed()).to.eql(true)
expect(await link.getComputedStyle(link.computedStyleList.color)).to.eq('rgb(0, 0, 0)')
})

it('disappear', async () => {
const file = 'disappear'
const clicker = element('#test_button')
Expand Down
7 changes: 7 additions & 0 deletions __specs__/spec_utils/appear.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
<head>
<meta charset="UTF-8">
<title>Appear file</title>
<style>
a {
text-align: right;
background: red;
width: 400px;
}
</style>
</head>

<body>
Expand Down
9 changes: 2 additions & 7 deletions lib/core/executeScript.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
const getLocalEnv = require('./env')

const {baseOptions, urlPathes} = getLocalEnv()
const {baseOptions, urlPathes} = getLocalEnv()

const {assertArray, assertObject, assertFunction, assertString, assertNumber} = require('../util')

module.exports = function(request) {
return async function(sessionId, script, args = [], options) {

if(assertFunction(script)) {
script = `const args = Array.prototype.slice.call(arguments,0)
return ${script.toString()}.apply(window, args)`
Expand All @@ -16,13 +15,9 @@ module.exports = function(request) {
args = [args]
}
}

if(!options) options = {...baseOptions}

const {body} = await request.post(urlPathes.executeSync(sessionId), JSON.stringify({
script,
args
}), options)
const {body} = await request.post(urlPathes.executeSync(sessionId), JSON.stringify({script, args}), options)


return body
Expand Down
12 changes: 7 additions & 5 deletions lib/element.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,18 @@ export declare class ElementAWB {
constructor(selector: string, sessionId: string | null, elementId: string | null, baseElement: ElementAWB)

util: IElementUtil
computedStyleList: object
getComputedStyle: (computedStyleName: string) => string
waitForElement: (time: number) => ElementAWB
waitForClickable: (time: number) => ElementAWB
waitForElementVisible: (time: number) => ElementAWB
waitForElementPresent: (time: number) => ElementAWB
waitUntilDisappear: (time: number) => Promise<void>
waitTextContains: (text: string, time: number) => ElementAWB
wait: (time: number, cb: Promise<any>) => ElementAWB
size(): Promise<{ width: number, height: number }>
location(): Promise<{ x: number, y: number }>
locationView(): Promise<{ x: number, y: number }>
size(): Promise<{width: number, height: number}>
location(): Promise<{x: number, y: number}>
locationView(): Promise<{x: number, y: number}>
clear(): Promise<any>
getElementHTML(): Promise<string>
getColor(): Promise<string>
Expand All @@ -62,8 +64,8 @@ export declare class ElementAWB {
toElement(): Promise<any>
isDisplayed(): Promise<boolean>
isPresent(): Promise<boolean>
getRect(): Promise<{ width: number, heigth: number, x: number, y: number }>
mouseDownAndMove(position: { x: number, y: number }): Promise<any>
getRect(): Promise<{width: number, heigth: number, x: number, y: number}>
mouseDownAndMove(position: {x: number, y: number}): Promise<any>
}


Expand Down
22 changes: 13 additions & 9 deletions lib/element.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ const {InterfaceError} = require('./interfaceError')
const {callWithWrap} = require('./callWrapper')
const {initElement} = require('./byStrategy')
const {GetElementUtils} = require('./elementUtil')
const {
waitEl,
waitPresent,
waitClicable,
waitVisible,
waitText,
waitEls,
getThisWrapperProxy
} = require('./proxySubCalls')
const {waitEl, waitPresent, waitClicable, waitVisible, waitText, waitEls, getThisWrapperProxy} = require('./proxySubCalls')

const {computedStyleList, pseudoClassesList} = require('./computedStyleList')

const proxyActions = [
'get',
Expand Down Expand Up @@ -43,6 +37,7 @@ function elementsInitializer(requests, client) {
this.elementId = elementId
this.baseElement = baseElement
this.util = new GetElementUtils(client, this)
this.computedStyleList = computedStyleList
}

element(...args) {
Expand Down Expand Up @@ -259,6 +254,14 @@ function elementsInitializer(requests, client) {
this.elementId = driverResp.ELEMENT; return
}

async getComputedStyle(computedStyleName) {
if(this.subCall) {await this.subCall(); this.subCall = null}
if(!this.elementId) {await this.getThisElement()}
return callWithWrap.call(
this, executeScript, 'return window.getComputedStyle(arguments[0])[arguments[1]]',
[toElementObject(this.elementId), computedStyleName])
}

async getElementHTML() {
if(this.subCall) {await this.subCall(); this.subCall = null}
if(!this.elementId) {await this.getThisElement()}
Expand Down Expand Up @@ -318,6 +321,7 @@ function elementsInitializer(requests, client) {
}, toElementObject(this.elementId))
}


async isPresent(...args) {
if(this.subCall) {await this.subCall(); this.subCall = null}
try {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "awb",
"version": "0.7.7",
"version": "0.7.8",
"description": "simple light weight interface for selenium webdriver (node js)",
"main": "./awb.js",
"bin": {
Expand Down
13 changes: 12 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ findInGoogle_potapovDim()
* [util](https://github.com/potapovDim/interface-webdriver/blob/develop/docs/elementUtil.md)
* [waitTextContains](#waittextcontains)
* [getRect](#getrect)
* [getComputedStyle](#getcomputedstyle)
* [clear](#clear)
* [location](#location)
* [doubleClick](#doubleclick)
Expand Down Expand Up @@ -440,7 +441,7 @@ const token = await sessionStorage.get('token')
* will wait 1000ms for url includes test
* /
```
## waitForUrlIncludes
## getRect
```js
const awb = require('awb')
const { element, client } = awb()
Expand Down Expand Up @@ -753,6 +754,16 @@ const token = await sessionStorage.get('token')
* return all text inside element , return string
*/
```
## getComputedStyle
```js
const awb = require('awb')
const { element, client } = awb()
const span = element('span')
const textAnchorValue = await span.getComputedStyle(span.computedStyleList.textAnchor)
/*
* will return string with computed style value
* /
```
## getColor
```js
const awb = require('awb')
Expand Down

0 comments on commit 9c18626

Please sign in to comment.