forked from nightwatchjs/nightwatch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add element property (nightwatchjs#2189)
Added W3C Webdriver related element property commands - "getElementProperty" and "elementIdProperty" protocol action.
- Loading branch information
1 parent
3bfe5a2
commit fd4aff1
Showing
6 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
const BaseElementCommand = require('./_baseElementCommand.js'); | ||
|
||
/** | ||
* Retrieve the value of a property for a given DOM element. Uses `elementIdProperty` protocol command. | ||
* | ||
* @example | ||
* this.demoTest = function (browser) { | ||
* browser.getElementProperty("#main ul li a.first", "href", function(result) { | ||
* this.assert.equal(typeof result, "object"); | ||
* this.assert.equal(result.status, 0); | ||
* this.assert.equal(result.value, 'https://nightwatchjs.org/'); | ||
* }); | ||
* }; | ||
* | ||
* | ||
* @method getElementProperty | ||
* @syntax .getElementProperty(selector, property, callback) | ||
* @param {string} selector The CSS/Xpath selector used to locate the element. | ||
* @param {string} property The property to inspect. | ||
* @param {function} callback Callback function which is called with the result value. | ||
* @see elementIdProperty | ||
* @returns {*} The value of the property | ||
* @api protocol.elementstate | ||
*/ | ||
class GetElementProperty extends BaseElementCommand { | ||
get extraArgsCount() { | ||
return 1; | ||
} | ||
|
||
get elementProtocolAction() { | ||
return 'getElementProperty'; | ||
} | ||
} | ||
|
||
module.exports = GetElementProperty; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const assert = require('assert'); | ||
const MockServer = require('../../../lib/mockserver.js'); | ||
const CommandGlobals = require('../../../lib/globals/commands.js'); | ||
|
||
describe('getElementProperty', function() { | ||
before(function(done) { | ||
CommandGlobals.beforeEach.call(this, done); | ||
}); | ||
|
||
after(function(done) { | ||
CommandGlobals.afterEach.call(this, done); | ||
}); | ||
|
||
it('client.getElementProperty()', function(done) { | ||
MockServer.addMock({ | ||
url : '/wd/hub/session/1352110219202/element/0/property/display', | ||
method:'GET', | ||
response : JSON.stringify({ | ||
sessionId: '1352110219202', | ||
status:0, | ||
value : 'block' | ||
}) | ||
}); | ||
|
||
this.client.api.getElementProperty('#weblogin', 'display', function callback(result) { | ||
assert.strictEqual(result.value, 'block'); | ||
}); | ||
|
||
this.client.start(done); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters