webdriverjs
Advanced tools
Comparing version 0.7.8 to 0.7.9
@@ -19,3 +19,3 @@ var buster = require("buster"), | ||
assert(result.height === 30); | ||
assert(result.width === 68); | ||
assert(result.width === 94); | ||
}) | ||
@@ -22,0 +22,0 @@ .getTitle(function(err, title) { |
@@ -19,3 +19,3 @@ var webdriverjs = require('../index'); | ||
expect(result.height).toBe(30); | ||
expect(result.width).toBe(68); | ||
expect(result.width).toBe(94); | ||
}) | ||
@@ -22,0 +22,0 @@ .getTitle(function(err, title) { |
@@ -6,3 +6,2 @@ /* jshint -W024 */ | ||
assert = chai.assert, | ||
should = chai.should(), | ||
expect = chai.expect, | ||
@@ -27,3 +26,3 @@ webdriverjs = require('../index'); | ||
assert.strictEqual(result.height , 30); | ||
assert.strictEqual(result.width, 68); | ||
assert.strictEqual(result.width, 94); | ||
}) | ||
@@ -30,0 +29,0 @@ .getTitle(function(err, title) { |
@@ -23,3 +23,3 @@ /* jshint -W024 */ | ||
assert(result.height === 30); | ||
assert(result.width === 68); | ||
assert(result.width === 94); | ||
}) | ||
@@ -26,0 +26,0 @@ .getTitle(function(err, title) { |
@@ -21,3 +21,3 @@ /* jshint -W024 */ | ||
test.ok(result.height === 30, 'logo height should be 30px'); | ||
test.ok(result.width === 68, 'logo width should be 68px'); | ||
test.ok(result.width === 94, 'logo width should be 94px'); | ||
}) | ||
@@ -24,0 +24,0 @@ .getTitle(function(err, title) { |
@@ -40,4 +40,4 @@ // division-by-zero-test.js | ||
'width is 68px': function(err,result) { | ||
assert(result.width === 68); | ||
'width is 94px': function(err,result) { | ||
assert(result.width === 94); | ||
} | ||
@@ -44,0 +44,0 @@ |
@@ -11,3 +11,3 @@ exports.command = function(cssSelector, attributeName, callback) { | ||
if (typeof callback === "function") { | ||
callback(err,result.value); | ||
callback(err,result.value.replace(/\s+/g, '')); | ||
} | ||
@@ -14,0 +14,0 @@ }); |
@@ -10,3 +10,3 @@ exports.command = function(cssSelector, cssProperty, callback) { | ||
if (typeof callback === "function") { | ||
callback(err, result.value); | ||
callback(err, result.value.replace(/\s+/g, '')); | ||
} | ||
@@ -13,0 +13,0 @@ }); |
@@ -10,3 +10,3 @@ exports.command = function(using, value, cssProperty, callback) { | ||
if (typeof callback === "function") { | ||
callback(err, result.value); | ||
callback(err, result.value.replace(/\s+/g, '')); | ||
} | ||
@@ -13,0 +13,0 @@ }); |
@@ -0,1 +1,3 @@ | ||
var unicodeChars = require('../utils/unicodeChars'); | ||
exports.command = function(id, value, callback) { | ||
@@ -17,2 +19,3 @@ | ||
// set | ||
var key = []; | ||
if (typeof value === 'string') { | ||
@@ -22,4 +25,12 @@ | ||
requestOptions.path = requestOptions.path.replace(/:id/gi, id); | ||
data = {'value': value.split('')}; | ||
// replace key with corresponding unicode character | ||
if(unicodeChars.hasOwnProperty(value)) { | ||
key = [unicodeChars[value]]; | ||
} else { | ||
key = value.split(""); | ||
} | ||
data = {'value': key}; | ||
this.requestHandler.create(requestOptions, data, callback); | ||
@@ -26,0 +37,0 @@ |
@@ -30,3 +30,3 @@ /** | ||
process.on('uncaughtexception', errorCB); | ||
process.on('uncaughtException', errorCB); | ||
@@ -40,3 +40,3 @@ // call the callback | ||
// remove the listener to avoid memoryleakes. but do it after self.next so we know everything went well | ||
process.removeListener('uncaughtexception', errorCB); | ||
process.removeListener('uncaughtException', errorCB); | ||
@@ -43,0 +43,0 @@ }; |
@@ -20,9 +20,25 @@ /** | ||
port: options.port || 4444, | ||
method: 'POST' | ||
method: 'POST', | ||
protocol: 'http:' | ||
}; | ||
// rename options var key | ||
if(options.key) { | ||
options.pwd = options.key; | ||
delete options.key; | ||
} | ||
// set auth from user and password configs | ||
if(options.user && options.pwd) { | ||
options.auth = options.user + ':' + options.pwd; | ||
delete options.user; | ||
delete options.pwd; | ||
} | ||
this.defaultOptions = extend(this.defaultOptions, options); | ||
this.defaultHeaders = { | ||
'content-type': 'application/json', | ||
'charset': 'charset=UTF-8' | ||
'Connection': 'keep-alive', | ||
'Accept': 'application/json;charset=utf-8', | ||
'content-type': 'application/json;charset=utf-8' | ||
}; | ||
@@ -29,0 +45,0 @@ |
{ | ||
"name": "webdriverjs", | ||
"description": "A nodejs bindings implementation for selenium 2.0/webdriver", | ||
"version": "0.7.8", | ||
"version": "0.7.9", | ||
"homepage": "https://github.com/camme/webdriverjs", | ||
@@ -29,3 +29,3 @@ "author": "camilo tapia <camilo.tapia@gmail.com>", | ||
"scripts": { | ||
"test": "mocha" | ||
"test": "mocha --reporter spec" | ||
}, | ||
@@ -32,0 +32,0 @@ "dependencies": {}, |
@@ -17,3 +17,3 @@ Webdriver/selenium 2.0 javascript bindings for nodejs [![Build Status](https://travis-ci.org/christian-bromann/webdriverjs.png)](https://travis-ci.org/christian-bromann/webdriverjs) | ||
### How to install it | ||
## How to install it | ||
@@ -26,3 +26,3 @@ Either download it from github or use npm: | ||
### Example of webdriverjs | ||
## Example of webdriverjs | ||
@@ -35,3 +35,3 @@ Run selenium server first: | ||
You can use any nodejs test framework as well as any BDD/TDD assertion library. | ||
Webdriverjs has just a few methods. Most of the methods you will use regurarly are the methods available from the client. To begin using Webdriverjs you just need to create a client. For testing you can use any nodejs test framework as well as any BDD/TDD assertion library. | ||
@@ -57,3 +57,3 @@ **example using [Mocha](http://visionmedia.github.com/mocha/) and [Chai](http://chaijs.com/)** | ||
assert.strictEqual(result.height , 30); | ||
assert.strictEqual(result.width, 68); | ||
assert.strictEqual(result.width, 94); | ||
}) | ||
@@ -79,62 +79,37 @@ .getTitle(function(err, title) { | ||
## webdriverjs howto | ||
Webdriverjs has just a few methods. Most of the methods you will use regurarly are the methods available from the client. To begin using Webdriverjs you just need to create a client. And to create a client, just do the following: | ||
## Options | ||
var webdriverjs = require("webdriverjs"); // You load the module as usual | ||
var client = webdriverjs.remote({}); // To create a client you just call the remote method | ||
### desiredCapabilities | ||
Type: `Object`<br> | ||
The remote method takes an object with the options needed to create the client. The available options are which capabilities the client should have. Here is an example: | ||
**Example:** | ||
var client = WebdriverJS.remote({ | ||
desiredCapabilities: {}, // read more below | ||
singelton: false, // boolean, default true | ||
logLevel: 'silent' // string, default is 'verbose' but it can also be 'silent' (read more below) | ||
}); | ||
### Options | ||
#### desiredCapabilities | ||
Type: `Object`<br> | ||
Default capabilities: | ||
```js | ||
browserName: 'firefox', // options: firefox, chrome, opera, safari | ||
version: '', | ||
javascriptEnabled: true, | ||
platform: 'ANY' | ||
browserName: 'chrome', // options: firefox, chrome, opera, safari | ||
version: '27.0', // browser version | ||
platform: 'XP', // OS platform | ||
tags: ['tag1','tag2'], // specify some tags (e.g. if you use SauceLabs) | ||
name: 'my test' // set name for test (e.g. if you use SauceLabs) | ||
``` | ||
If selenium can't find the browser binary, add the path as attribute in your desiredCapabilities | ||
object. | ||
### logLevel | ||
Type: `String`<br> | ||
Default: *verbose*<br> | ||
Options: *verbose* | *silent* | *command* | *data* | *result* | ||
**for Firefox:** | ||
### singelton | ||
Create client as singleton instance for use in different files<br> | ||
Type: `Boolean`<br> | ||
Default: *true* | ||
``` | ||
'firefox_binary': <path to binary> | ||
//e.g. '/Applications/Firefox.app/Contents/MacOS/firefox' | ||
``` | ||
## [SauceLabs](https://saucelabs.com/) support | ||
To run your tests via SauceLabs, add the following attributes to your option object. If you have a public repository, never publish your SauceLab key! Export these informations as enviroment variables. | ||
**for Chrome:** | ||
```js | ||
host: 'ondemand.saucelabs.com', // SauceLabs remote host | ||
user: 'webdriverjs', // your username | ||
key: 'XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX' // your account key | ||
``` | ||
'chrome.binary': <path to binary> | ||
``` | ||
**for Opera:** | ||
``` | ||
'opera.binary': <path to binary> | ||
``` | ||
**for Safari:** | ||
``` | ||
'safari.binary': <path to binary> | ||
``` | ||
#### logLevel | ||
Type: `String`<br> | ||
Default: *verbose*<br> | ||
Options: *verbose* | *silent* | *command* | *data* | *result* | ||
### webdriverjs.endAll | ||
## webdriverjs.endAll | ||
If you wish to end all sessions, you can call the endAll method: | ||
@@ -146,3 +121,3 @@ | ||
### webdriverjs.sessions | ||
## webdriverjs.sessions | ||
To get a list of all open sessions, you can call: | ||
@@ -154,3 +129,3 @@ | ||
### Extending | ||
## Extending | ||
If you which to extend with your own set of commands there is a method called addCommand available from the client object: | ||
@@ -189,3 +164,3 @@ | ||
- **addValue(`String` css selector, `String` value, `Function` callback)**<br>adds a value to an object found by a css selector | ||
- **addValue(`String` css selector, `String` value, `Function` callback)**<br>adds a value to an object found by a css selector. You can also use unicode characters like `Left arrow` or `Back space`. You'll find all supported characters [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value). To do that, the value has to correspond to a key from the table. | ||
- **buttonClick(`String` css selector, `Function` callback)**<br>click on a button using a css selector | ||
@@ -221,3 +196,3 @@ - **call(callback)**<br>call given function in async order of current command queue | ||
- **setCookie(`Object` cookie, `Function` callback)**<br>Sets a [cookie](http://code.google.com/p/selenium/wiki/JsonWireProtocol#Cookie_JSON_Object) for current page. | ||
- **setValue(`String` css selector, `String` value, `Function` callback)**<br>Sets a value to an object found by a css selector (clears value before) | ||
- **setValue(`String` css selector, `String` value, `Function` callback)**<br>Sets a value to an object found by a css selector (clears value before). You can also use unicode characters like `Left arrow` or `Back space`. You'll find all supported characters [here](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value). To do that, the value has to correspond to a key from the table. | ||
- **submitForm(`String` css selector, `Function` callback)**<br>Submits a form found by the css selector | ||
@@ -224,0 +199,0 @@ - **waitFor(`String` css selector, `Integer` milliseconds, `Function` callback)**<br>Waits for an object in the dom (selected by css selector) for the amount of milliseconds provided. the callback is called with false if the object isnt found. |
@@ -12,10 +12,17 @@ /* jshint -W024 */ | ||
testpageURL = 'http://webdriverjs.christian-bromann.com/', | ||
testpageURL = 'http://wdjs.local/', | ||
githubTitle = 'GitHub · Build software better, together.', | ||
testpageTitle = 'WebdriverJS Testpage', | ||
testpageSource = "", | ||
capabilities = {}; | ||
testpageSource = ""; | ||
describe('test webdriverjs API', function(){ | ||
// test capabilities | ||
var capabilities = { | ||
browserName: 'phantomjs', | ||
// version: '27', | ||
// platform: 'XP', | ||
// tags: ['webdriverjs','api','test'], | ||
// name: 'webdriverjs API test' | ||
}; | ||
describe('webdriverjs API test', function(){ | ||
this.timeout(99999999); | ||
@@ -30,10 +37,9 @@ | ||
// init client | ||
capabilities = { | ||
'browserName': 'phantomjs', | ||
// 'firefox_switches': ['-height=200','-width=200'], | ||
// 'chrome.binary': '/Applications/Browser/Google Chrome.app/Contents/MacOS/Google Chrome' | ||
// 'firefox_binary': '/Applications/Browser/Firefox.app/Contents/MacOS/firefox' | ||
}; | ||
client = webdriverjs.remote({logLevel:'silent',desiredCapabilities:capabilities}); | ||
client = webdriverjs.remote({ | ||
desiredCapabilities:capabilities, | ||
logLevel: 'silent', | ||
// host: 'ondemand.saucelabs.com', | ||
// user: process.env.SAUCE_USERNAME, | ||
// key: process.env.SAUCE_ACCESS_KEY | ||
}); | ||
client.init(); | ||
@@ -50,53 +56,89 @@ | ||
done(); | ||
}); | ||
}); | ||
describe('test commands', function(){ | ||
it('get commands should return the evaluated value', function(done){ | ||
client | ||
.url(testpageURL) | ||
.getAttribute('.nested', 'style', function(err,result) { | ||
describe('get commands should return the evaluated value', function() { | ||
before(function(done) { | ||
client.url(testpageURL).call(done); | ||
}); | ||
it('getAttribute: style of elem .nested should be "text-transform:uppercase;"', function(done){ | ||
client.getAttribute('.nested', 'style', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,'text-transform: uppercase; '); | ||
}) | ||
.getElementCssProperty('css selector', '.red', 'background-color', function(err,result) { | ||
assert.strictEqual(result,'text-transform:uppercase;'); | ||
}).call(done); | ||
}); | ||
it('getElementCssProperty: css selector of elem .red should be "rgba(255,0,0,1)"', function(done){ | ||
client.getElementCssProperty('css selector', '.red', 'background-color', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual('rgba(255, 0, 0, 1)',result); | ||
}) | ||
.getCssProperty('.green', 'float', function(err,result) { | ||
assert.strictEqual('rgba(255,0,0,1)',result); | ||
}).call(done); | ||
}); | ||
it('getCssProperty: float css attribute of .green should be "left"', function(done){ | ||
client.getCssProperty('.green', 'float', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual('left',result); | ||
}) | ||
.getElementCssProperty('class name', 'yellow', 'width', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getElementCssProperty: width of elem with class name yellow should be "100px"', function(done){ | ||
client.getElementCssProperty('class name', 'yellow', 'width', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual('100px',result); | ||
}) | ||
.getCssProperty('.black', 'background-color', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getCssProperty: background-color of elem .black should be "rgba(0,0,0,1)"', function(done){ | ||
client.getCssProperty('.black', 'background-color', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual('rgba(0, 0, 0, 1)',result); | ||
}) | ||
.getElementCssProperty('id', 'purplebox', 'margin-right', function(err,result) { | ||
assert.strictEqual('rgba(0,0,0,1)',result); | ||
}).call(done); | ||
}); | ||
it('getElementCssProperty: leftmargin of elem with ID purplebox should be "10px"', function(done){ | ||
client.getElementCssProperty('id', 'purplebox', 'margin-right', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual('10px',result); | ||
}) | ||
.getCssProperty('.purple', 'margin-right', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getCssProperty: rightmargin of elem .purple should be "10px"', function(done){ | ||
client.getCssProperty('.purple', 'margin-right', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual('10px',result); | ||
}) | ||
.getElementSize('.red', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getElementSize: size of elem .red should be 102x102px', function(done){ | ||
client.getElementSize('.red', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result.width,102); | ||
assert.strictEqual(result.height,102); | ||
}) | ||
.getLocation('.green', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getLocation: location of elem .green should be x=120 , y=89', function(done){ | ||
client.getLocation('.green', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result.x,120); | ||
assert(result.y === 89 || result.y === 94); | ||
}) | ||
.getLocationInView('.green', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getLocationInView: location of elem .green should be x=120 , y=89', function(done){ | ||
client.getLocationInView('.green', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result.x,120); | ||
assert(result.y === 89 || result.y === 94); | ||
}) | ||
.getSource(function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getSource: source code of testpage should be the same as the code, which was fetched before test', function(done){ | ||
client.getSource(function(err,result) { | ||
expect(err).to.be.null; | ||
@@ -108,154 +150,214 @@ | ||
assert.strictEqual(result,testpageSource); | ||
}) | ||
.getTagName('.black', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getTagName: tag name of elem .black should be "div"', function(done){ | ||
client.getTagName('.black', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,'div'); | ||
}) | ||
.getTagName('#githubRepo', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getTagName: tag name of elem #githubRepo should be "a"', function(done){ | ||
client.getTagName('#githubRepo', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,'a'); | ||
}) | ||
.getText('#githubRepo', function(err,result) { | ||
}).call(done); | ||
}); | ||
it('getText: content of elem #githubRepo should be "GitHub Repo"', function(done){ | ||
client.getText('#githubRepo', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,'GitHub Repo'); | ||
}) | ||
.getTitle(function(err,title) { | ||
}).call(done); | ||
}); | ||
it('getTitle: title of testpage should be "'+testpageTitle+'"', function(done){ | ||
client.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,testpageTitle); | ||
}) | ||
.call(done); | ||
}).call(done); | ||
}); | ||
}); | ||
it('should set, get and delete cookies',function(done) { | ||
client | ||
.url(testpageURL) | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.getCookie('test', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result.name,'test'); | ||
assert.strictEqual(result.value,'cookie saved!'); | ||
}) | ||
.setCookie({name: 'test2',value: 'cookie2 saved!'}) | ||
.deleteCookie('test') | ||
.getCookie('test', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,null); | ||
}) | ||
.getCookie('test2', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result.name,'test2'); | ||
assert.strictEqual(result.value,'cookie2 saved!'); | ||
}) | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.deleteCookie() | ||
.getCookie('test', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,null); | ||
}) | ||
.getCookie('test2', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,null); | ||
}) | ||
.call(done); | ||
describe('test cookie functionality',function() { | ||
before(function(done) { | ||
client.url(testpageURL).call(done); | ||
}); | ||
it('should set a cookie and read its content afterwards', function(done){ | ||
client | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.getCookie('test', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result.name,'test'); | ||
assert.strictEqual(result.value,'cookie saved!'); | ||
}) | ||
.call(done); | ||
}); | ||
it('should delete created cookie and is not able to read its content', function(done){ | ||
client | ||
.deleteCookie('test') | ||
.getCookie('test', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,null); | ||
}) | ||
.call(done); | ||
}); | ||
it('should create two cookies and delete all at once', function(done){ | ||
client | ||
.setCookie({name: 'test',value: 'cookie saved!'}) | ||
.setCookie({name: 'test2',value: 'cookie2 saved!'}) | ||
.deleteCookie() | ||
.getCookie('test', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,null); | ||
}) | ||
.getCookie('test2', function(err,result) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(result,null); | ||
}) | ||
.call(done); | ||
}); | ||
}); | ||
it('back/foward should return to the previous/next page', function(done) { | ||
client | ||
.url(testpageURL) | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,testpageTitle); | ||
}) | ||
.click('#githubRepo') | ||
// waitFor fix, to get safari a little bit more time to load | ||
.waitFor('.teaser-illustration',5000) | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,githubTitle); | ||
}) | ||
.back() | ||
// waitFor fix, to get safari a little bit more time to load | ||
.waitFor('.public',5000) | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,testpageTitle); | ||
}) | ||
.forward() | ||
.waitFor('.teaser-illustration',5000) | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,githubTitle); | ||
}) | ||
.call(done); | ||
describe('test ability to go back and forward in browser history', function() { | ||
before(function(done) { | ||
client.url(testpageURL).call(done); | ||
}); | ||
it('should be able to go backward in history', function(done){ | ||
client | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,testpageTitle); | ||
}) | ||
.click('#githubRepo') | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,githubTitle); | ||
}) | ||
.back() | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,testpageTitle); | ||
}) | ||
.call(done); | ||
}); | ||
it('should be able to go forward in history', function(done){ | ||
client | ||
.forward() | ||
.waitFor('.teaser-illustration',5000) | ||
.getTitle(function(err,title) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(title,githubTitle); | ||
}) | ||
.call(done); | ||
}); | ||
}); | ||
it('click command test',function(done) { | ||
client | ||
.url(testpageURL) | ||
.isVisible('.btn1',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn1',function(err,result) { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn1_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
assert(result, '.btn1 was clicked'); | ||
}) | ||
.isVisible('.btn2',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn2',function(err,result) { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn2_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
assert(!result, '.btn2 wasn\'t clicked'); | ||
}) | ||
.isVisible('.btn3',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn3',function(err,result) { | ||
expect(err).to.be.null; | ||
// phantomjs is able to click on a not clickable button | ||
if(capabilities.browserName === 'phantomjs') { | ||
describe('click command test',function(done) { | ||
// TODO call URL in before function doesn't work, why? | ||
it('text should be visible after clicking on .btn1', function(done){ | ||
client | ||
.url(testpageURL) | ||
.isVisible('.btn1',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn1',function(err,result) { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
} else { | ||
result.status.should.equal(13); | ||
} | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn3_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn1_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
assert(result, '.btn1 was clicked'); | ||
}) | ||
.call(done); | ||
}); | ||
// phantomjs is able to click on a not clickable button | ||
if(capabilities.browserName === 'phantomjs') { | ||
assert(result, '.btn3 wasn\'t clicked'); | ||
} else { | ||
assert(!result, '.btn3 was clicked'); | ||
} | ||
}) | ||
.isVisible('.btn4',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn4',function(err,result) { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn4_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
// it is possible to click on a button with width/height = 0 | ||
assert(result, '.btn3 was clicked'); | ||
}) | ||
.call(done); | ||
it('text should NOT be visible after click on .btn2 because button is disabled', function(done){ | ||
client | ||
.url(testpageURL) | ||
.isVisible('.btn2',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn2',function(err,result) { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn2_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
assert(!result, '.btn2 wasn\'t clicked'); | ||
}) | ||
.call(done); | ||
}); | ||
it('text should NOT be visible after click on .btn3 because button is behind overlay', function(done){ | ||
client | ||
.url(testpageURL) | ||
.isVisible('.btn3',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn3',function(err,result) { | ||
// phantomjs is able to click on a not clickable button | ||
if(capabilities.browserName === 'phantomjs') { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
} else { | ||
expect(err).not.to.be.null; | ||
result.status.should.equal(13); | ||
} | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn3_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
// phantomjs is able to click on a not clickable button | ||
if(capabilities.browserName === 'phantomjs') { | ||
assert(result, '.btn3 wasn\'t clicked'); | ||
} else { | ||
assert(!result, '.btn3 was clicked'); | ||
} | ||
}) | ||
.call(done); | ||
}); | ||
it('text should be visible after clicking ion .btn4 with a width/height of 0', function(done){ | ||
client | ||
.url(testpageURL) | ||
.isVisible('.btn4',function(err,result) { | ||
expect(err).to.be.null; | ||
if(result) { | ||
client.click('.btn4',function(err,result) { | ||
expect(err).to.be.null; | ||
result.status.should.equal(0); | ||
}); | ||
} | ||
}) | ||
.isVisible('.btn4_clicked',function(err,result){ | ||
expect(err).to.be.null; | ||
// it is possible to click on a button with width/height = 0 | ||
assert(result, '.btn4 was clicked'); | ||
}) | ||
.call(done); | ||
}); | ||
}); | ||
@@ -285,3 +387,3 @@ | ||
it('test setting values in input elements',function(done) { | ||
client.url(testpageURL); | ||
client.url(testpageURL).pause(1000); | ||
@@ -345,7 +447,8 @@ var checkError = function(err) { | ||
it('click on submit button should work as well as submitForm command', function(done) { | ||
describe('test submit button with click and submitForm', function(done) { | ||
var elementShouldBeNotFound = function(err,result) { | ||
err.should.not.equal.null; | ||
assert.strictEqual(result.status,13); | ||
// for phantomjs it is an UnknownError instead of NoSuchElement in Browser | ||
assert.strictEqual(result.status, capabilities.browserName === 'phantomjs' ? 13 : 7); | ||
}; | ||
@@ -360,21 +463,27 @@ var elementShouldBeVisible = function(err,result) { | ||
client | ||
.url(testpageURL) | ||
.isVisible('.gotDataA', elementShouldBeNotFound) | ||
.isVisible('.gotDataB', elementShouldBeNotFound) | ||
.isVisible('.gotDataC', elementShouldBeNotFound) | ||
.click('.send', shouldCauseNoError) | ||
.isVisible('.gotDataA', elementShouldBeVisible) | ||
.isVisible('.gotDataB', elementShouldBeVisible) | ||
.isVisible('.gotDataC', elementShouldBeVisible) | ||
it('click on submit button should send data from form', function(done) { | ||
client | ||
.url(testpageURL) | ||
.isVisible('.gotDataA', elementShouldBeNotFound) | ||
.isVisible('.gotDataB', elementShouldBeNotFound) | ||
.isVisible('.gotDataC', elementShouldBeNotFound) | ||
.click('.send', shouldCauseNoError) | ||
.isVisible('.gotDataA', elementShouldBeVisible) | ||
.isVisible('.gotDataB', elementShouldBeVisible) | ||
.isVisible('.gotDataC', elementShouldBeVisible) | ||
.call(done); | ||
}); | ||
.url(testpageURL) | ||
.isVisible('.gotDataA', elementShouldBeNotFound) | ||
.isVisible('.gotDataB', elementShouldBeNotFound) | ||
.isVisible('.gotDataC', elementShouldBeNotFound) | ||
.submitForm('.send', shouldCauseNoError) | ||
.isVisible('.gotDataA', elementShouldBeVisible) | ||
.isVisible('.gotDataB', elementShouldBeVisible) | ||
.isVisible('.gotDataC', elementShouldBeVisible) | ||
.call(done); | ||
it('submit form via provided command should send data from form', function(done) { | ||
client | ||
.url(testpageURL) | ||
.isVisible('.gotDataA', elementShouldBeNotFound) | ||
.isVisible('.gotDataB', elementShouldBeNotFound) | ||
.isVisible('.gotDataC', elementShouldBeNotFound) | ||
.submitForm('.send', shouldCauseNoError) | ||
.isVisible('.gotDataA', elementShouldBeVisible) | ||
.isVisible('.gotDataB', elementShouldBeVisible) | ||
.isVisible('.gotDataC', elementShouldBeVisible) | ||
.call(done); | ||
}); | ||
}); | ||
@@ -394,3 +503,3 @@ | ||
var delta = Date.now() - startTime; | ||
delta.should.be.within(2999,5000); | ||
delta.should.be.within(2999,10000); | ||
done(); | ||
@@ -401,3 +510,3 @@ }); | ||
it('closeAll ends all sessions', function(done) { | ||
it.skip('closeAll ends all sessions', function(done) { | ||
@@ -409,11 +518,15 @@ var client1 = webdriverjs.remote({logLevel:'silent',desiredCapabilities:capabilities}).init(); | ||
client2.url(testpageURL).call(function() { | ||
webdriverjs.endAll(function(err) { | ||
webdriverjs.sessions(function(err, sessions) { | ||
should.not.exist(err); | ||
sessions.should.have.lengthOf(0); | ||
require("child_process").exec("ps aux | grep 'phantomjs'", function(err, result) { | ||
result = result.replace(/grep 'phantomjs'/g, ''); | ||
result = result.replace(/grep phantomjs/g, ''); | ||
result.should.not.include('phantomjs'); | ||
done(); | ||
webdriverjs.sessions(function(err, sessions) { | ||
should.not.exist(err); | ||
sessions.should.have.lengthOf(2); | ||
webdriverjs.endAll(function(err) { | ||
webdriverjs.sessions(function(err, sessions) { | ||
should.not.exist(err); | ||
sessions.should.have.lengthOf(0); | ||
require("child_process").exec("ps aux | grep 'phantomjs'", function(err, result) { | ||
result = result.replace(/grep 'phantomjs'/g, ''); | ||
result = result.replace(/grep phantomjs/g, ''); | ||
result.should.not.include('phantomjs'); | ||
done(); | ||
}); | ||
}); | ||
@@ -426,3 +539,51 @@ }); | ||
describe('test unicode characters', function() { | ||
var checkError = function(err) { | ||
expect(err).to.be.null; | ||
}; | ||
it('input should have an empty value after using delete command', function(done) { | ||
client | ||
.url(testpageURL) | ||
.addValue('input.searchinput','012', checkError) | ||
.addValue('input.searchinput','Left arrow', checkError) | ||
.addValue('input.searchinput','Left arrow', checkError) | ||
.addValue('input.searchinput','Left arrow', checkError) | ||
.addValue('input.searchinput','Delete', checkError) | ||
.addValue('input.searchinput','Delete', checkError) | ||
.addValue('input.searchinput','Delete', checkError) | ||
.getValue('input.searchinput', function(err,value) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(value,''); | ||
}) | ||
.call(done); | ||
}); | ||
it('input should have an empty value after using Back space command', function(done) { | ||
client | ||
.url(testpageURL) | ||
.addValue('input.searchinput','012', checkError) | ||
.addValue('input.searchinput','Back space', checkError) | ||
.addValue('input.searchinput','Back space', checkError) | ||
.addValue('input.searchinput','Back space', checkError) | ||
.getValue('input.searchinput', function(err,value) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(value,''); | ||
}) | ||
.call(done); | ||
}); | ||
it('input should have one space as input', function(done) { | ||
client | ||
.url(testpageURL) | ||
.addValue('input.searchinput','Space', checkError) | ||
.getValue('input.searchinput', function(err,value) { | ||
expect(err).to.be.null; | ||
assert.strictEqual(value,' '); | ||
}) | ||
.call(done); | ||
}); | ||
}); | ||
}); | ||
@@ -432,5 +593,4 @@ | ||
client.end(); | ||
//}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34409381
2499
100
247
6