From 95acf63ea38eae6762fb8c7d3ac672661f711dfd Mon Sep 17 00:00:00 2001 From: Kegan Dougal Date: Mon, 22 Sep 2014 16:50:12 +0100 Subject: [PATCH] Add working protractor e2e test. This uses the ignoreSynchronization flag because of the longpoll on the event stream. It would be better to use $interval, but couldn't get that to *reliably* work when testing. I suspect that $interval won't help us here, since there is genuinely an open $http connection, as we're doing a long poll. https://github.com/angular/protractor/issues/49 for more info. --- webclient/test/README | 3 ++- webclient/test/e2e/home.spec.js | 16 ++++++++++++++++ webclient/test/e2e/user.spec.js | 6 ------ webclient/test/protractor.conf.js | 9 ++++++++- 4 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 webclient/test/e2e/home.spec.js delete mode 100644 webclient/test/e2e/user.spec.js diff --git a/webclient/test/README b/webclient/test/README index c13010e61..1a7bc832c 100644 --- a/webclient/test/README +++ b/webclient/test/README @@ -18,7 +18,7 @@ on. If you do, edit the config to point to that url): Create a file "environment-protractor.js" in this directory and type: module.exports = { seleniumAddress: 'http://localhost:4444/wd/hub', - loginUrl: "http://localhost:8008/_matrix/client/#/login", + baseUrl: "http://localhost:8008", username: "YOUR_TEST_USERNAME", password: "YOUR_TEST_PASSWORD" } @@ -26,6 +26,7 @@ on. If you do, edit the config to point to that url): Running e2e tests: protractor protractor.conf.js +NOTE: This will create a public room on the target home server. diff --git a/webclient/test/e2e/home.spec.js b/webclient/test/e2e/home.spec.js new file mode 100644 index 000000000..470237d55 --- /dev/null +++ b/webclient/test/e2e/home.spec.js @@ -0,0 +1,16 @@ +var env = require("../environment-protractor.js"); + +describe("home page", function() { + + beforeEach(function() { + ptor = protractor.getInstance(); + // FIXME we use longpoll on the event stream, and I can't get $interval + // playing nicely with it. Patches welcome to fix this. + ptor.ignoreSynchronization = true; + }); + + it("should have a title", function() { + browser.get(env.baseUrl); + expect(browser.getTitle()).toEqual("[matrix]"); + }); +}); diff --git a/webclient/test/e2e/user.spec.js b/webclient/test/e2e/user.spec.js deleted file mode 100644 index bbac53899..000000000 --- a/webclient/test/e2e/user.spec.js +++ /dev/null @@ -1,6 +0,0 @@ -describe("user page", function() { - it("should have a title", function() { - browser.get("http://matrix.org/alpha/#/login"); - expect(browser.getTitle()).toEqual("[matrix]"); - }); -}); diff --git a/webclient/test/protractor.conf.js b/webclient/test/protractor.conf.js index 720096b39..76ae7b712 100644 --- a/webclient/test/protractor.conf.js +++ b/webclient/test/protractor.conf.js @@ -3,9 +3,16 @@ exports.config = { seleniumAddress: env.seleniumAddress, specs: ['e2e/*.spec.js'], onPrepare: function() { - browser.driver.get(env.loginUrl); + browser.driver.get(env.baseUrl); browser.driver.findElement(by.id("user_id")).sendKeys(env.username); browser.driver.findElement(by.id("password")).sendKeys(env.password); browser.driver.findElement(by.id("login")).click(); + + // wait till the login is done, detect via url change + browser.driver.wait(function() { + return browser.driver.getCurrentUrl().then(function(url) { + return !(/login/.test(url)) + }); + }); } }