"use strict";

var UserPages = require("./UserPages.js");
var MailParser = require("mailparser").MailParser;
var fs = require("fs");

var restUrl = "http://localhost:9080/";


var hasClass = function (element, cls) {
    return element.getAttribute("class").then(function (classes) {
        return classes.split(" ").indexOf(cls) !== -1;
    });
};

var parseEmail = function(filename, callback) {
    var mailparser = new MailParser();

    mailparser.on("end", callback);
    mailparser.write(fs.readFileSync(filename));
    mailparser.end();
};

module.exports = {
    restUrl: restUrl,
    register: UserPages.register,
    login: UserPages.login,
    logout: UserPages.logout,
    isLoggedIn: UserPages.isLoggedIn,
    loginParticipant: UserPages.loginParticipant,
    participantName: UserPages.participantName,
    loginOtherParticipant: UserPages.loginOtherParticipant,
    hasClass: hasClass,
    parseEmail: parseEmail
}

@@ -125,16 +125,56 @@
 e(%22fs%22);
+%0Avar EC = protractor.ExpectedConditions;
 %0A%0Avar re
@@ -583,16 +583,172 @@
 ();%0A%7D;%0A%0A
+var waitAndClick = function(element) %7B%0A    var isClickable = EC.elementToBeClickable(element);%0A    browser.wait(isClickable, 5000);%0A    element.click();%0A%7D%0A%0A
 module.e
@@ -1092,16 +1092,16 @@
 sClass,%0A
-
     pars
@@ -1118,11 +1118,43 @@
 rseEmail
+,%0A    waitAndClick: waitAndClick
 %0A%7D%0A

Add protractor test function to click after an element is loaded