+ var LOCATION = 'test';
+ var TEST_TIMEOUT = 10000;
+ var TEST_FILE_NAME_0 = 'index.html';
+ var TEST_FILE_NAME_1 = 'test.txt';
+ var app;
+
+ // tests which are used more than once
+ function login(done) {
+ browser.manage().deleteAllCookies();
+ browser.get('https://' + app.fqdn + '/_admin');
+
+ browser.wait(until.elementLocated(by.id('inputUsername')), TEST_TIMEOUT).then(function () {
+ browser.wait(until.elementIsVisible(browser.findElement(by.id('inputUsername'))), TEST_TIMEOUT).then(function () {
+ browser.findElement(by.id('inputUsername')).sendKeys(process.env.USERNAME);
+ browser.findElement(by.id('inputPassword')).sendKeys(process.env.PASSWORD);
+ browser.findElement(by.id('loginForm')).submit();
+
+ browser.wait(until.elementIsVisible(browser.findElement(by.id('logoutButton'))), TEST_TIMEOUT).then(function () {
+ done();
+ });
+ });
+ });
+ }
+
+ function logout(done) {
+ browser.get('https://' + app.fqdn + '/_admin');
+
+ browser.wait(until.elementLocated(by.id('logoutButton')), TEST_TIMEOUT).then(function () {
+ browser.wait(until.elementIsVisible(browser.findElement(by.id('logoutButton'))), TEST_TIMEOUT).then(function () {
+ browser.findElement(by.id('logoutButton')).click();
+
+ browser.wait(until.elementIsVisible(browser.findElement(by.id('inputPassword'))), TEST_TIMEOUT).then(function () {
+ done();
+ });
+ });
+ });
+ }
+
+ function checkFileIsListed(name, done) {
+ browser.get('https://' + app.fqdn + '/_admin');
+
+ browser.wait(until.elementLocated(by.xpath('//*[text()="' + name + '"]')), TEST_TIMEOUT).then(function () {
+ done();
+ });
+ }
+
+ function checkFileIsPresent(done) {
+ browser.get('https://' + app.fqdn + '/' + TEST_FILE_NAME_0);
+
+ browser.wait(until.elementLocated(by.xpath('//*[text()="test"]')), TEST_TIMEOUT).then(function () {
+ done();
+ });
+ }
+
+ function checkIndexFileIsServedUp(done) {
+ browser.get('https://' + app.fqdn);
+
+ browser.wait(until.elementLocated(by.xpath('//*[text()="test"]')), TEST_TIMEOUT).then(function () {
+ done();
+ });
+ }
+
+ function checkFileIsGone(name, done) {
+ superagent.get('https://' + app.fqdn + '/' + name).end(function (error, result) {
+ expect(error).to.be.an('object');
+ expect(result.statusCode).to.equal(404);
+ done();
+ });
+ }
+
+ function cliLogin(done) {
+ execSync(util.format('%s login %s --username %s --password %s', path.join(__dirname, '/../cli/surfer.js'), app.fqdn, process.env.USERNAME, process.env.PASSWORD), { stdio: 'inherit' } );
+ done();
+ }
+
+ function uploadFile(name, done) {
+ // File upload can't be tested with selenium, since the file input is not visible and thus can't be interacted with :-(
+
+ execSync(path.join(__dirname, '/../cli/surfer.js') + ' put ' + path.join(__dirname, name), { stdio: 'inherit' } );
+ done();
+ }
+