Skip to content
Browse files

moved some tests to test/common

  • Loading branch information...
1 parent 2b52e07 commit a0b61796005009cdefb59906a9d016bcd40b1d57 @sebv sebv committed Oct 7, 2012
View
27 test/local/assets/element-test-page.html
@@ -1,27 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Test Page</title>
- <script src="http://code.jquery.com/jquery-latest.js"></script>
- </head>
- <body>
- <h1>This is a test page</h1>
- <textarea name="sendKeys" id="sendKeys"></textarea>
- <div id="click"><a href="#">not clicked</a></div>
- <div id="getTagName">
- <input type="text">
- <a href="#">a1</a>
- </div>
- <div id="isDisplayed">
- <input class="displayed" type="text" value="Hello">
- <input class="hidden" type="hidden" value="Hello">
- </div>
- <div id="getComputedCss">
- <a href="#">a1</a>
- </div>
- <div id="text">I am some text</div>
- <div id="getAttribute" att="42">Attribute</div>
- <div id="getValue" value="value">Value</div>
- <textarea name="clear" id="clear">Not clear</textarea>
- </body>
-</html>
View
11 test/local/assets/frames/bottombanner.htm
@@ -1,11 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Menu Page Frame</title>
-</head>
-<body>
- <p>Banner!</p>
- <input type="text">
-
-</body>
-</html>
View
15 test/local/assets/frames/index.html
@@ -1,15 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>My Frames Page</title>
-</head>
-
-<frameset cols="120,*">
-<frame src="menupage.htm" id='f1' name="menu">
-<frameset rows="*,50">
-<frame src="welcomepage.htm" id='f2' name="main">
-<frame src="bottombanner.htm" id='f3' name="bottom">
-</frameset>
-</frameset>
-
-</html>
View
10 test/local/assets/frames/menupage.htm
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Menu Page Frame</title>
-</head>
-<body>
- <p>Menu!</p>
- <input type="text">
-</body>
-</html>
View
10 test/local/assets/frames/welcomepage.htm
@@ -1,10 +0,0 @@
-<!DOCTYPE html>
-<html>
-<head>
-<title>Menu Page Frame</title>
-</head>
-<body>
- <p>Welcome!</p>
- <input type="text">
-</body>
-</html>
View
139 test/local/assets/test-page.html
@@ -1,139 +0,0 @@
-<!DOCTYPE html>
-<head>
- <meta charset="utf-8" />
- <title>TEST PAGE</title>
-
- <script src="http://code.jquery.com/jquery-latest.js"></script>
-
-</head>
- <body>
- <div class="elementByClassName">Hello World!</div>
- <div class="elementByCssSelector">Hello World!</div>
- <div id="elementById">Hello World!</div>
- <div name="elementByName">Hello World!</div>
- <div id="elementByLinkText"><a>click elementByLinkText</a></div>
- <div id="elementByPartialLinkText"><a>click elementByPartialLinkText</a></div>
- <div id="elementByTagName"><span>Hello World!</span></div>
- <div id="elementByXPath"/><input></div>
- <div class="elementByCss">Hello World!</div>
-
- <div id="waitForElement"></div>
- <div id="waitForVisible"></div>
- <div>
- <div class="elementsByClassName">Hello World!</div>
- <div class="elementsByClassName">Hello World!</div>
- <div class="elementsByClassName">Hello World!</div>
- </div>
- <div id="waitForElementByClassName"></div>
- <div id="waitForVisibleByClassName"></div>
- <div>
- <div class="elementsByCssSelector">Hello World!</div>
- <div class="elementsByCssSelector">Hello World!</div>
- <div class="elementsByCssSelector">Hello World!</div>
- </div>
- <div id="waitForElementByCssSelector"></div>
- <div id="waitForVisibleByCssSelector"></div>
- <div>
- <div id="elementsById">Hello World!</div>
- </div>
- <div id="waitForElementById"></div>
- <div id="waitForVisibleById"></div>
- <div>
- <div name="elementsByName">Hello World!</div>
- <div name="elementsByName">Hello World!</div>
- <div name="elementsByName">Hello World!</div>
- </div>
- <div id="waitForElementByName"></div>
- <div id="waitForVisibleByName"></div>
- <div>
- <div class="elementsByLinkText"><a>click elementsByLinkText</a></div>
- <div class="elementsByLinkText"><a>click elementsByLinkText</a></div>
- <div class="elementsByLinkText"><a>click elementsByLinkText</a></div>
- </div>
- <div id="waitForElementByLinkText"></div>
- <div id="waitForVisibleByLinkText"></div>
- <div>
- <div class="elementsByPartialLinkText"><a>click elementsByPartialLinkText</a></div>
- <div class="elementsByPartialLinkText"><a>click elementsByPartialLinkText</a></div>
- <div class="elementsByPartialLinkText"><a>click elementsByPartialLinkText</a></div>
- </div>
- <div id="waitForElementByPartialLinkText"></div>
- <div id="waitForVisibleByPartialLinkText"></div>
- <div id="elementsByTagName">
- <span>Hello World!</span>
- <span>Hello World!</span>
- <span>Hello World!</span>
- </div>
- <div id="waitForElementByTagName"></div>
- <div id="waitForVisibleByTagName"></div>
- <div id="elementsByXPath"/>
- <input>
- <input>
- <input>
- </div>
- <div id="waitForElementByXPath"></div>
- <div id="waitForVisibleByXPath"></div>
- <div>
- <div class="elementsByCss">Hello World!</div>
- <div class="elementsByCss">Hello World!</div>
- <div class="elementsByCss">Hello World!</div>
- </div>
- <div id="waitForElementByCss"></div>
- <div id="waitForVisibleByCss"></div>
- <div id="getAttribute" weather="sunny">Hi</div>
-
- <div id="getTagName">
- <input type="text">
- <a href="#">a1</a>
- </div>
-
- <div id="getValue">
- <input class="input-text" type="text" value="Hello getValueTest!">
- <textarea>Hello getValueTest2!</textarea>
- </div>
-
- <div id="isDisplayed">
- <input class="displayed" type="text" value="Hello">
- <input class="hidden" type="hidden" value="Hello">
- </div>
-
- <div id="getComputedCss">
- <a href="#">a1</a>
- </div>
-
- <div id="text"><div>text content</div></div>
- <div id="type"><input class="input-text" type="text"></div>
- <div id="keys"><input class="input-text" type="text"></div>
- <div id="eval"><ul><li>line 1</li><li>line 2</li></ul></div>
- <div id="setWaitTimeout"></div>
- <div id="clickElement"><a href="#">not clicked</a></div>
- <div id="moveTo">
- <a class="a1" href="#">a1</a><br>
- <a class="a2" href="#">a2</a><br>
- <div class='current'></div>
- </div>
- <div id="click">
- <div class="numOfClicks">not clicked</div>
- <div class="buttonNumber">not clicked</div>
- </div>
- <div id="doubleclick">
- <div>not clicked</div>
- </div>
- <div id="clear"><input class="input-text" type="text" value="not cleared"></div>
- <div id="textPresent">weather is sunny</div>
- <div id="acceptAlert"><a>click me</a></div>
- <div id="dismissAlert"><a>click me</a></div>
- <div id="active">
- <input class="i1" type="text" value="input 1">
- <input class="i2" type="text" value="input 2">
- </div>
- <div id="mouseButton"><a>hold me</a><div></div></div>
- <div id="waitForCondition"></div>
- <div id="waitForConditionInBrowser"></div>
-
- <div id="isVisible">
- <a href="#">a1</a>
- </div>
-
- </body>
-</html>
View
9 test/local/assets/window-test-page.html
@@ -1,9 +0,0 @@
-<!DOCTYPE html>
-<html>
- <head>
- <title>Test Page</title>
- </head>
- <body>
- <h1>This is a test page</h1>
- </body>
-</html>
View
308 test/local/element-test.js
@@ -1,316 +1,12 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var CoffeeScript, Express, async, executeCoffee, should, test, textShouldEqual, wd;
+ var test;
- CoffeeScript = require('coffee-script');
-
- should = require('should');
-
- async = require('async');
-
- Express = require('./express').Express;
-
- wd = require('../common/wd-with-cov');
-
- textShouldEqual = function(browser, element, expected, done) {
- return browser.text(element, function(err, res) {
- should.not.exist(err);
- res.should.equal(expected);
- return done(null);
- });
- };
-
- executeCoffee = function(browser, script) {
- var scriptAsJs;
- scriptAsJs = CoffeeScript.compile(script, {
- bare: 'on'
- });
- return function(done) {
- return browser.execute(scriptAsJs, function(err) {
- should.not.exist(err);
- return done(null);
- });
- };
- };
-
- test = function(browserName) {
- var browser;
- browser = null;
- describe("wd.remote", function() {
- return it("should create browser", function(done) {
- browser = wd.remote({});
- if (process.env.WD_COV == null) {
- browser.on("status", function(info) {
- return console.log("\u001b[36m%s\u001b[0m", info);
- });
- browser.on("command", function(meth, path) {
- return console.log(" > \u001b[33m%s\u001b[0m: %s", meth, path);
- });
- }
- return done(null);
- });
- });
- describe("init", function() {
- return it("should initialize browserinit", function(done) {
- this.timeout(15000);
- return browser.init({
- browserName: browserName
- }, function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("get", function() {
- return it("should navigate to test page", function(done) {
- this.timeout(10000);
- return browser.get("http://127.0.0.1:8181/element-test-page.html", function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("element.text", function() {
- return it("should retrieve the text", function(done) {
- return browser.element("id", "text", function(err, el) {
- should.not.exist(err);
- el.should.have.property("text");
- return el.text(function(err, res) {
- res.should.include("I am some text");
- return done(null);
- });
- });
- });
- });
- describe("element.textPresent", function() {
- return it("should check if text is present", function(done) {
- return browser.element("id", "text", function(err, el) {
- should.not.exist(err);
- el.should.have.property("textPresent");
- return el.textPresent("some text", function(err, present) {
- should.not.exist(err);
- present.should.be["true"];
- return done(null);
- });
- });
- });
- });
- describe("element.click", function() {
- return it("element should be clicked", function(done) {
- return browser.elementByCss("#click a", function(err, anchor) {
- should.not.exist(err);
- should.exist(anchor);
- return async.series([
- executeCoffee(browser, 'jQuery ->\n a = $(\'#click a\')\n a.click ->\n a.html \'clicked\'\n false '), function(done) {
- return textShouldEqual(browser, anchor, "not clicked", done);
- }, function(done) {
- return anchor.click(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, anchor, "clicked", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("getTagName", function() {
- return it("should get correct tag name", function(done) {
- return async.series([
- function(done) {
- return browser.elementByCss("#getTagName input", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.getTagName(function(err, res) {
- should.not.exist(err);
- res.should.equal("input");
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#getTagName a", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.getTagName(function(err, res) {
- should.not.exist(err);
- res.should.equal("a");
- return done(null);
- });
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("isDisplayed", function() {
- return it("should check if elemnt is displayed", function(done) {
- return async.series([
- function(done) {
- return browser.elementByCss("#isDisplayed .displayed", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.isDisplayed(function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#isDisplayed .hidden", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.isDisplayed(function(err, res) {
- should.not.exist(err);
- res.should.be["false"];
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#isDisplayed .displayed", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.displayed(function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("getComputedCss", function() {
- return it("should retrieve the element computed css", function(done) {
- return async.series([
- function(done) {
- return browser.elementByCss("#getComputedCss a", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.getComputedCss('color', function(err, res) {
- should.not.exist(err);
- should.exist(res);
- res.length.should.be.above(0);
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#getComputedCss a", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return field.getComputedCSS('color', function(err, res) {
- should.not.exist(err);
- should.exist(res);
- res.length.should.be.above(0);
- return done(null);
- });
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("element.getAttribute", function() {
- return it("should retrieve attribute value", function(done) {
- return browser.element("id", "getAttribute", function(err, el) {
- should.not.exist(err);
- el.should.have.property("getAttribute");
- return el.getAttribute("att", function(err, value) {
- should.not.exist(err);
- value.should.equal("42");
- return done(null);
- });
- });
- });
- });
- describe("element.getValue", function() {
- return it("should retrieve value", function(done) {
- return browser.element("id", "getValue", function(err, el) {
- should.not.exist(err);
- el.should.have.property("getValue");
- return el.getValue(function(err, value) {
- should.not.exist(err);
- value.should.equal("value");
- return done(null);
- });
- });
- });
- });
- describe("element.sendKeys", function() {
- return it("should send keys", function(done) {
- var text;
- text = "keys";
- return browser.element("id", "sendKeys", function(err, el) {
- should.not.exist(err);
- el.should.have.property("sendKeys");
- return el.sendKeys(text, function(err) {
- should.not.exist(err);
- return el.getValue(function(err, textReceived) {
- should.not.exist(err);
- textReceived.should.equal(text);
- return done(null);
- });
- });
- });
- });
- });
- describe("element.clear", function() {
- return it("should clear input field", function(done) {
- return browser.element("id", "clear", function(err, el) {
- should.not.exist(err);
- el.should.have.property("clear");
- return el.clear(function(err) {
- should.not.exist(err);
- return el.getValue(function(err, textReceived) {
- should.not.exist(err);
- textReceived.should.equal("");
- return done(null);
- });
- });
- });
- });
- });
- describe("close", function() {
- return it("should close current window", function(done) {
- return browser.close(function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- return describe("quit", function() {
- return it("should destroy browser", function(done) {
- return browser.quit(function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- };
+ test = require('../common/element-test-base').test;
describe("wd", function() {
return describe("local", function() {
return describe("element method tests", function() {
- var express;
- express = new Express;
- before(function(done) {
- express.start();
- return done(null);
- });
- after(function(done) {
- express.stop();
- return done(null);
- });
describe("using chrome", function() {
return test('chrome');
});
View
12 test/local/express.coffee
@@ -1,12 +0,0 @@
-express = require 'express'
-
-class Express
- start: ->
- @app = express.createServer()
- @app.use(express.static(__dirname + '/assets'));
- @app.listen 8181
-
- stop: ->
- @app.close()
-
-exports.Express = Express
View
27 test/local/express.js
@@ -1,27 +0,0 @@
-// Generated by CoffeeScript 1.3.3
-(function() {
- var Express, express;
-
- express = require('express');
-
- Express = (function() {
-
- function Express() {}
-
- Express.prototype.start = function() {
- this.app = express.createServer();
- this.app.use(express["static"](__dirname + '/assets'));
- return this.app.listen(8181);
- };
-
- Express.prototype.stop = function() {
- return this.app.close();
- };
-
- return Express;
-
- })();
-
- exports.Express = Express;
-
-}).call(this);
View
1,889 test/local/per-method-test.js
@@ -1,1897 +1,12 @@
// Generated by CoffeeScript 1.3.3
(function() {
- var CoffeeScript, Express, async, elementByCss, evalShouldEqual, executeCoffee, imageinfo, safeEvalShouldEqual, should, test, textShouldEqual, valueShouldEqual, wd;
+ var test;
- CoffeeScript = require('coffee-script');
-
- should = require('should');
-
- async = require('async');
-
- imageinfo = require('imageinfo');
-
- Express = require('./express').Express;
-
- wd = require('../common/wd-with-cov');
-
- evalShouldEqual = function(browser, formula, expected) {
- return function(done) {
- return browser["eval"](formula, function(err, res) {
- should.not.exist(err);
- res.should.equal(expected);
- return done(null);
- });
- };
- };
-
- safeEvalShouldEqual = function(browser, formula, expected) {
- return function(done) {
- return browser.safeEval(formula, function(err, res) {
- should.not.exist(err);
- res.should.equal(expected);
- return done(null);
- });
- };
- };
-
- executeCoffee = function(browser, script) {
- var scriptAsJs;
- scriptAsJs = CoffeeScript.compile(script, {
- bare: 'on'
- });
- return function(done) {
- return browser.execute(scriptAsJs, function(err) {
- should.not.exist(err);
- return done(null);
- });
- };
- };
-
- elementByCss = function(browser, env, css, name) {
- return function(done) {
- return browser.elementByCss(css, function(err, res) {
- should.not.exist(err);
- env[name] = res;
- return done(null);
- });
- };
- };
-
- textShouldEqual = function(browser, element, expected, done) {
- return browser.text(element, function(err, res) {
- should.not.exist(err);
- res.should.equal(expected);
- return done(null);
- });
- };
-
- valueShouldEqual = function(browser, element, expected, done) {
- return browser.getValue(element, function(err, res) {
- should.not.exist(err);
- res.should.equal(expected);
- return done(null);
- });
- };
-
- test = function(browserName) {
- var browser, elementFunctionTests;
- browser = null;
- elementFunctionTests = function() {
- var _funcSuffix, _i, _len, _ref, _results;
- describe("element", function() {
- return it("should retrieve element", function(done) {
- return async.series([
- function(done) {
- return browser.element("name", "elementByName", function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser.element("name", "elementByName2", function(err, res) {
- should.exist(err);
- err.status.should.equal(7);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("elementOrNull", function() {
- return it("should retrieve element or return null", function(done) {
- return async.series([
- function(done) {
- return browser.elementOrNull("name", "elementByName", function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser.elementOrNull("name", "elementByName2", function(err, res) {
- should.not.exist(err);
- (res === null).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("elementIfExists", function() {
- return it("should retrieve element or return undefined", function(done) {
- return async.series([
- function(done) {
- return browser.elementIfExists("name", "elementByName", function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser.elementIfExists("name", "elementByName2", function(err, res) {
- should.not.exist(err);
- (res === void 0).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("hasElement", function() {
- return it("should check if element exist", function(done) {
- return async.series([
- function(done) {
- return browser.hasElement("name", "elementByName", function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- }, function(done) {
- return browser.hasElement("name", "elementByName2", function(err, res) {
- should.not.exist(err);
- res.should.be["false"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("waitForElement", function() {
- return it("should wait for element", function(done) {
- this.timeout(10000);
- return async.series([
- executeCoffee(browser, "setTimeout ->\n $('#waitForElement').append '<div class=\"child\">a waitForElement child</div>'\n, 750"), function(done) {
- return browser.elementByCss("#waitForElement .child", function(err, res) {
- should.exist(err);
- err.status.should.equal(7);
- return done(null);
- });
- }, function(done) {
- return browser.waitForElement("css selector", "#waitForElement .child", 2000, function(err) {
- should.not.exist(err);
- return done(err);
- });
- }, function(done) {
- return browser.waitForElement("css selector", "#wrongsel .child", 2000, function(err) {
- should.exist(err);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("waitForVisible", function() {
- return it("should wait until element is visible", function(done) {
- this.timeout(10000);
- return async.series([
- executeCoffee(browser, "$('#waitForVisible').append '<div class=\"child\">a waitForVisible child</div>' \n$('#waitForVisible .child').hide()\nsetTimeout ->\n $('#waitForVisible .child').show()\n, 750"), function(done) {
- return browser.elementByCss("#waitForVisible .child", function(err, res) {
- should.not.exist;
- return done(null);
- });
- }, function(done) {
- return browser.waitForVisible("css selector", "#waitForVisible .child", 2000, function(err) {
- should.not.exist(err);
- return done(err);
- });
- }, function(done) {
- return browser.waitForVisible("css selector", "#wrongsel .child", 2000, function(err) {
- should.exist(err);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("elements", function() {
- return it("should retrieve several elements", function(done) {
- return async.series([
- function(done) {
- return browser.elements("name", "elementsByName", function(err, res) {
- should.not.exist(err);
- res.should.have.length(3);
- return done(null);
- });
- }, function(done) {
- return browser.elements("name", "elementsByName2", function(err, res) {
- should.not.exist(err);
- res.should.eql([]);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- _ref = ['ByClassName', 'ByCssSelector', 'ById', 'ByName', 'ByLinkText', 'ByPartialLinkText', 'ByTagName', 'ByXPath', 'ByCss'];
- _results = [];
- for (_i = 0, _len = _ref.length; _i < _len; _i++) {
- _funcSuffix = _ref[_i];
- _results.push((function() {
- var elementFuncName, elementsFuncName, funcSuffix, hasElementFuncName, searchSeveralText, searchSeveralText2, searchText, searchText2, waitForElementFuncName, waitForVisibleFuncName;
- funcSuffix = _funcSuffix;
- elementFuncName = 'element' + funcSuffix;
- hasElementFuncName = 'hasElement' + funcSuffix;
- elementsFuncName = 'elements' + funcSuffix;
- waitForElementFuncName = 'waitForElement' + funcSuffix;
- waitForVisibleFuncName = 'waitForVisible' + funcSuffix;
- searchText = elementFuncName;
- if (searchText.match(/ByLinkText/)) {
- searchText = "click " + searchText;
- }
- if (searchText.match(/ByCss/)) {
- searchText = "." + searchText;
- }
- if (searchText.match(/ByXPath/)) {
- searchText = "//div[@id='elementByXPath']/input";
- }
- if (searchText.match(/ByTagName/)) {
- searchText = "span";
- }
- searchText2 = searchText + '2';
- if (searchText.match(/ByXPath/)) {
- searchText2 = "//div[@id='elementByXPath2']/input";
- }
- if (searchText.match(/ByTagName/)) {
- searchText2 = "span2";
- }
- searchSeveralText = searchText.replace('element', 'elements');
- searchSeveralText2 = searchText2.replace('element', 'elements');
- describe(elementFuncName, function() {
- return it("should retrieve element", function(done) {
- return async.series([
- function(done) {
- return browser[elementFuncName](searchText, function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser[elementFuncName](searchText2, function(err, res) {
- should.exist(err);
- err.status.should.equal(7);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("" + elementFuncName + "OrNull", function() {
- return it("should retrieve element or null", function(done) {
- return async.series([
- function(done) {
- return browser[elementFuncName + 'OrNull'](searchText, function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser[elementFuncName + 'OrNull'](searchText2, function(err, res) {
- should.not.exist(err);
- (res === null).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("" + elementFuncName + "IfExists", function() {
- return it("should retrieve element or undefined", function(done) {
- return async.series([
- function(done) {
- return browser[elementFuncName + 'IfExists'](searchText, function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser[elementFuncName + 'IfExists'](searchText2, function(err, res) {
- should.not.exist(err);
- (res === void 0).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe(hasElementFuncName, function() {
- return it("should check if element exists", function(done) {
- return async.series([
- function(done) {
- return browser[hasElementFuncName](searchText, function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- }, function(done) {
- return browser[hasElementFuncName](searchText2, function(err, res) {
- should.not.exist(err);
- res.should.be["false"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe(waitForElementFuncName, function() {
- return it("should wait for element (" + funcSuffix + ")", function(done) {
- var childHtml, searchChild;
- this.timeout(10000);
- childHtml = "<div class='child child_" + waitForElementFuncName + "'>a " + waitForElementFuncName + " child</div>";
- if (funcSuffix.match(/ById/)) {
- childHtml = "<div class='child' id='child_" + waitForElementFuncName + "'>a " + waitForElementFuncName + " child</div>";
- }
- if (funcSuffix.match(/ByName/)) {
- childHtml = "<div class='child' name='child_" + waitForElementFuncName + "'>a " + waitForElementFuncName + " child</div>";
- }
- if (funcSuffix.match(/ByLinkText/)) {
- childHtml = "<a class='child'>child_" + waitForElementFuncName + "</a>";
- }
- if (funcSuffix.match(/ByPartialLinkText/)) {
- childHtml = "<a class='child'>hello child_" + waitForElementFuncName + "</a>";
- }
- if (funcSuffix.match(/ByTagName/)) {
- childHtml = "<hr class='child'>";
- }
- searchChild = "child_" + waitForElementFuncName;
- if (funcSuffix.match(/ByCss/)) {
- searchChild = "." + searchChild;
- }
- if (funcSuffix.match(/ByTagName/)) {
- searchChild = "hr";
- }
- if (funcSuffix.match(/ByXPath/)) {
- searchChild = "//div[@class='child child_" + waitForElementFuncName + "']";
- }
- return async.series([
- executeCoffee(browser, "$('hr').remove() \nsetTimeout ->\n $('#" + waitForElementFuncName + "').append \"" + childHtml + "\"\n, 750"), function(done) {
- return browser[elementFuncName](searchChild, function(err, res) {
- should.exist(err);
- err.status.should.equal(7);
- return done(null);
- });
- }, function(done) {
- return browser[waitForElementFuncName](searchChild, 2000, function(err) {
- should.not.exist(err);
- return done(err);
- });
- }, function(done) {
- if (funcSuffix === 'ByClassName') {
- return browser[waitForElementFuncName]("__wrongsel", 2000, function(err) {
- should.exist(err);
- return done(null);
- });
- } else {
- return done(null);
- }
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe(waitForVisibleFuncName, function() {
- return it("should wait until element is visible", function(done) {
- var childHtml, searchChild;
- this.timeout(10000);
- childHtml = "<div class='child child_" + waitForVisibleFuncName + "'>a " + waitForVisibleFuncName + " child</div>";
- if (funcSuffix.match(/ById/)) {
- childHtml = "<div class='child' id='child_" + waitForVisibleFuncName + "'>a " + waitForVisibleFuncName + " child</div>";
- }
- if (funcSuffix.match(/ByName/)) {
- childHtml = "<div class='child' name='child_" + waitForVisibleFuncName + "'>a " + waitForVisibleFuncName + " child</div>";
- }
- if (funcSuffix.match(/ByLinkText/)) {
- childHtml = "<a class='child'>child_" + waitForVisibleFuncName + "</a>";
- }
- if (funcSuffix.match(/ByPartialLinkText/)) {
- childHtml = "<a class='child'>hello child_" + waitForVisibleFuncName + "</a>";
- }
- if (funcSuffix.match(/ByTagName/)) {
- childHtml = "<hr class='child'>";
- }
- searchChild = "child_" + waitForVisibleFuncName;
- if (funcSuffix.match(/ByCss/)) {
- searchChild = "." + searchChild;
- }
- if (funcSuffix.match(/ByTagName/)) {
- searchChild = "hr";
- }
- if (funcSuffix.match(/ByXPath/)) {
- searchChild = "//div[@class='child child_" + waitForVisibleFuncName + "']";
- }
- return async.series([
- executeCoffee(browser, "$('hr').remove()\n$('#" + waitForVisibleFuncName + "').append \"" + childHtml + "\"\n$('#" + waitForVisibleFuncName + " .child').hide()\nsetTimeout ->\n $('#" + waitForVisibleFuncName + " .child').show()\n, 750"), function(done) {
- if (funcSuffix !== 'ByLinkText' && funcSuffix !== 'ByPartialLinkText') {
- return browser[elementFuncName](searchChild, function(err, res) {
- should.not.exist(err);
- return done(null);
- });
- } else {
- return done(null);
- }
- }, function(done) {
- return browser[waitForVisibleFuncName](searchChild, 2000, function(err) {
- should.not.exist(err);
- return done(err);
- });
- }, function(done) {
- if (funcSuffix === 'ByClassName') {
- return browser[waitForVisibleFuncName]("__wrongsel", 2000, function(err) {
- should.exist(err);
- return done(null);
- });
- } else {
- return done(null);
- }
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- return describe(elementsFuncName, function() {
- return it("should retrieve several elements", function(done) {
- return async.series([
- function(done) {
- return browser[elementsFuncName](searchSeveralText, function(err, res) {
- should.not.exist(err);
- if (elementsFuncName.match(/ById/)) {
- res.should.have.length(1);
- } else if (elementsFuncName.match(/ByTagName/)) {
- (res.length > 1).should.be["true"];
- } else {
- res.should.have.length(3);
- }
- return done(null);
- });
- }, function(done) {
- return browser[elementsFuncName](searchSeveralText2, function(err, res) {
- should.not.exist(err);
- res.should.eql([]);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- })());
- }
- return _results;
- };
- describe("wd.remote", function() {
- return it("should create browser object", function(done) {
- browser = wd.remote({});
- if (process.env.WD_COV == null) {
- browser.on("status", function(info) {
- return console.log("\u001b[36m%s\u001b[0m", info);
- });
- browser.on("command", function(meth, path) {
- return console.log(" > \u001b[33m%s\u001b[0m: %s", meth, path);
- });
- }
- return done(null);
- });
- });
- describe("status", function() {
- return it("should retrieve selenium server status", function(done) {
- return browser.status(function(err, status) {
- should.not.exist(err);
- should.exist(status);
- return done(null);
- });
- });
- });
- describe("sessions", function() {
- return it("should retrieve selenium server sessions", function(done) {
- return browser.sessions(function(err, sessions) {
- should.not.exist(err);
- should.exist(sessions);
- return done(null);
- });
- });
- });
- describe("init", function() {
- return it("should initialize browser and open browser window", function(done) {
- this.timeout(20000);
- return browser.init({
- browserName: browserName
- }, function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("sessionCapabilities", function() {
- return it("should retrieve the session capabilities", function(done) {
- return browser.sessionCapabilities(function(err, capabilities) {
- should.not.exist(err);
- should.exist(capabilities);
- should.exist(capabilities.browserName);
- should.exist(capabilities.platform);
- return done(null);
- });
- });
- });
- describe("altSessionCapabilities", function() {
- return it("should retrieve the session capabilities using alt method", function(done) {
- return browser.altSessionCapabilities(function(err, capabilities) {
- should.not.exist(err);
- should.exist(capabilities);
- should.exist(capabilities.browserName);
- should.exist(capabilities.platform);
- return done(null);
- });
- });
- });
- describe("get", function() {
- return it("should navigate to the test page", function(done) {
- this.timeout(20000);
- return browser.get("http://127.0.0.1:8181/test-page.html", function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("setPageLoadTimeout", function() {
- return it("should set the page load timeout, test get, and unset it", function(done) {
- var capabilities;
- this.timeout(10000);
- capabilities = null;
- return async.series([
- function(done) {
- return browser.sessionCapabilities(function(err, res) {
- should.not.exist(err);
- capabilities = res;
- return done(null);
- });
- }, function(done) {
- if (capabilities.browserName !== 'chrome') {
- return browser.setPageLoadTimeout(500, function(err) {
- should.not.exist(err);
- return done(null);
- });
- } else {
- return done(null);
- }
- }, function(done) {
- if (capabilities.browserName !== 'chrome') {
- return browser.setPageLoadTimeout(500, function(err) {
- should.not.exist(err);
- return done(null);
- });
- } else {
- return done(null);
- }
- }, function(done) {
- return browser.get("http://127.0.0.1:8181/test-page.html", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- if (capabilities.browserName !== 'chrome') {
- return browser.setPageLoadTimeout(-1, function(err) {
- should.not.exist(err);
- return done(null);
- });
- } else {
- return done(null);
- }
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("refresh", function() {
- return it("should refresh page", function(done) {
- this.timeout(10000);
- return browser.refresh(function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("back forward", function() {
- return it("urls should be correct when navigating back/forward", function(done) {
- this.timeout(15000);
- return async.series([
- function(done) {
- return browser.get("http://127.0.0.1:8181/test-page.html?p=2", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.url(function(err, url) {
- should.not.exist(err);
- url.should.include("?p=2");
- return done(null);
- });
- }, function(done) {
- return browser.back(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.url(function(err, url) {
- should.not.exist(err);
- url.should.not.include("?p=2");
- return done(null);
- });
- }, function(done) {
- return browser.forward(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.url(function(err, url) {
- should.not.exist(err);
- url.should.include("?p=2");
- return done(null);
- });
- }, function(done) {
- return browser.get("http://127.0.0.1:8181/test-page.html", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("eval", function() {
- return it("should correctly evaluate various formulas", function(done) {
- return async.series([evalShouldEqual(browser, "1+2", 3), evalShouldEqual(browser, "document.title", "TEST PAGE"), evalShouldEqual(browser, "$('#eval').length", 1), evalShouldEqual(browser, "$('#eval li').length", 2)], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("safeEval", function() {
- return it("should correctly evaluate (with safeEval) various formulas", function(done) {
- return async.series([
- safeEvalShouldEqual(browser, "1+2", 3), safeEvalShouldEqual(browser, "document.title", "TEST PAGE"), safeEvalShouldEqual(browser, "$('#eval').length", 1), safeEvalShouldEqual(browser, "$('#eval li').length", 2), function(done) {
- return browser.safeEval('wrong formula +', function(err, res) {
- should.exist(err);
- (err instanceof Error).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("execute (no args)", function() {
- return it("should execute script", function(done) {
- return async.series([
- function(done) {
- return browser.execute("window.wd_sync_execute_test = 'It worked!'", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, evalShouldEqual(browser, "window.wd_sync_execute_test", 'It worked!')
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("execute (with args)", function() {
- return it("should execute script", function(done) {
- var jsScript;
- jsScript = 'var a = arguments[0], b = arguments[1];\nwindow.wd_sync_execute_test = \'It worked! \' + (a+b)';
- return async.series([
- function(done) {
- return browser.execute(jsScript, [6, 4], function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, evalShouldEqual(browser, "window.wd_sync_execute_test", 'It worked! 10')
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("safeExecute (no args)", function() {
- return it("should execute script (with safeExecute)", function(done) {
- return async.series([
- function(done) {
- return browser.safeExecute("window.wd_sync_execute_test = 'It worked!'", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, evalShouldEqual(browser, "window.wd_sync_execute_test", 'It worked!'), function(done) {
- return browser.safeExecute("invalid-code> here", function(err) {
- should.exist(err);
- (err instanceof Error).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("safeExecute (with args)", function() {
- return it("should execute script (with safeExecute)", function(done) {
- var jsScript;
- jsScript = 'var a = arguments[0], b = arguments[1];\nwindow.wd_sync_execute_test = \'It worked! \' + (a+b)';
- return async.series([
- function(done) {
- return browser.safeExecute(jsScript, [6, 4], function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, evalShouldEqual(browser, "window.wd_sync_execute_test", 'It worked! 10'), function(done) {
- return browser.safeExecute("invalid-code> here", [6, 4], function(err) {
- should.exist(err);
- (err instanceof Error).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("executeAsync (no args)", function() {
- return it("should execute async script", function(done) {
- var scriptAsCoffee, scriptAsJs;
- scriptAsCoffee = "[args...,done] = arguments\ndone \"OK\" ";
- scriptAsJs = CoffeeScript.compile(scriptAsCoffee, {
- bare: 'on'
- });
- return browser.executeAsync(scriptAsJs, function(err, res) {
- should.not.exist(err);
- res.should.equal("OK");
- return done(null);
- });
- });
- });
- describe("executeAsync (with args)", function() {
- return it("should execute async script", function(done) {
- var scriptAsCoffee, scriptAsJs;
- scriptAsCoffee = "[a,b,done] = arguments\ndone(\"OK \" + (a+b)) ";
- scriptAsJs = CoffeeScript.compile(scriptAsCoffee, {
- bare: 'on'
- });
- return browser.executeAsync(scriptAsJs, [10, 5], function(err, res) {
- should.not.exist(err);
- res.should.equal("OK 15");
- return done(null);
- });
- });
- });
- describe("safeExecuteAsync (no args)", function() {
- return it("should execute async script (using safeExecuteAsync)", function(done) {
- return async.series([
- function(done) {
- var scriptAsCoffee, scriptAsJs;
- scriptAsCoffee = "[args...,done] = arguments\ndone \"OK\" ";
- scriptAsJs = CoffeeScript.compile(scriptAsCoffee, {
- bare: 'on'
- });
- return browser.safeExecuteAsync(scriptAsJs, function(err, res) {
- should.not.exist(err);
- res.should.equal("OK");
- return done(null);
- });
- }, function(done) {
- return browser.safeExecuteAsync("123 invalid<script", function(err, res) {
- should.exist(err);
- (err instanceof Error).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("safeExecuteAsync (with args)", function() {
- return it("should execute async script (using safeExecuteAsync)", function(done) {
- return async.series([
- function(done) {
- var scriptAsCoffee, scriptAsJs;
- scriptAsCoffee = "[a,b,done] = arguments\ndone(\"OK \" + (a+b)) ";
- scriptAsJs = CoffeeScript.compile(scriptAsCoffee, {
- bare: 'on'
- });
- return browser.safeExecuteAsync(scriptAsJs, [10, 5], function(err, res) {
- should.not.exist(err);
- res.should.equal("OK 15");
- return done(null);
- });
- }, function(done) {
- return browser.safeExecuteAsync("123 invalid<script", [10, 5], function(err, res) {
- should.exist(err);
- (err instanceof Error).should.be["true"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("setWaitTimeout / setImplicitWaitTimeout", function() {
- return it("should set the wait timeout and implicit wait timeout, " + "run scripts to check functionality, " + "and unset them", function(done) {
- this.timeout(5000);
- return async.series([
- function(done) {
- return browser.setWaitTimeout(0, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, executeCoffee(browser, "setTimeout ->\n $('#setWaitTimeout').html '<div class=\"child\">a child</div>'\n, 1000"), function(done) {
- return browser.elementByCss("#setWaitTimeout .child", function(err, res) {
- should.exist(err);
- err.status.should.equal(7);
- return done(null);
- });
- }, function(done) {
- return browser.setImplicitWaitTimeout(2000, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.elementByCss("#setWaitTimeout .child", function(err, res) {
- should.not.exist(err);
- should.exist(res);
- return done(null);
- });
- }, function(done) {
- return browser.setImplicitWaitTimeout(0, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("setAsyncScriptTimeout", function() {
- return it("should set the async script timeout, " + "run scripts to check functionality, " + "and unset it", function(done) {
- this.timeout(5000);
- return async.series([
- function(done) {
- return browser.setAsyncScriptTimeout(500, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- var scriptAsCoffee, scriptAsJs;
- scriptAsCoffee = "[args...,done] = arguments\nsetTimeout ->\n done \"OK\"\n, 2000";
- scriptAsJs = CoffeeScript.compile(scriptAsCoffee, {
- bare: 'on'
- });
- return browser.executeAsync(scriptAsJs, function(err, res) {
- should.exist(err);
- err.status.should.equal(28);
- return done(null);
- });
- }, function(done) {
- return browser.setAsyncScriptTimeout(2000, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- var scriptAsCoffee, scriptAsJs;
- scriptAsCoffee = "[args...,done] = arguments\nsetTimeout ->\n done \"OK\"\n, 500";
- scriptAsJs = CoffeeScript.compile(scriptAsCoffee, {
- bare: 'on'
- });
- return browser.executeAsync(scriptAsJs, function(err, res) {
- should.not.exist(err);
- res.should.equal("OK");
- return done(null);
- });
- }, function(done) {
- return browser.setAsyncScriptTimeout(0, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- elementFunctionTests();
- describe("getAttribute", function() {
- return it("should get correct attribute value", function(done) {
- return browser.elementById("getAttribute", function(err, testDiv) {
- should.not.exist(err);
- should.exist(testDiv);
- return async.series([
- function(done) {
- return browser.getAttribute(testDiv, "weather", function(err, res) {
- should.not.exist(err);
- res.should.equal("sunny");
- return done(null);
- });
- }, function(done) {
- return browser.getAttribute(testDiv, "timezone", function(err, res) {
- should.not.exist(err);
- should.not.exist(res);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("getTagName", function() {
- return it("should get correct tag name", function(done) {
- return async.series([
- function(done) {
- return browser.elementByCss("#getTagName input", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.getTagName(field, function(err, res) {
- should.not.exist(err);
- res.should.equal("input");
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#getTagName a", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.getTagName(field, function(err, res) {
- should.not.exist(err);
- res.should.equal("a");
- return done(null);
- });
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("getValue (input)", function() {
- return it("should get correct value", function(done) {
- return browser.elementByCss("#getValue input", function(err, inputField) {
- should.not.exist(err);
- should.exist(inputField);
- return browser.getValue(inputField, function(err, res) {
- should.not.exist(err);
- res.should.equal("Hello getValueTest!");
- return done(null);
- });
- });
- });
- });
- describe("getValue (textarea)", function() {
- return it("should get correct value", function(done) {
- return browser.elementByCss("#getValue textarea", function(err, inputField) {
- should.not.exist(err);
- should.exist(inputField);
- return browser.getValue(inputField, function(err, res) {
- should.not.exist(err);
- res.should.equal("Hello getValueTest2!");
- return done(null);
- });
- });
- });
- });
- describe("isDisplayed", function() {
- return it("should check if elemnt is displayed", function(done) {
- return async.series([
- function(done) {
- return browser.elementByCss("#isDisplayed .displayed", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.isDisplayed(field, function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#isDisplayed .hidden", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.isDisplayed(field, function(err, res) {
- should.not.exist(err);
- res.should.be["false"];
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#isDisplayed .displayed", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.displayed(field, function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("getComputedCss", function() {
- return it("should retrieve the element computed css", function(done) {
- return async.series([
- function(done) {
- return browser.elementByCss("#getComputedCss a", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.getComputedCss(field, 'color', function(err, res) {
- should.not.exist(err);
- should.exist(res);
- res.length.should.be.above(0);
- return done(null);
- });
- });
- }, function(done) {
- return browser.elementByCss("#getComputedCss a", function(err, field) {
- should.not.exist(err);
- should.exist(field);
- return browser.getComputedCSS(field, 'color', function(err, res) {
- should.not.exist(err);
- should.exist(res);
- res.length.should.be.above(0);
- return done(null);
- });
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("clickElement", function() {
- return it("element should be clicked", function(done) {
- return browser.elementByCss("#clickElement a", function(err, anchor) {
- should.not.exist(err);
- should.exist(anchor);
- return async.series([
- executeCoffee(browser, 'jQuery ->\n a = $(\'#clickElement a\')\n a.click ->\n a.html \'clicked\'\n false '), function(done) {
- return textShouldEqual(browser, anchor, "not clicked", done);
- }, function(done) {
- return browser.clickElement(anchor, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, anchor, "clicked", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("moveTo", function() {
- return it("should move to correct element", function(done) {
- var env;
- env = {};
- return async.series([
- elementByCss(browser, env, "#moveTo .a1", 'a1'), elementByCss(browser, env, "#moveTo .a2", 'a2'), elementByCss(browser, env, "#moveTo .current", 'current'), function(done) {
- return textShouldEqual(browser, env.current, '', done);
- }, executeCoffee(browser, 'jQuery ->\n a1 = $(\'#moveTo .a1\')\n a2 = $(\'#moveTo .a2\')\n current = $(\'#moveTo .current\')\n a1.hover ->\n current.html \'a1\'\n a2.hover ->\n current.html \'a2\''), function(done) {
- return textShouldEqual(browser, env.current, '', done);
- }, function(done) {
- return browser.moveTo(env.a1, 5, 5, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.current, 'a1', done);
- }, function(done) {
- return browser.moveTo(env.a2, void 0, void 0, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.current, 'a2', done);
- }, function(done) {
- return browser.moveTo(env.a1, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.current, 'a1', done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("buttonDown / buttonUp", function() {
- return it("should press/unpress button", function(done) {
- var env;
- env = {};
- return async.series([
- elementByCss(browser, env, "#mouseButton a", 'a'), elementByCss(browser, env, "#mouseButton div", 'resDiv'), executeCoffee(browser, 'jQuery ->\n a = $(\'#mouseButton a\')\n resDiv = $(\'#mouseButton div\')\n a.mousedown ->\n resDiv.html \'button down\'\n a.mouseup ->\n resDiv.html \'button up\''), function(done) {
- return textShouldEqual(browser, env.resDiv, '', done);
- }, function(done) {
- return browser.moveTo(env.a, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.buttonDown(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.resDiv, 'button down', done);
- }, function(done) {
- return browser.buttonUp(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.resDiv, 'button up', done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("click", function() {
- return it("should move to then click element", function(done) {
- var env;
- env = {};
- return async.series([
- elementByCss(browser, env, "#click .numOfClicks", 'numOfClicksDiv'), elementByCss(browser, env, "#click .buttonNumber", 'buttonNumberDiv'), executeCoffee(browser, 'jQuery ->\n window.numOfClick = 0\n numOfClicksDiv = $(\'#click .numOfClicks\')\n buttonNumberDiv = $(\'#click .buttonNumber\')\n numOfClicksDiv.mousedown (eventObj) ->\n button = eventObj.button\n button = \'default\' unless button?\n window.numOfClick = window.numOfClick + 1\n numOfClicksDiv.html "clicked #{window.numOfClick}"\n buttonNumberDiv.html "#{button}" \n false '), function(done) {
- return textShouldEqual(browser, env.numOfClicksDiv, "not clicked", done);
- }, function(done) {
- return browser.moveTo(env.numOfClicksDiv, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.click(0, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.numOfClicksDiv, "clicked 1", done);
- }, function(done) {
- return textShouldEqual(browser, env.buttonNumberDiv, "0", done);
- }, function(done) {
- return browser.moveTo(env.numOfClicksDiv, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.click(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.numOfClicksDiv, "clicked 2", done);
- }, function(done) {
- return textShouldEqual(browser, env.buttonNumberDiv, "0", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("doubleclick", function() {
- return it("should move to then doubleclick element", function(done) {
- var env;
- env = {};
- return async.series([
- elementByCss(browser, env, "#doubleclick div", 'div'), executeCoffee(browser, 'jQuery ->\n div = $(\'#doubleclick div\')\n div.dblclick ->\n div.html \'doubleclicked\' '), function(done) {
- return textShouldEqual(browser, env.div, "not clicked", done);
- }, function(done) {
- return browser.moveTo(env.div, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.doubleclick(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return textShouldEqual(browser, env.div, "doubleclicked", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- describe("type", function() {
- return it("should correctly input text", function(done) {
- var altKey, nullKey;
- altKey = wd.SPECIAL_KEYS['Alt'];
- nullKey = wd.SPECIAL_KEYS['NULL'];
- return browser.elementByCss("#type input", function(err, inputField) {
- should.not.exist(err);
- should.exist(inputField);
- return async.series([
- function(done) {
- return valueShouldEqual(browser, inputField, "", done);
- }, function(done) {
- return browser.type(inputField, "Hello", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "Hello", done);
- }, function(done) {
- return browser.type(inputField, [altKey, nullKey, " World"], function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "Hello World", done);
- }, function(done) {
- return browser.type(inputField, "\n", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "Hello World", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("keys", function() {
- return it("should press keys to input text", function(done) {
- var altKey, nullKey;
- altKey = wd.SPECIAL_KEYS['Alt'];
- nullKey = wd.SPECIAL_KEYS['NULL'];
- return browser.elementByCss("#keys input", function(err, inputField) {
- should.not.exist(err);
- should.exist(inputField);
- return async.series([
- function(done) {
- return valueShouldEqual(browser, inputField, "", done);
- }, function(done) {
- return browser.clickElement(inputField, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.keys("Hello", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "Hello", done);
- }, function(done) {
- return browser.keys([altKey, nullKey, " World"], function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "Hello World", done);
- }, function(done) {
- return browser.keys("\n", function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "Hello World", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("clear", function() {
- return it("should clear input field", function(done) {
- return browser.elementByCss("#clear input", function(err, inputField) {
- should.not.exist(err);
- should.exist(inputField);
- return async.series([
- function(done) {
- return valueShouldEqual(browser, inputField, "not cleared", done);
- }, function(done) {
- return browser.clear(inputField, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return valueShouldEqual(browser, inputField, "", done);
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("title", function() {
- return it("should retrieve title", function(done) {
- return browser.title(function(err, title) {
- should.not.exist(err);
- title.should.equal("TEST PAGE");
- return done(null);
- });
- });
- });
- describe("text (passing element)", function() {
- return it("should retrieve text", function(done) {
- return browser.elementByCss("#text", function(err, textDiv) {
- should.not.exist(err);
- should.exist(textDiv);
- return browser.text(textDiv, function(err, res) {
- should.not.exist(err);
- res.should.include("text content");
- res.should.not.include("div");
- return done(null);
- });
- });
- });
- });
- describe("text (passing undefined)", function() {
- return it("should retrieve text", function(done) {
- return browser.text(void 0, function(err, res) {
- should.not.exist(err);
- res.should.include("text content");
- res.should.include("sunny");
- res.should.include("click elementsByLinkText");
- res.should.not.include("div");
- return done(null);
- });
- });
- });
- describe("text (passing body)", function() {
- return it("should retrieve text", function(done) {
- return browser.text('body', function(err, res) {
- should.not.exist(err);
- res.should.include("text content");
- res.should.include("sunny");
- res.should.include("click elementsByLinkText");
- res.should.not.include("div");
- return done(null);
- });
- });
- });
- describe("text (passing null)", function() {
- return it("should retrieve text", function(done) {
- return browser.text(null, function(err, res) {
- should.not.exist(err);
- res.should.include("text content");
- res.should.include("sunny");
- res.should.include("click elementsByLinkText");
- res.should.not.include("div");
- return done(null);
- });
- });
- });
- describe("textPresent", function() {
- return it("should check if text is present", function(done) {
- return browser.elementByCss("#textPresent", function(err, textDiv) {
- should.not.exist(err);
- should.exist(textDiv);
- return async.series([
- function(done) {
- return browser.textPresent('sunny', textDiv, function(err, res) {
- should.not.exist(err);
- res.should.be["true"];
- return done(null);
- });
- }, function(done) {
- return browser.textPresent('raining', textDiv, function(err, res) {
- should.not.exist(err);
- res.should.be["false"];
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("acceptAlert", function() {
- return it("should accept alert", function(done) {
- return browser.elementByCss("#acceptAlert a", function(err, a) {
- should.not.exist(err);
- should.exist(a);
- return async.series([
- executeCoffee(browser, "jQuery -> \n a = $('#acceptAlert a')\n a.click ->\n alert \"coffee is running out\"\n false"), function(done) {
- return browser.clickElement(a, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.acceptAlert(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("dismissAlert", function() {
- return it("should dismiss alert", function(done) {
- return browser.elementByCss("#dismissAlert a", function(err, a) {
- var capabilities;
- should.not.exist(err);
- should.exist(a);
- capabilities = null;
- return async.series([
- function(done) {
- return browser.sessionCapabilities(function(err, res) {
- should.not.exist(err);
- capabilities = res;
- return done(null);
- });
- }, executeCoffee(browser, "jQuery -> \n a = $('#dismissAlert a')\n a.click ->\n alert \"coffee is running out\"\n false"), function(done) {
- return browser.clickElement(a, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- if (!(capabilities.platform === 'MAC' && capabilities.browserName === 'chrome')) {
- return browser.dismissAlert(function(err) {
- should.not.exist(err);
- return done(null);
- });
- } else {
- return browser.acceptAlert(function(err) {
- should.not.exist(err);
- return done(null);
- });
- }
- }
- ], function(err) {
- should.not.exist(err);
- return done(null);
- });
- });
- });
- });
- describe("active", function() {
- return it("should check if element is active", function(done) {
- var env;
- env = {};
- return async.series([
- elementByCss(browser, env, "#active .i1", 'i1'), elementByCss(browser, env, "#active .i2", 'i2'), function(done) {
- return browser.clickElement(env.i1, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.active(function(err, res) {
- var k, _i, _len;
- should.not.exist(err);
- for (_i = 0, _len = res.length; _i < _len; _i++) {
- k = res[_i];
- res.should.equal(env.i1[k]);
- env.i1.should.have.property(k);
- }
- return done(null);
- });
- }, function(done) {
- return browser.clickElement(env.i2, function(err) {
- should.not.exist(err);
- return done(null);
- });
- }, function(done) {
- return browser.active(function(err, res) {
- var k, _i, _len;
- should.not.exist(err);
- for (_i = 0, _len = res.length; _i < _len; _i++) {
- k = res[_i];
- res.should.equal(env.i2[k]);
- env.i2.should.have.property(k);
- }
- return done(null);
- });
- }
- ], function(err) {