diff --git a/.gitignore b/.gitignore index ae589cf7919..3943d8f4483 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ +node_modules .hg .hgignore /*.png diff --git a/lib/commands/getElementSize.js b/lib/commands/getElementSize.js index 6b6800ad2ad..c6c7defea3d 100644 --- a/lib/commands/getElementSize.js +++ b/lib/commands/getElementSize.js @@ -1,8 +1,8 @@ -exports.command = function(using, value, callback) { +exports.command = function(cssSelector, callback) { var self = this; - this.element(using, value, function(result) { + this.element('css selector', cssSelector, function(result) { if(result.status === 0) { self.elementIdSize(result.value.ELEMENT, function(result) { diff --git a/lib/commands/getLocation.js b/lib/commands/getLocation.js index 429b4796d78..d1b1addb2b6 100644 --- a/lib/commands/getLocation.js +++ b/lib/commands/getLocation.js @@ -3,11 +3,13 @@ exports.command = function(cssSelector, callback) { var self = this; this.element("css selector", cssSelector, function(result) { - if(result.status === 0) { + if(result.status === 0 && result.value !== undefined) { self.elementIdLocation(result.value.ELEMENT, function(result) { - if (typeof callback === "function") { + if (typeof callback === "function" && result !== undefined) { callback({x:result.value.x, y: result.value.y}); + } else { + callback(result); } }); diff --git a/lib/commands/getTagName.js b/lib/commands/getTagName.js index 69d71baabb1..1ce5bfafc85 100644 --- a/lib/commands/getTagName.js +++ b/lib/commands/getTagName.js @@ -7,7 +7,7 @@ exports.command = function(cssSelector, callback) { self.elementIdName(result.value.ELEMENT, function(result) { if (typeof callback === "function") { - callback(result.value); + callback(result.value.toLowerCase()); } }); diff --git a/lib/commands/getText.js b/lib/commands/getText.js index 1525e5dde9f..9609b2dbc8c 100644 --- a/lib/commands/getText.js +++ b/lib/commands/getText.js @@ -7,14 +7,14 @@ exports.command = function(cssSelector, callback) { self.elementIdText(result.value.ELEMENT, function(result) { if (typeof callback === "function") { - callback(result); + callback(result.value); } }); } else { if (typeof callback === "function") { - callback(result.value); + callback(result); } } diff --git a/lib/commands/getValue.js b/lib/commands/getValue.js deleted file mode 100644 index 7342670db46..00000000000 --- a/lib/commands/getValue.js +++ /dev/null @@ -1,23 +0,0 @@ -exports.command = function(cssSelector, callback) { - - var self = this; - - this.element("css selector", cssSelector, function(result) { - if(result.status === 0) { - - self.elementIdValue(result.value.ELEMENT, function(result) { - if (typeof callback === "function") { - callback(result.value); - } - }); - - } else { - - if (typeof callback === "function") { - callback(result.value); - } - - } - }); -}; - diff --git a/lib/protocol/elementIdAttribute.js b/lib/protocol/elementIdAttribute.js index 801d4fdefc7..61877bcd67e 100644 --- a/lib/protocol/elementIdAttribute.js +++ b/lib/protocol/elementIdAttribute.js @@ -6,7 +6,7 @@ exports.command = function (id, attributeName, callback) { }; requestOptions.path = requestOptions.path.replace(/:id/gi, id); - requestOptions.path = requestOptions.path.replace(":name", attributeName); + requestOptions.path = requestOptions.path.replace(/:name/gi, attributeName); this.executeProtocolCommand( requestOptions, diff --git a/lib/protocol/elementIdLocation.js b/lib/protocol/elementIdLocation.js index bdc78041afb..4bfead44045 100644 --- a/lib/protocol/elementIdLocation.js +++ b/lib/protocol/elementIdLocation.js @@ -9,7 +9,7 @@ exports.command = function (id, callback) { this.executeProtocolCommand( requestOptions, - this.proxyResponseNoReturn(callback), + this.proxyResponse(callback), {} ); diff --git a/lib/protocol/elementIdLocationInView.js b/lib/protocol/elementIdLocationInView.js index 3d7060f2841..9c3a78bfd0d 100644 --- a/lib/protocol/elementIdLocationInView.js +++ b/lib/protocol/elementIdLocationInView.js @@ -9,7 +9,7 @@ exports.command = function (id, callback) { this.executeProtocolCommand( requestOptions, - this.proxyResponseNoReturn(callback), + this.proxyResponse(callback), {} ); diff --git a/lib/protocol/elementIdValue.js b/lib/protocol/elementIdValue.js index 2f56c532aed..6ff21d3e090 100644 --- a/lib/protocol/elementIdValue.js +++ b/lib/protocol/elementIdValue.js @@ -1,41 +1,16 @@ exports.command = function (id, value, callback) { - var commandOptionsPost = { + var requestOptions = { path:"/session/:sessionId/element/:id/value", method:"POST" }; - var commandOptionsGet = { - path:"/session/:sessionId/element/:id/value", - method:"GET" - }; - - var requestOptions = {}; - - // set or get - if (typeof value === "string") { - - requestOptions = commandOptionsPost; - requestOptions.path = requestOptions.path.replace(/:id/gi, id); - - this.executeProtocolCommand( - requestOptions, - this.proxyResponseNoReturn(callback), - {"value":value.split("")} - ); - - } else { - - callback = value; - - requestOptions = commandOptionsGet; - requestOptions.path = requestOptions.path.replace(/:id/gi, id); + requestOptions.path = requestOptions.path.replace(/:id/gi, id); - this.executeProtocolCommand( - requestOptions, - this.proxyResponse(callback), - {} - ); + this.executeProtocolCommand( + requestOptions, + this.proxyResponseNoReturn(callback), + {"value":value.split("")} + ); - } }; diff --git a/package.json b/package.json index cf5924e2781..45dc246914a 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,9 @@ "test": "mocha" }, "dependencies": {}, - "devDependencies": {}, + "devDependencies": { + "chai": "1.x" + }, "optionalDependencies": {}, "tags": [ "web", diff --git a/test/commands-test.js b/test/commands-test.js index 165b886b915..106f38a2ddd 100644 --- a/test/commands-test.js +++ b/test/commands-test.js @@ -1,7 +1,10 @@ -var assert = require("assert"), - webdriverjs = require("../index"), - githubTitle = 'GitHub · Build software better, together.', - githubRepoTitle = 'Camme/webdriverjs · GitHub'; +var assert = require('chai').assert, + fs = require('fs'), + webdriverjs = require('../index'), + testpageURL = 'http://webdriverjs.christian-bromann.com/', + githubTitle = 'GitHub · Build software better, together.', + testpageTitle = 'WebdriverJS Testpage', + testpageSource = ""; describe('test webdriverjs API', function(){ @@ -12,65 +15,103 @@ describe('test webdriverjs API', function(){ before(function(){ // init client var capabilities = { - 'browserName': 'safari', - // 'safari.binary': '/Applications/Safari.app/Contents/MacOS/Safari' + 'browserName': 'phantomjs' }; client = webdriverjs.remote({desiredCapabilities:capabilities}); - }); - - beforeEach(function(){ client .init() - .url('https://github.com/Camme/webdriverjs'); + .url(testpageURL); + + // load source of testpage for getSource() test + fs.readFile('./test/index.html', function (err, html) { + if (err) { + throw err; + } + testpageSource = html.toString(); + }); }); describe('test commands', function(){ it('get commands should return the evaluated value', function(done){ client - .getElementCssProperty('id', 'footer', 'color', function(result) { - assert('rgba(119,119,119,1)' === result.replace(/\s+/g, '')); + .getAttribute('.nested', 'style', function(result) { + assert.strictEqual(result,'text-transform: uppercase; '); }) - .getCssProperty('#footer', 'color', function(result) { - assert('rgba(119,119,119,1)' === result.replace(/\s+/g, '')); + .getElementCssProperty('css selector', '.red', 'background-color', function(result) { + assert.strictEqual('rgba(255, 0, 0, 1)',result); }) - .getElementCssProperty('class name', 'repo-label', 'text-transform', function(result) { - assert('uppercase' === result); + .getCssProperty('.green', 'float', function(result) { + assert.strictEqual('left',result); }) - .getCssProperty('.repo-label', 'text-transform', function(result) { - assert('uppercase' === result); + .getElementCssProperty('class name', 'yellow', 'width', function(result) { + assert.strictEqual('100px',result); }) - .getElementCssProperty('id', 'js-repo-pjax-container', 'width', function(result) { - assert('920px' === result); + .getCssProperty('.black', 'background-color', function(result) { + assert.strictEqual('rgba(0, 0, 0, 1)',result); }) - .getCssProperty('.container', 'width', function(result) { - assert('920px' === result); + .getElementCssProperty('id', 'purplebox', 'margin-right', function(result) { + assert.strictEqual('10px',result); }) - .end(done); + .getCssProperty('.purple', 'margin-right', function(result) { + assert.strictEqual('10px',result); + }) + .getElementSize('.red', function(result) { + assert.strictEqual(result.width,102); + assert.strictEqual(result.height,102); + }) + .getLocation('.green', function(result) { + assert.strictEqual(result.x,120); + assert.strictEqual(result.y,89); + }) + .getLocationInView('.green', function(result) { + assert.strictEqual(result.x,120); + assert.strictEqual(result.y,89); + }) + .getSource(function(result) { + assert.strictEqual(result,testpageSource); + }) + .getTagName('.black', function(result) { + assert.strictEqual(result,'div'); + }) + .getTagName('#githubRepo', function(result) { + assert.strictEqual(result,'a'); + }) + .getText('#githubRepo', function(result) { + assert.strictEqual(result,'GitHub Repo'); + }) + .getTitle(function(title) { + assert.strictEqual(title,testpageTitle); + done(); + }); }); - it.only('back button should return to the previous page', function(done) { + it('back/foward should return to the previous/next page', function(done) { client .getTitle(function(title) { - assert(title === githubRepoTitle); + assert.strictEqual(title,testpageTitle); }) - .click('.header-logo-wordmark') + .click('#githubRepo') // waitFor fix, to get safari a little bit more time to load .waitFor('.teaser-illustration',5000) .getTitle(function(title) { - assert(title === githubTitle); + assert.strictEqual(title,githubTitle); }) .back() // waitFor fix, to get safari a little bit more time to load .waitFor('.public',5000) .getTitle(function(title) { - assert(title === githubRepoTitle); + assert.strictEqual(title,testpageTitle); }) .forward() .waitFor('.teaser-illustration',5000) .getTitle(function(title) { - assert(title === githubTitle); + assert.strictEqual(title,githubTitle); }) .end(done); }); }); + + after(function() { + client.end(); + }); }); \ No newline at end of file diff --git a/test/index.html b/test/index.html new file mode 100644 index 00000000000..c496aa43e47 --- /dev/null +++ b/test/index.html @@ -0,0 +1,41 @@ + + WebdriverJS Testpage + + + + + + +

Test CSS Attributes

+
+
+
+
+
+
+ +GitHub Repo + +
+

nested elements

+
+ nested span +
+
+ \ No newline at end of file