Skip to content

Commit

Permalink
Merge branch 'master' of github.com:Codeception/CodeceptJS
Browse files Browse the repository at this point in the history
  • Loading branch information
DavertMik committed Feb 17, 2018
2 parents 7124642 + ab24a51 commit f5badc5
Show file tree
Hide file tree
Showing 21 changed files with 130 additions and 75 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ addons:
services:
- docker
before_install:
- docker pull selenium/standalone-chrome:3.8
- docker pull selenium/standalone-chrome:3.9.1-actinium
before_script:
- docker run -d --net=host selenium/standalone-chrome:3.8
- docker run -d --net=host --shm-size=2g selenium/standalone-chrome:3.8
- export DBUS_SESSION_BUS_ADDRESS=/dev/null
- export DISPLAY=:99.0
- sh -e /etc/init.d/xvfb start
- chmod -R 777 test/data
Expand All @@ -32,5 +33,4 @@ before_script:
- sleep 10
script:
- npm build && npm test
- './node_modules/.bin/mocha test/rest'
- './node_modules/.bin/mocha test/helper/${HELPER}_test.js'
2 changes: 0 additions & 2 deletions docs/acceptance.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ Strict locators allow to specify additional locator types:
```js
// locate form element by name
I.seeElement({name: 'password'});
// locate element by text
I.seeElement({text: 'press me'});
// locate element by id
I.seeElement({id: 'users'});
```
Expand Down
2 changes: 1 addition & 1 deletion docs/basics.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ Usage: `within('section', ()=>{})`

```js
I.amOnPage('https://github.com');
within('.form-signup-home', () => {
within('.js-signup-form', () => {
I.fillField('user[login]', 'User');
I.fillField('user[email]', '[email protected]');
I.fillField('user[password]', '[email protected]');
Expand Down
2 changes: 1 addition & 1 deletion docs/nightmare.md
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ When opening a web page you can set headers as well. `amOnPage` methods can take

```js
// use basic http auth
I.amOnPage('/admin', [{'Authorization': 'Basic '+token}]);
I.amOnPage('/admin', { 'Authorization': 'Basic '+token });
```

As a small bonus: all `console.log` calls on a page will be also shown in `--debug` mode.
Expand Down
6 changes: 6 additions & 0 deletions docs/webapi/grabSource.mustache
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Retrieves page source and returns it to test.
Resumes test execution, so should be used inside an async function.

```js
let pageSource = await I.grabSource();
```
2 changes: 1 addition & 1 deletion docs/webapi/pressKey.mustache
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Presses a key on a focused element.
Speical keys like 'Enter', 'Control', [etc](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value)
Special keys like 'Enter', 'Control', [etc](https://code.google.com/p/selenium/wiki/JsonWireProtocol#/session/:sessionId/element/:id/value)
will be replaced with corresponding unicode.
If modifier key is used (Control, Command, Alt, Shift) in array, it will be released afterwards.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Waits for an element to become not attached to the DOM on a page (by default wai
Element can be located by CSS or XPath.

```
I.waitForStalenessOf('#popup');
I.waitForDetached('#popup');
```

@param locator element located by CSS|XPath|strict locator
Expand Down
3 changes: 2 additions & 1 deletion lib/helper/Nightmare.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ class Nightmare extends Helper {
this.browser = this.Nightmare(this.options);
await this.browser;
}
await this.browser.goto('about:blank'); // Load a blank page so .saveScreenshot (/evaluate) will work
this.isRunning = true;
this.browser.on('dom-ready', () => this._injectClientScripts());
this.browser.on('did-start-loading', () => this._injectClientScripts());
Expand Down Expand Up @@ -340,7 +341,7 @@ class Nightmare extends Helper {
* In a second argument a list of request headers can be passed:
*
* ```js
* I.amOnPage('/auth', [{'x-my-custom-header': 'some value'}])
* I.amOnPage('/auth', { 'x-my-custom-header': 'some value' })
* ```
*/
async amOnPage(url, headers = null) {
Expand Down
33 changes: 22 additions & 11 deletions lib/helper/Protractor.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,7 @@ class Protractor extends Helper {
}

/**
* {{> ../webapi/seeInSource }}
* {{> ../webapi/grabSource }}
*/
async grabSource() {
return this.browser.getPageSource();
Expand Down Expand Up @@ -899,19 +899,30 @@ class Protractor extends Helper {
return this.browser.wait(EC.presenceOf(el), aSec * 1000);
}

async waitUntilExists(locator, sec = null) {
console.log(`waitUntilExists deprecated:
* use 'waitForElement' to wait for element to be attached
* use 'waitForDetached to wait for element to be removed'`);
return this.waitForDetached(locator, sec);
}

/**
* {{> ../webapi/waitUntilExists }}
* {{> ../webapi/waitForDetached }}
*/
waitUntilExists(locator, sec = null) {
async waitForDetached(locator, sec = null) {
const aSec = sec || this.options.waitForTimeout;
const el = global.element(guessLocator(locator) || global.by.css(locator));
return this.browser.wait(EC.not(EC.presenceOf(el)), aSec * 1000);
}

/**
* Waits for element to become clickable for number of seconds.
*
* ```js
* I.waitForClickable('#link');
* ```
*/
waitForClickable(locator, sec = null) {
async waitForClickable(locator, sec = null) {
const aSec = sec || this.options.waitForTimeout;
const el = global.element(guessLocator(locator) || global.by.css(locator));
return this.browser.wait(EC.elementToBeClickable(el), aSec * 1000);
Expand All @@ -920,7 +931,7 @@ class Protractor extends Helper {
/**
* {{> ../webapi/waitForVisible }}
*/
waitForVisible(locator, sec = null) {
async waitForVisible(locator, sec = null) {
const aSec = sec || this.options.waitForTimeout;
const el = global.element(guessLocator(locator) || global.by.css(locator));
return this.browser.wait(EC.visibilityOf(el), aSec * 1000);
Expand All @@ -929,23 +940,23 @@ class Protractor extends Helper {
/**
* {{> ../webapi/waitForInvisible }}
*/
waitForInvisible(locator, sec = null) {
async waitForInvisible(locator, sec = null) {
const aSec = sec || this.options.waitForTimeout;
const el = global.element(guessLocator(locator) || global.by.css(locator));
return this.browser.wait(EC.invisibilityOf(el), aSec * 1000);
}

/**
* {{> ../webapi/waitForStalenessOf }}
*/
waitForStalenessOf(locator, sec = null) {
async waitForStalenessOf(locator, sec = null) {
console.log(`waitForStalenessOf deprecated.
* Use waitForDetached to wait for element to be removed from page
* Use waitForInvisible to wait for element to be hidden on page`);
return this.waitForInvisible(locator, sec);
}

/**
* {{> ../webapi/waitForText }}
*/
waitForText(text, sec = null, context = null) {
async waitForText(text, sec = null, context = null) {
if (!context) {
context = this.context;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/Puppeteer.js
Original file line number Diff line number Diff line change
Expand Up @@ -912,7 +912,7 @@ class Puppeteer extends Helper {
}

/**
* {{> ../webapi/seeInSource }}
* {{> ../webapi/grabSource }}
*/
async grabSource() {
return this.page.content();
Expand Down
24 changes: 18 additions & 6 deletions lib/helper/WebDriverIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -873,7 +873,7 @@ class WebDriverIO extends Helper {
}

/**
* {{> ../webapi/seeInSource }}
* {{> ../webapi/grabSource }}
* Appium: support
*/
async grabSource() {
Expand Down Expand Up @@ -1419,13 +1419,16 @@ class WebDriverIO extends Helper {
}, aSec * 1000, `element (${locator}) still not present on page after ${aSec} sec`);
}

/**
* {{> ../webapi/waitUntilExists }}
* Appium: support
*/
async waitUntilExists(locator, sec = null) {
<<<<<<< HEAD
const aSec = sec || this.options.waitForTimeout;
return this.browser.waitForExist(withStrictLocator.call(this, locator), aSec * 1000);
=======
console.log(`waitUntilExists deprecated:
* use 'waitForElement' to wait for element to be attached
* use 'waitForDetached to wait for element to be removed'`);
return this.waitForStalenessOf(locator, sec);
>>>>>>> ab24a51a7bb977452cdff9f26cf772fa6de7ed77
}


Expand Down Expand Up @@ -1594,10 +1597,16 @@ class WebDriverIO extends Helper {
return this.waitForInvisible(locator, sec);
}

async waitForStalenessOf(locator, sec = null) {
console.log('waitForStalenessOf deprecated. Use waitForDetached instead');
return this.waitForDetached(locator, sec);
}

/**
* {{> ../webapi/waitForStalenessOf }}
* {{> ../webapi/waitForDetached }}
* Appium: support
*/
<<<<<<< HEAD
async waitForStalenessOf(locator, sec = null) {
return this.waitUntilNotExists(locator, sec);
}
Expand All @@ -1607,6 +1616,9 @@ class WebDriverIO extends Helper {
* Appium: support
*/
async waitUntilNotExists(locator, sec = null) {
=======
async waitForDetached(locator, sec = null) {
>>>>>>> ab24a51a7bb977452cdff9f26cf772fa6de7ed77
const aSec = sec || this.options.waitForTimeout;
return this.browser.waitUntil(async () => {
const res = await this.browser.elements(withStrictLocator.call(this, locator));
Expand Down
1 change: 1 addition & 0 deletions test/.env
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ SITE_URL=http://php:8000
SELENIUM_HOST=selenium.chrome
SELENIUM_PORT=4444
JSON_SERVER_URL=http://json_server:8010
DBUS_SESSION_BUS_ADDRESS=/dev/null
5 changes: 5 additions & 0 deletions test/acceptance/codecept.WebDriverIO.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ module.exports.config = {
browser: 'chrome',
host: TestHelper.seleniumHost(),
port: TestHelper.seleniumPort(),
desiredCapabilities: {
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,1024'],
},
},
},

},
Expand Down
2 changes: 1 addition & 1 deletion test/acceptance/within_test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Feature('within');
Feature('within', { retries: 3 });

Scenario('within on form @WebDriverIO @Protractor @Nightmare @Puppeteer', (I) => {
I.amOnPage('/form/bug1467');
Expand Down
3 changes: 2 additions & 1 deletion test/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ services:
- node_modules:/codecept/node_modules

selenium.chrome:
image: selenium/standalone-chrome:3.5.2-antimony
image: selenium/standalone-chrome:3.9.1-actinium
shm_size: 2g
ports:
- 4444:4444

Expand Down
5 changes: 5 additions & 0 deletions test/helper/ProtractorWeb_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ describe('Protractor-NonAngular', function () {
restart: false,
seleniumAddress: TestHelper.seleniumAddress(),
waitForTimeout: 5000,
desiredCapabilities: {
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,1024'],
},
},
});
return I._init().then(() => I._beforeSuite().then(() => {
browser = I.browser;
Expand Down
5 changes: 5 additions & 0 deletions test/helper/Protractor_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ describe('Protractor', function () {
seleniumAddress: TestHelper.seleniumAddress(),
angular: true,
waitForTimeout: 5000,
desiredCapabilities: {
chromeOptions: {
args: ['--headless', '--disable-gpu', '--window-size=1280,1024'],
},
},
});
return I._init().then(() => I._beforeSuite());
});
Expand Down
17 changes: 16 additions & 1 deletion test/helper/Puppeteer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const siteUrl = TestHelper.siteUrl();

describe('Puppeteer', function () {
this.timeout(35000);
// this.retries(1);
this.retries(1);

before(() => {
global.codecept_dir = path.join(__dirname, '/../data');
Expand Down Expand Up @@ -101,14 +101,17 @@ describe('Puppeteer', function () {

describe('#switchToNextTab, #switchToPreviousTab, #openNewTab, #closeCurrentTab, #closeOtherTabs, #grabNumberOfOpenTabs', () => {
it('should only have 1 tab open when the browser starts and navigates to the first page', () => I.amOnPage('/')
.then(() => I.wait(1))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 1)));

it('should switch to next tab', () => I.amOnPage('/info')
.then(() => I.wait(1))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 1))
.then(() => I.click('New tab'))
.then(() => I.switchToNextTab())
.then(() => I.wait(2))
.then(() => I.seeCurrentUrlEquals('/login'))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 2)));
Expand All @@ -117,6 +120,7 @@ describe('Puppeteer', function () {
.then(() => I.click('More info'))
.then(() => I.wait(1)) // Wait is required because the url is change by previous statement (maybe related to #914)
.then(() => I.switchToNextTab(2))
.then(() => I.wait(2))
.then(() => assert.equal(true, false, 'Throw an error if it gets this far (which it should not)!'))
.catch((e) => {
assert.equal(e.message, 'There is no ability to switch to next tab with offset 2');
Expand All @@ -125,42 +129,52 @@ describe('Puppeteer', function () {
it('should close current tab', () => I.amOnPage('/info')
.then(() => I.click('New tab'))
.then(() => I.switchToNextTab())
.then(() => I.wait(2))
.then(() => I.seeInCurrentUrl('/login'))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 2))
.then(() => I.closeCurrentTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('/info'))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 1)));

it('should close other tabs', () => I.amOnPage('/')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('about:blank'))
.then(() => I.amOnPage('/info'))
.then(() => I.click('New tab'))
.then(() => I.switchToNextTab())
.then(() => I.wait(2))
.then(() => I.seeInCurrentUrl('/login'))
.then(() => I.closeOtherTabs())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('/login'))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 1)));

it('should open new tab', () => I.amOnPage('/info')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('about:blank'))
.then(() => I.grabNumberOfOpenTabs())
.then(numPages => assert.equal(numPages, 2)));

it('should switch to previous tab', () => I.amOnPage('/info')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.seeInCurrentUrl('about:blank'))
.then(() => I.switchToPreviousTab())
.then(() => I.wait(2))
.then(() => I.seeInCurrentUrl('/info')));

it('should assert when there is no ability to switch to previous tab', () => I.amOnPage('/info')
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.waitInUrl('about:blank'))
.then(() => I.switchToPreviousTab(2))
.then(() => I.wait(2))
.then(() => I.waitInUrl('/info'))
.catch((e) => {
assert.equal(e.message, 'There is no ability to switch to previous tab with offset 2');
Expand Down Expand Up @@ -495,6 +509,7 @@ describe('Puppeteer', function () {
console.log('Test log entry 1');
}))
.then(() => I.openNewTab())
.then(() => I.wait(1))
.then(() => I.amOnPage('/info'))
.then(() => I.executeScript(() => {
console.log('Test log entry 2');
Expand Down
Loading

0 comments on commit f5badc5

Please sign in to comment.