Skip to content

Commit

Permalink
Tests for the inject page
Browse files Browse the repository at this point in the history
  • Loading branch information
zalmoxisus committed Oct 17, 2015
1 parent d59dd03 commit f133263
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/browser/extension/inject/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ window.addEventListener('load', () => {
injectDiv.style.width = '200px';
injectDiv.style.border = '1px solid #ccc';
injectDiv.style.textAlign = 'center';
injectDiv.className = 'browser-redux';
document.body.appendChild(injectDiv);

React.render(
Expand Down
Empty file removed test/.gitkeep
Empty file.
41 changes: 41 additions & 0 deletions test/extension/injectpage.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import webdriver from 'selenium-webdriver';
import expect from 'expect';
import { check, doBefore, doAfter } from '../shared/functions';

describe('inject page (in github.com)', function() {

before(function(done) {
doBefore.call(this, done, () => {
return this.driver.get('https://github.com');
});
});

after(doAfter);

it('should open Github', function(done) {
this.driver.getTitle().then((title) => {
expect(title).toEqual('GitHub · Where software is built');
done();
});
});

it('should render inject app', function(done) {
this.timeout(8000);
this.driver.wait(() =>
this.driver.findElements(webdriver.By.className('browser-redux'))
.then(elems => elems.length > 0)
, 15000, 'Inject app not found')
.then(() => done());
});

it('should contain text "Clicked: 0 times"', function(done) {
this.driver
.findElements(webdriver.By.xpath(
'//div[@class="browser-redux"][//*[contains(text(), "Clicked:")]][//*[contains(text(), "0")]][//*[contains(text(), "times")]]'
))
.then((elems) => { expect(elems.length).toBe(1); })
.then(() => done());
});

});

28 changes: 28 additions & 0 deletions test/shared/functions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import webdriver from 'selenium-webdriver';

export function check(done, func) {
try {
func();
} catch (ex) {
done(ex);
}
}

export function doBefore(done, action, load = './build/extension', port = 9515, browser = 'chrome', timeout = 6000) {
this.timeout(timeout);
this.driver = new webdriver.Builder()
.usingServer(`http://localhost:${port}`)
.withCapabilities({
chromeOptions: {
args: [ `load-extension=${load}` ]
}
})
.forBrowser(browser)
.build();
action().then(done);
}

export function doAfter(done, timeout = 20000) {
this.timeout(timeout);
this.driver.quit().then(done);
}

0 comments on commit f133263

Please sign in to comment.