Bug 1336124 - Add assert.session for checking if session is active; r=maja_zf

MozReview-Commit-ID: CmHFag2q1V2

--HG--
extra : rebase_source : 526e01466ce4a00a091dd88cb060d166c6ac4245
This commit is contained in:
Andreas Tolfsen 2017-02-02 16:09:14 +00:00
Родитель 90ac2e75ba
Коммит 73f85ac684
2 изменённых файлов: 29 добавлений и 0 удалений

Просмотреть файл

@ -21,6 +21,26 @@ const isFirefox = () => Services.appinfo.name == "Firefox";
/** Shorthands for common assertions made in Marionette. */
this.assert = {};
/**
* Asserts that Marionette has a session.
*
* @param {GeckoDriver} driver
* Marionette driver instance.
* @param {string=} msg
* Custom error message.
*
* @return {string}
* Session ID.
*
* @throws {InvalidSessionIdError}
* If |driver| does not have a session ID.
*/
assert.session = function (driver, msg = "") {
assert.that(sessionID => sessionID,
msg, InvalidSessionIdError)(driver.sessionId);
return driver.sessionId;
};
/**
* Asserts that the current browser is Firefox Desktop.
*

Просмотреть файл

@ -9,6 +9,15 @@ const {utils: Cu} = Components;
Cu.import("chrome://marionette/content/assert.js");
Cu.import("chrome://marionette/content/error.js");
add_test(function test_session() {
assert.session({sessionId: "foo"});
for (let typ of [null, undefined, ""]) {
Assert.throws(() => assert.session({sessionId: typ}), InvalidSessionIdError);
}
run_next_test();
});
add_test(function test_platforms() {
// at least one will fail
let raised;