diff --git a/.github/workflows/webdriver.yml b/.github/workflows/webdriver.yml index 71b78e9a4..bf7cf31fd 100644 --- a/.github/workflows/webdriver.yml +++ b/.github/workflows/webdriver.yml @@ -40,7 +40,9 @@ jobs: - name: start a server run: "php -S 127.0.0.1:8000 -t test/data/app &" - name: run unit tests - run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js + run: ./node_modules/.bin/mocha test/helper/WebDriver_test.js --exit + - name: run unit tests - no selenium server + run: ./node_modules/.bin/mocha test/helper/WebDriver.noSeleniumServer_test.js --exit - name: run tests run: "./bin/codecept.js run -c test/acceptance/codecept.WebDriver.js --grep @WebDriver --debug" diff --git a/docs/helpers/WebDriver.md b/docs/helpers/WebDriver.md index 96a6fbc89..1b315ae51 100644 --- a/docs/helpers/WebDriver.md +++ b/docs/helpers/WebDriver.md @@ -16,37 +16,45 @@ manipulate browser using Selenium WebDriver or PhantomJS. WebDriver requires Selenium Server and ChromeDriver/GeckoDriver to be installed. Those tools can be easily installed via NPM. Please check [Testing with WebDriver][2] for more details. +With the release of WebdriverIO version v8.14.0, and onwards, all driver management hassles are now a thing of the past 🙌. Read more [here][3]. +One of the significant advantages of this update is that you can now get rid of any driver services you previously had to manage, such as +`wdio-chromedriver-service`, `wdio-geckodriver-service`, `wdio-edgedriver-service`, `wdio-safaridriver-service`, and even `@wdio/selenium-standalone-service`. + +For those who require custom driver options, fear not; WebDriver Helper allows you to pass in driver options through custom WebDriver configuration. +If you have a custom grid, use a cloud service, or prefer to run your own driver, there's no need to worry since WebDriver Helper will only start a driver when there are no other connection information settings like hostname or port specified. + ## Configuration This helper should be configured in codecept.conf.js -Type: [object][16] +Type: [object][17] ### Properties -- `url` **[string][17]** base url of website to be tested. -- `browser` **[string][17]** Browser in which to perform testing. -- `basicAuth` **[string][17]?** (optional) the basic authentication to pass to base url. Example: {username: 'username', password: 'password'} -- `host` **[string][17]?** WebDriver host to connect. -- `port` **[number][22]?** WebDriver port to connect. -- `protocol` **[string][17]?** protocol for WebDriver server. -- `path` **[string][17]?** path to WebDriver server. -- `restart` **[boolean][32]?** restart browser between tests. -- `smartWait` **([boolean][32] | [number][22])?** **enables [SmartWait][36]**; wait for additional milliseconds for element to appear. Enable for 5 secs: "smartWait": 5000. -- `disableScreenshots` **[boolean][32]?** don't save screenshots on failure. -- `fullPageScreenshots` **[boolean][32]?** (optional - make full page screenshots on failure. -- `uniqueScreenshotNames` **[boolean][32]?** option to prevent screenshot override if you have scenarios with the same name in different suites. -- `keepBrowserState` **[boolean][32]?** keep browser state between tests when `restart` is set to false. -- `keepCookies` **[boolean][32]?** keep cookies between tests when `restart` set to false. -- `windowSize` **[string][17]?** default window size. Set to `maximize` or a dimension in the format `640x480`. -- `waitForTimeout` **[number][22]?** sets default wait time in _ms_ for all `wait*` functions. -- `desiredCapabilities` **[object][16]?** Selenium's [desired capabilities][6]. -- `manualStart` **[boolean][32]?** do not start browser before a test, start it manually inside a helper with `this.helpers["WebDriver"]._startBrowser()`. -- `timeouts` **[object][16]?** [WebDriver timeouts][37] defined as hash. -- `highlightElement` **[boolean][32]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). -- `devtoolsProtocol` **[boolean][32]?** enable devtools protocol. Default: false. More info: [https://webdriver.io/docs/automationProtocols/#devtools-protocol][38]. +- `url` **[string][18]** base url of website to be tested. +- `browser` **[string][18]** Browser in which to perform testing. +- `basicAuth` **[string][18]?** (optional) the basic authentication to pass to base url. Example: {username: 'username', password: 'password'} +- `host` **[string][18]?** WebDriver host to connect. +- `port` **[number][23]?** WebDriver port to connect. +- `protocol` **[string][18]?** protocol for WebDriver server. +- `path` **[string][18]?** path to WebDriver server. +- `restart` **[boolean][33]?** restart browser between tests. +- `smartWait` **([boolean][33] | [number][23])?** **enables [SmartWait][37]**; wait for additional milliseconds for element to appear. Enable for 5 secs: "smartWait": 5000. +- `disableScreenshots` **[boolean][33]?** don't save screenshots on failure. +- `fullPageScreenshots` **[boolean][33]?** (optional - make full page screenshots on failure. +- `uniqueScreenshotNames` **[boolean][33]?** option to prevent screenshot override if you have scenarios with the same name in different suites. +- `keepBrowserState` **[boolean][33]?** keep browser state between tests when `restart` is set to false. +- `keepCookies` **[boolean][33]?** keep cookies between tests when `restart` set to false. +- `windowSize` **[string][18]?** default window size. Set to `maximize` or a dimension in the format `640x480`. +- `waitForTimeout` **[number][23]?** sets default wait time in _ms_ for all `wait*` functions. +- `desiredCapabilities` **[object][17]?** Selenium's [desired capabilities][7]. +- `manualStart` **[boolean][33]?** do not start browser before a test, start it manually inside a helper with `this.helpers["WebDriver"]._startBrowser()`. +- `timeouts` **[object][17]?** [WebDriver timeouts][38] defined as hash. +- `highlightElement` **[boolean][33]?** highlight the interacting elements. Default: false. Note: only activate under verbose mode (--verbose). +- `logLevel` **[string][18]?** level of logging verbosity. Default: silent. Options: trace | debug | info | warn | error | silent. More info: [https://webdriver.io/docs/configuration/#loglevel][39] +- `devtoolsProtocol` **[boolean][33]?** enable devtools protocol. Default: false. More info: [https://webdriver.io/docs/automationProtocols/#devtools-protocol][40]. @@ -69,6 +77,27 @@ Example: } ``` +Testing Chrome locally is now more convenient than ever. You can define a browser channel, and WebDriver Helper will take care of downloading the specified browser version for you. +For example: + +```js +{ + helpers: { + WebDriver : { + smartWait: 5000, + browser: "chrome", + browserVersion: '116.0.5793.0', // or 'stable', 'beta', 'dev' or 'canary' + restart: false, + windowSize: "maximize", + timeouts: { + "script": 60000, + "page load": 10000 + } + } + } +} +``` + Example with basic authentication ```js @@ -90,7 +119,7 @@ Example with basic authentication ``` Additional configuration params can be used from [webdriverio -website][3]. +website][4]. ### Headless Chrome @@ -131,7 +160,7 @@ website][3]. ### Internet Explorer -Additional configuration params can be used from [IE options][4] +Additional configuration params can be used from [IE options][5] ```js { @@ -153,7 +182,7 @@ Additional configuration params can be used from [IE options][4] ### Selenoid Options -[Selenoid][5] is a modern way to run Selenium inside Docker containers. +[Selenoid][6] is a modern way to run Selenium inside Docker containers. Selenoid is easy to set up and provides more features than original Selenium Server. Use `selenoidOptions` to set Selenoid capabilities ```js @@ -219,13 +248,13 @@ For example, } ``` -Please refer to [Selenium - Proxy Object][6] for more +Please refer to [Selenium - Proxy Object][7] for more information. ### Cloud Providers WebDriver makes it possible to execute tests against services like `Sauce Labs` `BrowserStack` `TestingBot` -Check out their documentation on [available parameters][7] +Check out their documentation on [available parameters][8] Connecting to `BrowserStack` and `Sauce Labs` is simple. All you need to do is set the `user` and `key` parameters. WebDriver automatically know which @@ -274,9 +303,9 @@ plugins: { } ``` -See [complete reference on webdriver.io][8]. +See [complete reference on webdriver.io][9]. -> Alternatively, use [codeceptjs-saucehelper][9] for better reporting. +> Alternatively, use [codeceptjs-saucehelper][10] for better reporting. #### BrowserStack @@ -300,13 +329,13 @@ plugins: { } ``` -See [complete reference on webdriver.io][10]. +See [complete reference on webdriver.io][11]. -> Alternatively, use [codeceptjs-bshelper][11] for better reporting. +> Alternatively, use [codeceptjs-bshelper][12] for better reporting. #### TestingBot -> **Recommended**: use official [TestingBot Helper][12]. +> **Recommended**: use official [TestingBot Helper][13]. Alternatively, TestingBot can be configured via wdio service, which should be installed additionally: @@ -328,20 +357,20 @@ plugins: { } ``` -See [complete reference on webdriver.io][13]. +See [complete reference on webdriver.io][14]. #### Applitools Visual testing via Applitools service -> Use [CodeceptJS Applitools Helper][14] with Applitools wdio service. +> Use [CodeceptJS Applitools Helper][15] with Applitools wdio service. ### Multiremote Capabilities This is a work in progress but you can control two browsers at a time right out of the box. Individual control is something that is planned for a later version. -Here is the [webdriverio docs][15] on the subject +Here is the [webdriverio docs][16] on the subject ```js { @@ -385,7 +414,7 @@ Check if locator is type of "Shadow" #### Parameters -- `locator` **[object][16]** +- `locator` **[object][17]** ### _locate @@ -398,7 +427,7 @@ this.helpers['WebDriver']._locate({name: 'password'}).then //... #### Parameters -- `locator` **([string][17] | [object][16])** element located by CSS|XPath|strict locator. +- `locator` **([string][18] | [object][17])** element located by CSS|XPath|strict locator. - `smartWait` ### _locateCheckable @@ -411,7 +440,7 @@ this.helpers['WebDriver']._locateCheckable('I agree with terms and conditions'). #### Parameters -- `locator` **([string][17] | [object][16])** element located by CSS|XPath|strict locator. +- `locator` **([string][18] | [object][17])** element located by CSS|XPath|strict locator. ### _locateClickable @@ -424,7 +453,7 @@ const els = await this.helpers.WebDriver._locateClickable('Next page', '.pages') #### Parameters -- `locator` **([string][17] | [object][16])** element located by CSS|XPath|strict locator. +- `locator` **([string][18] | [object][17])** element located by CSS|XPath|strict locator. - `context` ### _locateFields @@ -437,7 +466,7 @@ this.helpers['WebDriver']._locateFields('Your email').then // ... #### Parameters -- `locator` **([string][17] | [object][16])** element located by CSS|XPath|strict locator. +- `locator` **([string][18] | [object][17])** element located by CSS|XPath|strict locator. ### _locateShadow @@ -445,7 +474,7 @@ Locate Element within the Shadow Dom #### Parameters -- `locator` **[object][16]** +- `locator` **[object][17]** ### _smartWait @@ -453,13 +482,13 @@ Smart Wait to locate an element #### Parameters -- `locator` **[object][16]** +- `locator` **[object][17]** ### acceptPopup Accepts the active JavaScript native popup window, as created by window.alert|window.confirm|window.prompt. Don't confuse popups with modal windows, as created by [various -libraries][18]. +libraries][19]. ### amOnPage @@ -474,7 +503,7 @@ I.amOnPage('/login'); // opens a login page #### Parameters -- `url` **[string][17]** url path or global url. +- `url` **[string][18]** url path or global url. Returns **void** automatically synchronized promise through #recorder @@ -491,8 +520,8 @@ I.appendField('password', secret('123456')); #### Parameters -- `field` **([string][17] | [object][16])** located by label|name|CSS|XPath|strict locator -- `value` **[string][17]** text value to append. +- `field` **([string][18] | [object][17])** located by label|name|CSS|XPath|strict locator +- `value` **[string][18]** text value to append. Returns **void** automatically synchronized promise through #recorder @@ -515,15 +544,15 @@ I.attachFile('form input[name=avatar]', 'data/avatar.jpg'); #### Parameters -- `locator` **([string][17] | [object][16])** field located by label|name|CSS|XPath|strict locator. -- `pathToFile` **[string][17]** local file path relative to codecept.conf.ts or codecept.conf.js config file. +- `locator` **([string][18] | [object][17])** field located by label|name|CSS|XPath|strict locator. +- `pathToFile` **[string][18]** local file path relative to codecept.conf.ts or codecept.conf.js config file. Returns **void** automatically synchronized promise through #recorder ### blur Remove focus from a text input, button, etc. -Calls [blur][19] on the element. +Calls [blur][20] on the element. Examples: @@ -540,8 +569,8 @@ I.dontSee('#add-to-cart-btn'); #### Parameters -- `locator` **([string][17] | [object][16])** field located by label|name|CSS|XPath|strict locator. -- `options` **any?** Playwright only: [Additional options][20] for available options object as 2nd argument. +- `locator` **([string][18] | [object][17])** field located by label|name|CSS|XPath|strict locator. +- `options` **any?** Playwright only: [Additional options][21] for available options object as 2nd argument. Returns **void** automatically synchronized promise through #recorder @@ -565,8 +594,8 @@ I.checkOption('agree', '//form'); #### Parameters -- `field` **([string][17] | [object][16])** checkbox located by label | name | CSS | XPath | strict locator. -- `context` **([string][17]? | [object][16])** (optional, `null` by default) element located by CSS | XPath | strict locator. +- `field` **([string][18] | [object][17])** checkbox located by label | name | CSS | XPath | strict locator. +- `context` **([string][18]? | [object][17])** (optional, `null` by default) element located by CSS | XPath | strict locator. Returns **void** automatically synchronized promise through #recorder @@ -582,7 +611,7 @@ I.clearCookie('test'); // Playwright currently doesn't support clear a particula #### Parameters -- `cookie` **[string][17]?** (optional, `null` by default) cookie name +- `cookie` **[string][18]?** (optional, `null` by default) cookie name ### clearField @@ -597,7 +626,7 @@ I.clearField('#email'); #### Parameters - `field` -- `editable` **([string][17] | [object][16])** field located by label|name|CSS|XPath|strict locator. +- `editable` **([string][18] | [object][17])** field located by label|name|CSS|XPath|strict locator. Returns **void** automatically synchronized promise through #recorder. @@ -627,8 +656,8 @@ I.click({css: 'nav a.login'}); #### Parameters -- `locator` **([string][17] | [object][16])** clickable link or button located by text, or any element located by CSS|XPath|strict locator. -- `context` **([string][17]? | [object][16] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator. +- `locator` **([string][18] | [object][17])** clickable link or button located by text, or any element located by CSS|XPath|strict locator. +- `context` **([string][18]? | [object][17] | null)** (optional, `null` by default) element to search in CSS|XPath|Strict locator. Returns **void** automatically synchronized promise through #recorder @@ -658,7 +687,7 @@ Returns **void** automatically synchronized promise through #recorder ### defineTimeout -Set [WebDriver timeouts][21] in realtime. +Set [WebDriver timeouts][22] in realtime. Timeouts are expected to be passed as object: @@ -683,8 +712,8 @@ I.dontSee('Login', '.nav'); // no login inside .nav element #### Parameters -- `text` **[string][17]** which is not present. -- `context` **([string][17] | [object][16])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search. +- `text` **[string][18]** which is not present. +- `context` **([string][18] | [object][17])?** (optional) element located by CSS|XPath|strict locator in which to perfrom search. Returns **void** automatically synchronized promise through #recorder @@ -705,7 +734,7 @@ I.dontSeeCheckboxIsChecked('agree'); // located by name #### Parameters -- `field` **([string][17] | [object][16])** located by label|name|CSS|XPath|strict locator. +- `field` **([string][18] | [object][17])** located by label|name|CSS|XPath|strict locator. Returns **void** automatically synchronized promise through #recorder @@ -719,7 +748,7 @@ I.dontSeeCookie('auth'); // no auth cookie #### Parameters -- `name` **[string][17]** cookie name. +- `name` **[string][18]** cookie name. Returns **void** automatically synchronized promise through #recorder @@ -735,7 +764,7 @@ I.dontSeeCurrentUrlEquals('http://mysite.com/login'); // absolute urls are also #### Parameters -- `url` **[string][17]** value to check. +- `url` **[string][18]** value to check. Returns **void** automatically synchronized promise through #recorder @@ -749,7 +778,7 @@ I.dontSeeElement('.modal'); // modal is not shown #### Parameters -- `locator` **([string][17] | [object][16])** located by CSS|XPath|Strict locator. +- `locator` **([string][18] | [object][17])** located by CSS|XPath|Strict locator. Returns **void** automatically synchronized promise through #recorder @@ -767,7 +796,7 @@ I.dontSeeElementInDOM('.nav'); // checks that element is not on page visible or #### Parameters -- `locator` **([string][17] | [object][16])** located by CSS|XPath|Strict locator. +- `locator` **([string][18] | [object][17])** located by CSS|XPath|Strict locator. Returns **void** automatically synchronized promise through #recorder @@ -777,7 +806,7 @@ Checks that current url does not contain a provided fragment. #### Parameters -- `url` **[string][17]** value to check. +- `url` **[string][18]** value to check. Returns **void** automatically synchronized promise through #recorder @@ -793,8 +822,8 @@ I.dontSeeInField({ css: 'form input.email' }, 'user@user.com'); // field by CSS #### Parameters -- `field` **([string][17] | [object][16])** located by label|name|CSS|XPath|strict locator. -- `value` **([string][17] | [object][16])** value to check. +- `field` **([string][18] | [object][17])** located by label|name|CSS|XPath|strict locator. +- `value` **([string][18] | [object][17])** value to check. Returns **void** automatically synchronized promise through #recorder @@ -809,7 +838,7 @@ I.dontSeeInSource(' * * Example: @@ -94,6 +102,28 @@ const config = {}; * } * ``` * + * Testing Chrome locally is now more convenient than ever. You can define a browser channel, and WebDriver Helper will take care of downloading the specified browser version for you. + * For example: + * + * ```js + * { + * helpers: { + * WebDriver : { + * smartWait: 5000, + * browser: "chrome", + * browserVersion: '116.0.5793.0', // or 'stable', 'beta', 'dev' or 'canary' + * restart: false, + * windowSize: "maximize", + * timeouts: { + * "script": 60000, + * "page load": 10000 + * } + * } + * } + * } + * ``` + * + * * Example with basic authentication * ```js * { @@ -435,7 +465,6 @@ class WebDriver extends Helper { _validateConfig(config) { const defaults = { logLevel: 'silent', - path: '/wd/hub', // codeceptjs remoteFileUpload: true, smartWait: 0, @@ -455,12 +484,17 @@ class WebDriver extends Helper { // override defaults with config config = Object.assign(defaults, config); - if (typeof config.host !== 'undefined') config.hostname = config.host; // webdriverio spec + if (config.host) { + // webdriverio spec + config.hostname = config.host; + config.path = '/wd/hub'; + } config.baseUrl = config.url || config.baseUrl; if (config.desiredCapabilities && Object.keys(config.desiredCapabilities).length) { config.capabilities = config.desiredCapabilities; } config.capabilities.browserName = config.browser || config.capabilities.browserName; + config.capabilities.browserVersion = config.browserVersion || config.capabilities.browserVersion; if (config.capabilities.chromeOptions) { config.capabilities['goog:chromeOptions'] = config.capabilities.chromeOptions; delete config.capabilities.chromeOptions; @@ -1702,7 +1736,11 @@ class WebDriver extends Helper { const res = await this._locate(withStrictLocator(locator), true); assertElementExists(res, locator); const elem = usingFirstElement(res); - return elem.moveTo({ xOffset, yOffset }); + try { + await elem.moveTo({ xOffset, yOffset }); + } catch (e) { + debug(e.message); + } } /** diff --git a/package.json b/package.json index ccc0d7dcc..1f9fbb4af 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "test:unit:webbapi:playwright": "mocha test/helper/Playwright_test.js", "test:unit:webbapi:puppeteer": "mocha test/helper/Puppeteer_test.js", "test:unit:webbapi:webDriver": "mocha test/helper/WebDriver_test.js", + "test:unit:webbapi:webDriver:noSeleniumServer": "mocha test/helper/WebDriver.noSeleniumServer_test.js", "test:unit:webbapi:webDriver:devtools": "mocha test/helper/WebDriver_devtools_test.js --exit", "test:unit:webbapi:testCafe": "mocha test/helper/TestCafe_test.js", "test:unit:expect": "mocha test/helper/Expect_test.js", @@ -85,6 +86,7 @@ "commander": "11.1.0", "cross-spawn": "7.0.3", "csstoxpath": "1.6.0", + "devtools": "8.27.2", "envinfo": "7.11.0", "escape-string-regexp": "4.0.0", "figures": "3.2.0", @@ -158,7 +160,7 @@ "typedoc-plugin-markdown": "3.17.1", "typescript": "5.3.3", "wdio-docker-service": "1.5.0", - "webdriverio": "8.3.8", + "webdriverio": "8.27.0", "xml2js": "0.6.2", "xpath": "0.0.34" }, diff --git a/test/helper/WebDriver.noSeleniumServer_test.js b/test/helper/WebDriver.noSeleniumServer_test.js new file mode 100644 index 000000000..0964e3ae9 --- /dev/null +++ b/test/helper/WebDriver.noSeleniumServer_test.js @@ -0,0 +1,1242 @@ +const assert = require('assert'); +const expect = require('chai').expect; +const path = require('path'); +const fs = require('fs'); + +const TestHelper = require('../support/TestHelper'); +const WebDriver = require('../../lib/helper/WebDriver'); +const AssertionFailedError = require('../../lib/assert/error'); +const Secret = require('../../lib/secret'); +global.codeceptjs = require('../../lib'); + +const siteUrl = TestHelper.siteUrl(); +let wd; + +describe('WebDriver - No Selenium server started', function () { + this.retries(1); + this.timeout(35000); + + before(() => { + global.codecept_dir = path.join(__dirname, '/../data'); + try { + fs.unlinkSync(dataFile); + } catch (err) { + // continue regardless of error + } + + wd = new WebDriver({ + url: siteUrl, + browser: 'chrome', + windowSize: '500x700', + smartWait: 0, // just to try + waitForTimeout: 5000, + capabilities: { + chromeOptions: { + args: ['--headless', '--disable-gpu', '--window-size=1280,1024'], + }, + }, + customLocatorStrategies: { + customSelector: (selector) => ( + { 'element-6066-11e4-a52e-4f735466cecf': `${selector}-foobar` } + ), + }, + }); + }); + + beforeEach(async () => { + this.wdBrowser = await wd._before(); + return this.wdBrowser; + }); + + afterEach(async () => wd._after()); + + describe('customLocatorStrategies', () => { + it('should include the custom strategy', async () => { + expect(wd.customLocatorStrategies.customSelector).to.not.be.undefined; + }); + + it('should be added to the browser locator strategies', async () => { + expect(this.wdBrowser.addLocatorStrategy).to.not.be.undefined; + }); + + it('throws on invalid custom selector', async () => { + try { + await wd.waitForEnabled({ madeUpSelector: '#text' }, 2); + } catch (e) { + expect(e.message).to.include('Please define "customLocatorStrategies"'); + } + }); + }); + + describe('open page : #amOnPage', () => { + it('should open main page of configured site', async () => { + await wd.amOnPage('/'); + const url = await wd.grabCurrentUrl(); + url.should.eql(`${siteUrl}/`); + }); + + it('should open any page of configured site', async () => { + await wd.amOnPage('/info'); + const url = await wd.grabCurrentUrl(); + url.should.eql(`${siteUrl}/info`); + }); + + it('should open absolute url', async () => { + await wd.amOnPage(siteUrl); + const url = await wd.grabCurrentUrl(); + url.should.eql(`${siteUrl}/`); + }); + }); + + describe('see text : #see', () => { + it('should fail when text is not on site', async () => { + await wd.amOnPage('/'); + + try { + await wd.see('Something incredible!'); + } catch (e) { + e.should.be.instanceOf(AssertionFailedError); + e.inspect().should.include('web page'); + } + + try { + await wd.dontSee('Welcome'); + } catch (e) { + e.should.be.instanceOf(AssertionFailedError); + e.inspect().should.include('web page'); + } + }); + }); + + describe.skip('check fields: #seeInField, #seeCheckboxIsChecked, ...', () => { + it('should throw error if field is not empty', async () => { + await wd.amOnPage('/form/empty'); + + try { + await wd.seeInField('#empty_input', 'Ayayay'); + } catch (e) { + e.should.be.instanceOf(AssertionFailedError); + e.inspect().should.be.equal('expected fields by #empty_input to include "Ayayay"'); + } + }); + + it('should check values in checkboxes', async () => { + await wd.amOnPage('/form/field_values'); + await wd.dontSeeInField('checkbox[]', 'not seen one'); + await wd.seeInField('checkbox[]', 'see test one'); + await wd.dontSeeInField('checkbox[]', 'not seen two'); + await wd.seeInField('checkbox[]', 'see test two'); + await wd.dontSeeInField('checkbox[]', 'not seen three'); + await wd.seeInField('checkbox[]', 'see test three'); + }); + + it('should check values are the secret type in checkboxes', async () => { + await wd.amOnPage('/form/field_values'); + await wd.dontSeeInField('checkbox[]', Secret.secret('not seen one')); + await wd.seeInField('checkbox[]', Secret.secret('see test one')); + await wd.dontSeeInField('checkbox[]', Secret.secret('not seen two')); + await wd.seeInField('checkbox[]', Secret.secret('see test two')); + await wd.dontSeeInField('checkbox[]', Secret.secret('not seen three')); + await wd.seeInField('checkbox[]', Secret.secret('see test three')); + }); + + it('should check values with boolean', async () => { + await wd.amOnPage('/form/field_values'); + await wd.seeInField('checkbox1', true); + await wd.dontSeeInField('checkbox1', false); + await wd.seeInField('checkbox2', false); + await wd.dontSeeInField('checkbox2', true); + await wd.seeInField('radio2', true); + await wd.dontSeeInField('radio2', false); + await wd.seeInField('radio3', false); + await wd.dontSeeInField('radio3', true); + }); + + it('should check values in radio', async () => { + await wd.amOnPage('/form/field_values'); + await wd.seeInField('radio1', 'see test one'); + await wd.dontSeeInField('radio1', 'not seen one'); + await wd.dontSeeInField('radio1', 'not seen two'); + await wd.dontSeeInField('radio1', 'not seen three'); + }); + + it('should check values in select', async () => { + await wd.amOnPage('/form/field_values'); + await wd.seeInField('select1', 'see test one'); + await wd.dontSeeInField('select1', 'not seen one'); + await wd.dontSeeInField('select1', 'not seen two'); + await wd.dontSeeInField('select1', 'not seen three'); + }); + + it('should check for empty select field', async () => { + await wd.amOnPage('/form/field_values'); + await wd.seeInField('select3', ''); + }); + + it('should check for select multiple field', async () => { + await wd.amOnPage('/form/field_values'); + await wd.dontSeeInField('select2', 'not seen one'); + await wd.seeInField('select2', 'see test one'); + await wd.dontSeeInField('select2', 'not seen two'); + await wd.seeInField('select2', 'see test two'); + await wd.dontSeeInField('select2', 'not seen three'); + await wd.seeInField('select2', 'see test three'); + }); + + it('should return error when element has no value attribute', async () => { + await wd.amOnPage('https://codecept.io/quickstart'); + + try { + await wd.seeInField('#search_input_react', 'WebDriver1'); + } catch (e) { + e.should.be.instanceOf(Error); + } + }); + }); + + describe('Force Right Click: #forceRightClick', () => { + it('it should forceRightClick', async () => { + await wd.amOnPage('/form/rightclick'); + await wd.dontSee('right clicked'); + await wd.forceRightClick('Lorem Ipsum'); + await wd.see('right clicked'); + }); + + it('it should forceRightClick by locator', async () => { + await wd.amOnPage('/form/rightclick'); + await wd.dontSee('right clicked'); + await wd.forceRightClick('.context a'); + await wd.see('right clicked'); + }); + + it('it should forceRightClick by locator and context', async () => { + await wd.amOnPage('/form/rightclick'); + await wd.dontSee('right clicked'); + await wd.forceRightClick('Lorem Ipsum', '.context'); + await wd.see('right clicked'); + }); + }); + + describe.skip('#pressKey, #pressKeyDown, #pressKeyUp', () => { + it('should be able to send special keys to element', async () => { + await wd.amOnPage('/form/field'); + await wd.appendField('Name', '-'); + + await wd.pressKey(['Right Shift', 'Home']); + await wd.pressKey('Delete'); + + // Sequence only executes up to first non-modifier key ('Digit1') + await wd.pressKey(['SHIFT_RIGHT', 'Digit1', 'Digit4']); + await wd.pressKey('1'); + await wd.pressKey('2'); + await wd.pressKey('3'); + await wd.pressKey('ArrowLeft'); + await wd.pressKey('Left Arrow'); + await wd.pressKey('arrow_left'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('a'); + await wd.pressKey('KeyB'); + await wd.pressKeyUp('ShiftLeft'); + await wd.pressKey('C'); + await wd.seeInField('Name', '!ABC123'); + }); + + it('should use modifier key based on operating system', async () => { + await wd.amOnPage('/form/field'); + await wd.fillField('Name', 'value that is cleared using select all shortcut'); + + await wd.pressKey(['CommandOrControl', 'A']); + await wd.pressKey('Backspace'); + await wd.dontSeeInField('Name', 'value that is cleared using select all shortcut'); + }); + + it('should show correct numpad or punctuation key when Shift modifier is active', async () => { + await wd.amOnPage('/form/field'); + await wd.fillField('Name', ''); + + await wd.pressKey(';'); + await wd.pressKey(['Shift', ';']); + await wd.pressKey(['Shift', 'Semicolon']); + await wd.pressKey('='); + await wd.pressKey(['Shift', '=']); + await wd.pressKey(['Shift', 'Equal']); + await wd.pressKey('*'); + await wd.pressKey(['Shift', '*']); + await wd.pressKey(['Shift', 'Multiply']); + await wd.pressKey('+'); + await wd.pressKey(['Shift', '+']); + await wd.pressKey(['Shift', 'Add']); + await wd.pressKey(','); + await wd.pressKey(['Shift', ',']); + await wd.pressKey(['Shift', 'Comma']); + await wd.pressKey(['Shift', 'NumpadComma']); + await wd.pressKey(['Shift', 'Separator']); + await wd.pressKey('-'); + await wd.pressKey(['Shift', '-']); + await wd.pressKey(['Shift', 'Subtract']); + await wd.pressKey('.'); + await wd.pressKey(['Shift', '.']); + await wd.pressKey(['Shift', 'Decimal']); + await wd.pressKey(['Shift', 'Period']); + await wd.pressKey('/'); + await wd.pressKey(['Shift', '/']); + await wd.pressKey(['Shift', 'Divide']); + await wd.pressKey(['Shift', 'Slash']); + + await wd.seeInField('Name', ';::=++***+++,<<<<-_-.>.>/?/?'); + }); + + it('should show correct number key when Shift modifier is active', async () => { + await wd.amOnPage('/form/field'); + await wd.fillField('Name', ''); + + await wd.pressKey('0'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('0'); + await wd.pressKey('Digit0'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('1'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('1'); + await wd.pressKey('Digit1'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('2'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('2'); + await wd.pressKey('Digit2'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('3'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('3'); + await wd.pressKey('Digit3'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('4'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('4'); + await wd.pressKey('Digit4'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('5'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('5'); + await wd.pressKey('Digit5'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('6'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('6'); + await wd.pressKey('Digit6'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('7'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('7'); + await wd.pressKey('Digit7'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('8'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('8'); + await wd.pressKey('Digit8'); + await wd.pressKeyUp('Shift'); + + await wd.pressKey('9'); + await wd.pressKeyDown('Shift'); + await wd.pressKey('9'); + await wd.pressKey('Digit9'); + await wd.pressKeyUp('Shift'); + + await wd.seeInField('Name', '0))1!!2@@3##4$$5%%6^^7&&8**9(('); + }); + }); + + describe('#seeInSource, #grabSource', () => { + it('should check for text to be in HTML source', async () => { + await wd.amOnPage('/'); + await wd.seeInSource('