diff --git a/API.md b/API.md index f9e7e4d..af88cc1 100644 --- a/API.md +++ b/API.md @@ -192,10 +192,6 @@ browser.click '.menu-button' browser.waitForElementNotVisible('.menu', 1000) ``` -### browser.waitForElement(cssSelector, timeout=3000) - -Deprecated synonym for `browser.waitForElementVisible(cssSelector, timeout=3000)` - ### browser.getUrl() Returns the current url @@ -968,43 +964,6 @@ about the test when the assertion fails. browser.assert.imgLoaded '.logo' ``` -### ~~browser.assert.imagesMatch(image1, image2, tolerance=0)~~ - -**Deprecated** - -Asserts that the provided images -are equal within the given `tolerance`. - -Images can be provided as -base64-encoded PNG buffers. -You can pass the value returned -by `getScreenshot` directly into this method. - -It is recommended that you leave the `tolerance` -value at 0 unless you are fully aware -of what you are testing. -Allowing a tolerance larger than 0 -can lead to tests that pass on bad input. - -Warning: this method is experimental and slow. -It uses the [img-diff](https://github.com/groupon-testium/img-diff) -library. -You can use `@slow(4000)` in tests to -notify mocha of this. - -```coffee -it 'has the same UI across implementations', -> - @slow(5000) - - browser.navigateTo '/products' - screenshot1 = browser.getScreenshot() - - browser.navigateTo '/products-rewrite' - screenshot2 = browser.getScreenshot() - - browser.assert.imagesMatch(screenshot1, screenshot2) -``` - ## Capabilities This is an object based on diff --git a/README.md b/README.md index 865f482..03614ad 100644 --- a/README.md +++ b/README.md @@ -71,13 +71,6 @@ system-level libraries. - **phantomjs 1.9.7+** (only for headless testing) - **java 7+** (only when running in browsers) -**optional** - -- ~~**libpng**~~ (**deprecated**) (for image diffing) -
[Ubuntu] `sudo apt-get install libpng-dev` -
[OS X] `brew install libpng` - - ## Configuration testium uses [`rc`](https://www.npmjs.org/package/rc) for configuration. @@ -259,7 +252,6 @@ Method | Description `browser.capabilities` | Is an object describing the [WebDriver capabilities](https://code.google.com/p/selenium/wiki/JsonWireProtocol#Capabilities_JSON_Object) that the current browser supports. `browser.getElement(cssSelector)` | Finds an element on the page using the `cssSelector` and returns an Element. `browser.getElements(cssSelector)` | Finds all elements on the page using the `cssSelector` and returns an array of Elements. -~~`browser.waitForElement(cssSelector, timeout=3000)`~~ | **Deprecated** *(synonym for `browser.waitForElementVisible(cssSelector, timeout=3000)`* `browser.waitForElementVisible(cssSelector, timeout=3000)` | Waits for the element at `cssSelector` to exist and be visible, then returns the Element. Times out after `timeout` ms. `browser.waitForElementNotVisible(cssSelector, timeout=3000)` | Waits for the element at `cssSelector` to exist and not be visible, then returns the Element. Times out after `timeout` ms. `browser.waitForElementExist(cssSelector, timeout=3000)` | Waits for the element at `cssSelector` to exist, then returns the Element. Times out after `timeout` ms. Visibility is not considered. @@ -272,7 +264,6 @@ Method | Description `browser.getPageSource()` | Returns the current page's html source. `browser.getPageSize()` | Returns the current window's size. `browser.setPageSize({height, width})` | Sets the current window's size. -~~`browser.getScreenshot(selector)`~~ | **Deprecated** Returns screenshot as a base64 encoded PNG bounded by the element at `cssSelector`. `browser.getScreenshot()` | Returns screenshot as a base64 encoded PNG. `browser.click(cssSelector)` | Calls Click on the Element found by the given `cssSelector`. `browser.type(cssSelector, value)` | Sends `value` to the input Element found by the given `cssSelector`. @@ -342,7 +333,6 @@ Method | Description `browser.assert.elementDoesntExist(selector)` | Throws exceptions if selector exists. `browser.assert.httpStatus(statusCode)` | Throws exceptions if current status code is not equal to the provided statusCode. `browser.assert.imgLoaded(selector)` | Throws exceptions if selector doesn't match a single `` element that has both loaded and been decoded successfully. Allows an optional extra _initial_ docstring argument, for semantic documentation about the test when the assertion fails. -~~`browser.assert.imagesMatch(image1, image2, tolerance=0)`~~ | **Deprecated** Throws exceptions if the images don't match within the given tolerance. Warning: this method is experimental and slow. You can use `@slow(4000)` in tests to notify mocha of this. ### Element diff --git a/lib/assert/index.js b/lib/assert/index.js index b0e0432..4f92880 100644 --- a/lib/assert/index.js +++ b/lib/assert/index.js @@ -45,7 +45,7 @@ Assertions = (function() { })(); -[require('./element'), require('../img_diff'), require('./imgLoaded'), require('./navigation')].forEach(function(mixin) { +[require('./element'), require('./imgLoaded'), require('./navigation')].forEach(function(mixin) { return extend(Assertions.prototype, mixin); }); diff --git a/lib/browser/element.js b/lib/browser/element.js index 294873d..fedf52d 100644 --- a/lib/browser/element.js +++ b/lib/browser/element.js @@ -99,11 +99,6 @@ ElementMixin = { hasType('getElements(selector) - requires (String) selector', String, selector); return this.driver.getElements(selector); }, - waitForElement: function(selector, timeout) { - console.warn('DEPRECATED: waitForElement; use waitForElementVisible instead.'); - hasType('getElements(selector) - requires (String) selector', String, selector); - return this._waitForElement(selector, isVisiblePredicate, isVisibleFailure, timeout); - }, waitForElementVisible: function(selector, timeout) { hasType('getElements(selector) - requires (String) selector', String, selector); return this._waitForElement(selector, isVisiblePredicate, isVisibleFailure, timeout); diff --git a/lib/browser/page.js b/lib/browser/page.js index 6a4933b..4125152 100644 --- a/lib/browser/page.js +++ b/lib/browser/page.js @@ -31,9 +31,7 @@ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -var cropScreenshot, hasType; - -cropScreenshot = require('../img_diff').crop; +var hasType; hasType = require('assertive').hasType; @@ -44,29 +42,8 @@ module.exports = { getPageSource: function() { return this.driver.getPageSource(); }, - _cropScreenshotBySelector: function(screenshot, selector) { - var element, elementData, position, size; - element = this.driver.getElement(selector); - position = element.getLocationInView(); - size = element.getSize(); - elementData = { - x: position.x, - y: position.y, - width: size.width, - height: size.height - }; - return cropScreenshot(screenshot, elementData); - }, - getScreenshot: function(selector) { - var screenshot; - if (selector != null) { - hasType('getScreenshot(selector) - requires (String) selector or nothing', String, selector); - console.warn('DEPRECATED: getScreenshot(selector); use getScreenshot() instead.'); - screenshot = this.driver.getScreenshot(); - return this._cropScreenshotBySelector(screenshot, selector); - } else { - return this.driver.getScreenshot(); - } + getScreenshot: function() { + return this.driver.getScreenshot(); }, setPageSize: function(size) { var height, invocation, width; diff --git a/lib/img_diff.js b/lib/img_diff.js deleted file mode 100644 index 482576f..0000000 --- a/lib/img_diff.js +++ /dev/null @@ -1,64 +0,0 @@ -// Generated by CoffeeScript 1.9.1 - -/* -Copyright (c) 2014, Groupon, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -Neither the name of GROUPON nor the names of its contributors may be -used to endorse or promote products derived from this software without -specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ -var _imgDiff, error, errorMessage, imgDiff; - -imgDiff = null; - -errorMessage = "img-diff failed to install on your system and cannot be used.\nmake sure you have libpng installed.\nUbuntu: sudo apt-get install libpng-dev\nOS X: brew install libpng"; - -try { - _imgDiff = require('img-diff'); - imgDiff = { - imagesMatch: function() { - console.warn('DEPRECATED: img-diff#imagesMatch'); - return _imgDiff.imagesMatch.apply(_imgDiff, arguments); - }, - crop: function() { - console.warn('DEPRECATED: img-diff#crop'); - return _imgDiff.crop.apply(_imgDiff, arguments); - } - }; -} catch (_error) { - error = _error; - imgDiff = { - imagesMatch: function() { - throw new Error(errorMessage); - }, - crop: function() { - throw new Error(errorMessage); - } - }; -} - -module.exports = imgDiff; diff --git a/package.json b/package.json index 116a57b..120f2ca 100644 --- a/package.json +++ b/package.json @@ -57,8 +57,5 @@ "node-static": "~0.7.6", "npub": "0.0.6", "rimraf": "^2.2.8" - }, - "optionalDependencies": { - "img-diff": "~0.1.0" } } diff --git a/src/assert/index.coffee b/src/assert/index.coffee index edf8aa6..3fcafe4 100644 --- a/src/assert/index.coffee +++ b/src/assert/index.coffee @@ -37,7 +37,6 @@ class Assertions [ require('./element') - require('../img_diff') require('./imgLoaded') require('./navigation') ].forEach (mixin) -> diff --git a/src/browser/element.coffee b/src/browser/element.coffee index 9f1e86f..c3424f3 100644 --- a/src/browser/element.coffee +++ b/src/browser/element.coffee @@ -82,11 +82,6 @@ ElementMixin = @driver.getElements(selector) - waitForElement: (selector, timeout) -> - console.warn 'DEPRECATED: waitForElement; use waitForElementVisible instead.' - hasType 'getElements(selector) - requires (String) selector', String, selector - @_waitForElement(selector, isVisiblePredicate, isVisibleFailure, timeout) - waitForElementVisible: (selector, timeout) -> hasType 'getElements(selector) - requires (String) selector', String, selector @_waitForElement(selector, isVisiblePredicate, isVisibleFailure, timeout) diff --git a/src/browser/page.coffee b/src/browser/page.coffee index 75d46bd..a36b53e 100644 --- a/src/browser/page.coffee +++ b/src/browser/page.coffee @@ -30,7 +30,6 @@ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. ### -{crop: cropScreenshot} = require '../img_diff' {hasType} = require 'assertive' module.exports = @@ -40,27 +39,8 @@ module.exports = getPageSource: -> @driver.getPageSource() - _cropScreenshotBySelector: (screenshot, selector) -> - element = @driver.getElement(selector) - position = element.getLocationInView() - size = element.getSize() - - elementData = - x: position.x - y: position.y - width: size.width - height: size.height - - cropScreenshot(screenshot, elementData) - - getScreenshot: (selector) -> - if selector? - hasType 'getScreenshot(selector) - requires (String) selector or nothing', String, selector - console.warn 'DEPRECATED: getScreenshot(selector); use getScreenshot() instead.' - screenshot = @driver.getScreenshot() - @_cropScreenshotBySelector(screenshot, selector) - else - @driver.getScreenshot() + getScreenshot: -> + @driver.getScreenshot() setPageSize: (size) -> invocation = 'setPageSize(size={height, width})' diff --git a/src/img_diff.coffee b/src/img_diff.coffee deleted file mode 100644 index cf3277a..0000000 --- a/src/img_diff.coffee +++ /dev/null @@ -1,62 +0,0 @@ -### -Copyright (c) 2014, Groupon, Inc. -All rights reserved. - -Redistribution and use in source and binary forms, with or without -modification, are permitted provided that the following conditions -are met: - -Redistributions of source code must retain the above copyright notice, -this list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. - -Neither the name of GROUPON nor the names of its contributors may be -used to endorse or promote products derived from this software without -specific prior written permission. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS -IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED -TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A -PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -### - -# img-diff is an optional dependency -# we fake it out if it can't be used - -imgDiff = null -errorMessage = """ -img-diff failed to install on your system and cannot be used. -make sure you have libpng installed. -Ubuntu: sudo apt-get install libpng-dev -OS X: brew install libpng -""" - -try - _imgDiff = require 'img-diff' - - imgDiff = - imagesMatch: -> - console.warn 'DEPRECATED: img-diff#imagesMatch' - _imgDiff.imagesMatch.apply(_imgDiff, arguments) - crop: -> - console.warn 'DEPRECATED: img-diff#crop' - _imgDiff.crop.apply(_imgDiff, arguments) - -catch error - imgDiff = - imagesMatch: -> - throw new Error errorMessage - crop: -> - throw new Error errorMessage - -module.exports = imgDiff diff --git a/test/integration/screenshot.test.coffee b/test/integration/screenshot.test.coffee index 96e506e..3870813 100644 --- a/test/integration/screenshot.test.coffee +++ b/test/integration/screenshot.test.coffee @@ -16,30 +16,3 @@ describe 'screenshots', -> it 'captures the page', -> assert.truthy @indexScreenshot.length > 0 - it 'can be scoped to a selector', -> - formScreenshot = @browser.getScreenshot('#the-form') - assert.truthy 'selector screenshot is smaller than the page', formScreenshot.length < @indexScreenshot.length - - describe 'comparing', -> - before -> - @indexScreenshot ?= getIndexScreenshot(@browser) - - it 'to itself succeeds', -> - @browser.assert.imagesMatch(@indexScreenshot, @indexScreenshot) - - it 'to something else fails', -> - @browser.navigateTo '/other-page.html' - @browser.assert.httpStatus 200 - otherScreenshot = @browser.getScreenshot() - - error = assert.throws => - @browser.assert.imagesMatch(@indexScreenshot, otherScreenshot) - expectedError = /^Images are .+ different! Tolerance was 0\.$/ - assert.match expectedError, error.message - - it 'allows tolerance', -> - @browser.navigateTo '/index-diff.html' - @browser.assert.httpStatus 200 - diffScreenshot = @browser.getScreenshot() - @browser.assert.imagesMatch(@indexScreenshot, diffScreenshot, 60.00) -