Skip to content

Commit

Permalink
updates selenium webdriver which removes promise manager
Browse files Browse the repository at this point in the history
the selenium driver now returns a promise instead of doing some crazy
stack-magic.

see this issue for more information:
SeleniumHQ/selenium#2969
  • Loading branch information
Christoph Wolfes committed Feb 28, 2018
1 parent 2a1db24 commit 95e9592
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 45 deletions.
5 changes: 2 additions & 3 deletions integrationTests/adminFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ module.exports = class AdminFunctions{
await driver.wait(until.elementLocated(By.linkText(this.testuserName)),5000);
await driver.findElement(By.linkText(this.testuserName)).click();
await driver.get(config.baseUrl + config.jenkinsContextPath + "/user/" + this.testuserName + "/delete");
await driver.findElement(By.id("yui-gen2-button")).click();};
await driver.findElement(By.id("yui-gen2-button")).click();
};

async giveAdminRights(){

Expand Down Expand Up @@ -83,7 +84,6 @@ module.exports = class AdminFunctions{

async testUserLogin(driver) {
await driver.wait(until.elementLocated(By.id('password')), 5000);

await driver.findElement(By.id('username')).sendKeys(this.testuserName);
await driver.findElement(By.id('password')).sendKeys(this.testuserPasswort);
await driver.findElement(By.css('input[name="submit"]')).click();
Expand All @@ -97,7 +97,6 @@ module.exports = class AdminFunctions{
};

async accessUsersJson(expectStatus){

await request(config.baseUrl)
.get(config.jenkinsContextPath+"/pluginManager/api/json")
.auth(this.testuserName, this.testuserPasswort)
Expand Down
32 changes: 16 additions & 16 deletions integrationTests/cas-browser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,31 @@ afterEach(() => {
describe('cas browser login', () => {

test('automatic redirect to cas login', async () => {
driver.get(config.baseUrl + config.jenkinsContextPath);
await driver.get(config.baseUrl + config.jenkinsContextPath);
const url = await driver.getCurrentUrl();
expect(url).toMatch(loginUrl);
});

test('login', async() => {
driver.get(utils.getCasUrl(driver));
utils.login(driver);
await driver.get(utils.getCasUrl(driver));
await utils.login(driver);
const username = await driver.findElement(By.className('login')).getText();
expect(username).toContain(config.displayName);
});

test('logout front channel', async() => {
driver.get(utils.getCasUrl(driver));
utils.login(driver);
driver.findElement(By.xpath("//div[@id='header']/div[2]/span/a[2]/b")).click();
await driver.get(utils.getCasUrl(driver));
await utils.login(driver);
await driver.findElement(By.xpath("//div[@id='header']/div[2]/span/a[2]/b")).click();
const url = await driver.getCurrentUrl();
expect(url).toMatch(logoutUrl);
});

test('logout back channel', async() => {
driver.get(utils.getCasUrl(driver));
utils.login(driver);
driver.get(config.baseUrl + logoutUrl);
driver.get(config.baseUrl + config.jenkinsContextPath);
await driver.get(utils.getCasUrl(driver));
await utils.login(driver);
await driver.get(config.baseUrl + logoutUrl);
await driver.get(config.baseUrl + config.jenkinsContextPath);
const url = await driver.getCurrentUrl();
expect(url).toMatch(loginUrl);
});
Expand All @@ -57,9 +57,9 @@ describe('cas browser login', () => {
describe('browser attributes', () => {

test('front channel user attributes', async () => {
driver.get(utils.getCasUrl(driver));
utils.login(driver);
driver.get(config.baseUrl + config.jenkinsContextPath + "/user/" + config.username + "/configure");
await driver.get(utils.getCasUrl(driver));
await utils.login(driver);
await driver.get(config.baseUrl + config.jenkinsContextPath + "/user/" + config.username + "/configure");
const emailAddressInput = await driver.findElement(By.name("email.address"));
const emailAddress = await emailAddressInput.getAttribute("value");
const usernameInput= await driver.findElement(By.name('_.fullName'));
Expand All @@ -69,9 +69,9 @@ describe('browser attributes', () => {
});

test('front channel user administrator', async () => {
driver.get(utils.getCasUrl(driver));
utils.login(driver);
var isAdministrator = await utils.isAdministrator(driver);
await driver.get(utils.getCasUrl(driver));
await utils.login(driver);
const isAdministrator = await utils.isAdministrator(driver);
expect(isAdministrator).toBe(true);
});

Expand Down
10 changes: 5 additions & 5 deletions integrationTests/cas-rest.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ describe('cas rest basic authentication', () => {

/*login -> click on username -> configure -> show api token*/
test('authentication with API key', async () => {
driver.get(utils.getCasUrl(driver));
utils.login(driver);
driver.get(config.baseUrl + config.jenkinsContextPath + "/user/" + config.username + "/configure");
driver.wait(until.elementLocated(By.id('yui-gen1-button')), 5000);
driver.findElement(By.id("yui-gen1-button")).click();
await driver.get(utils.getCasUrl(driver));
await utils.login(driver);
await driver.get(config.baseUrl + config.jenkinsContextPath + "/user/" + config.username + "/configure");
await driver.wait(until.elementLocated(By.id('yui-gen1-button')), 5000);
await driver.findElement(By.id("yui-gen1-button")).click();
const input = await driver.findElement(By.id("apiToken"));
const apikey = await input.getAttribute("value");
await request(config.baseUrl)
Expand Down
2 changes: 1 addition & 1 deletion integrationTests/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"chromedriver": "^2.33.2",
"jest": "^21.2.1",
"jest-junit": "^3.1.0",
"selenium-webdriver": "^3.6.0",
"selenium-webdriver": "4.0.0-alpha.1",
"supertest": "^3.0.0",
"yarn": "^1.3.2"
},
Expand Down
15 changes: 4 additions & 11 deletions integrationTests/permissions-rest.spec.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@

const request = require('supertest');
const config = require('./config');
const AdminFunctions = require('./adminFunctions');
const utils = require('./utils');
const webdriver = require('selenium-webdriver');
const By = webdriver.By;
const keys = webdriver.Key;
const until = webdriver.until;

jest.setTimeout(30000);
let driver;
Expand All @@ -22,7 +17,6 @@ beforeEach(async() => {
});

afterEach(async() => {

await adminFunctions.removeUser(driver);
await driver.quit();
});
Expand All @@ -39,17 +33,16 @@ describe('administration rest tests', () => {
});

test('rest - user (testUser) has no admin privileges', async() => {
driver.get(utils.getCasUrl(driver));
await driver.get(utils.getCasUrl(driver));
await adminFunctions.accessUsersJson(403);
});


test('rest - user (testUser) remove admin privileges', async() => {

driver.get(utils.getCasUrl(driver));
adminFunctions.testUserLogin(driver);
await driver.get(utils.getCasUrl(driver));
await adminFunctions.testUserLogin(driver);
await adminFunctions.testUserLogout(driver);
adminFunctions.takeAdminRights();
await adminFunctions.takeAdminRights();
await driver.get(utils.getCasUrl(driver));
await adminFunctions.accessUsersJson(403);
});
Expand Down
8 changes: 4 additions & 4 deletions integrationTests/permissions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let driver;
let adminFunctions;

beforeEach(async() => {
driver = utils.createDriver(webdriver);
driver = await utils.createDriver(webdriver);
adminFunctions = new AdminFunctions('testUser', 'testUser', 'testUser', 'testUser@test.de', 'testuserpassword');
await adminFunctions.createUser();
});
Expand All @@ -34,15 +34,15 @@ describe('user permissions', () => {
await adminFunctions.giveAdminRights();
await adminFunctions.testUserLogin(driver);
await driver.wait(until.elementLocated(By.className('login')), 5000);
var adminPermissions = await utils.isAdministrator(driver);
const adminPermissions = await utils.isAdministrator(driver);
expect(adminPermissions).toBe(true);
});

test('user (testUser) has no admin privileges', async() => {
await driver.get(utils.getCasUrl(driver));
await adminFunctions.testUserLogin(driver);
await driver.wait(until.elementLocated(By.className('login')), 5000);
var adminPermissions = await utils.isAdministrator(driver);
const adminPermissions = await utils.isAdministrator(driver);
expect(adminPermissions).toBe(false);
});

Expand All @@ -57,7 +57,7 @@ describe('user permissions', () => {
await driver.get(utils.getCasUrl(driver));
await adminFunctions.testUserLogin(driver);
await driver.wait(until.elementLocated(By.className('login')), 5000);
var adminPermissions = await utils.isAdministrator(driver);
const adminPermissions = await utils.isAdministrator(driver);
expect(adminPermissions).toBe(false);
});

Expand Down
10 changes: 5 additions & 5 deletions integrationTests/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ function createLocalDriver() {


exports.getCasUrl = async function getCasUrl(driver){
driver.get(config.baseUrl + config.jenkinsContextPath);
await driver.get(config.baseUrl + config.jenkinsContextPath);
return driver.getCurrentUrl();
};

exports.login = async function login(driver) {
driver.wait(until.elementLocated(By.id('password')), 5000);
driver.wait(until.elementLocated(By.id('username')), 5000);
await driver.wait(until.elementLocated(By.id('password')), 5000);
await driver.wait(until.elementLocated(By.id('username')), 5000);

driver.findElement(By.id('username')).sendKeys(config.username);
driver.findElement(By.id('password')).sendKeys(config.password);
await driver.findElement(By.id('username')).sendKeys(config.username);
await driver.findElement(By.id('password')).sendKeys(config.password);
return driver.findElement(By.css('input[name="submit"]')).click();
};

Expand Down

0 comments on commit 95e9592

Please sign in to comment.