Skip to content

Commit

Permalink
fix protractor test setup, remove outdated login test
Browse files Browse the repository at this point in the history
Signed-off-by: Stephan Krusche <s.krusche@tum.de>
  • Loading branch information
Stephan Krusche committed Mar 28, 2019
1 parent 723fe5e commit 5e8f470
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 220 deletions.
6 changes: 3 additions & 3 deletions protractor.conf.js
Expand Up @@ -11,8 +11,8 @@ exports.config = {
browserName: 'chrome',
chromeOptions: {
args: process.env.JHI_E2E_HEADLESS
? [ "--headless", "--disable-gpu", "--window-size=800,600", "--disable-extensions", "incognito" ]
: [ "--disable-gpu", "--window-size=800,600", "--disable-extensions", "incognito" ]
? [ "--headless", "--disable-gpu", "--window-size=1280,1024", "--disable-extensions", "incognito" ]
: [ "--disable-gpu", "--window-size=1280,1024", "--disable-extensions", "incognito" ]
}
},

Expand All @@ -38,7 +38,7 @@ exports.config = {
},

onPrepare: function() {
browser.driver.manage().window().setSize(1280, 1024);
browser.driver.manage().window().setRect({x: 100, y: 100, width: 1280, height: 1024});
// Disable animations
// @ts-ignore
browser.executeScript('document.body.className += " notransition";');
Expand Down
8 changes: 4 additions & 4 deletions src/test/javascript/e2e/account/account.spec.ts
Expand Up @@ -31,31 +31,31 @@ describe('account', () => {
signInPage = await navBarPage.getSignInPage();
await signInPage.autoSignInUsing(process.env.bamboo_admin_user, process.env.bamboo_admin_password);

browser.wait(ec.urlContains('/courses'), 5000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains('/courses'), 5000).then((result: any) => expect(result).to.be.true);
});

it('should login successfully with instructor account', async () => {
await browser.get('/');
signInPage = await navBarPage.getSignInPage();
await signInPage.autoSignInUsing(process.env.bamboo_instructor_user, process.env.bamboo_instructor_password);

browser.wait(ec.urlContains('/courses'), 5000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains('/courses'), 5000).then((result: any) => expect(result).to.be.true);
});

it('should login successfully with tutor account', async () => {
await browser.get('/');
signInPage = await navBarPage.getSignInPage();
await signInPage.autoSignInUsing(process.env.bamboo_tutor_user, process.env.bamboo_tutor_password);

browser.wait(ec.urlContains('/courses'), 5000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains('/courses'), 5000).then((result: any) => expect(result).to.be.true);
});

it('should login successfully with student account', async () => {
await browser.get('/');
signInPage = await navBarPage.getSignInPage();
await signInPage.autoSignInUsing(process.env.bamboo_student_user, process.env.bamboo_student_password);

browser.wait(ec.urlContains('/courses'), 5000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains('/courses'), 5000).then((result: any) => expect(result).to.be.true);
});

afterEach(async () => {
Expand Down
14 changes: 8 additions & 6 deletions src/test/javascript/e2e/entities/course.spec.ts
@@ -1,6 +1,6 @@
import { NavBarPage, SignInPage } from '../page-objects/jhi-page-objects';
import {browser, by, element, ExpectedConditions as ec} from "protractor";
import {CoursePage, NewCoursePage} from "../page-objects/entities/course-page-object";
import { browser, by, element, ExpectedConditions as ec } from 'protractor';
import { CoursePage, NewCoursePage } from '../page-objects/entities/course-page-object';

const expect = chai.expect;

Expand Down Expand Up @@ -73,12 +73,15 @@ describe('course', () => {
expect(await newCoursePage.save.getAttribute('disabled')).to.equal(null);
await newCoursePage.clickSave();

browser.wait(ec.urlContains('/course'), 5000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains('/course'), 5000).then((result: any) => expect(result).to.be.true);
});

it('should show the created course in the list', async () => {
const rows = element.all(by.tagName('tbody')).all(by.tagName('tr'));
const lastTitle = await rows.last().element(by.css('td:nth-child(2) > span.bold')).getText();
const lastTitle = await rows
.last()
.element(by.css('td:nth-child(2) > span.bold'))
.getText();

expect(lastTitle).contains(courseName);
});
Expand All @@ -89,10 +92,9 @@ describe('course', () => {
const deleteButton = rows.last().element(by.className('btn-danger'));
await deleteButton.click();

const confirmDeleteButton = element(by.tagName('jhi-course-delete-dialog')).element(by.className('btn-danger'))
const confirmDeleteButton = element(by.tagName('jhi-course-delete-dialog')).element(by.className('btn-danger'));
await confirmDeleteButton.click();


rows = element.all(by.tagName('tbody')).all(by.tagName('tr'));
expect(await rows.count()).to.equal(numberOfCourses - 1);
});
Expand Down
99 changes: 52 additions & 47 deletions src/test/javascript/e2e/quiz-exercise/quiz-exericse.spec.ts
@@ -1,5 +1,5 @@
import { NavBarPage, SignInPage } from '../page-objects/jhi-page-objects';
import {browser, by, element, ExpectedConditions as ec} from "protractor";
import { browser, by, element, ExpectedConditions as ec } from 'protractor';
import { CoursePage, NewCoursePage } from '../page-objects/entities/course-page-object';
import { QuizExercisePage } from '../page-objects/entities/quiz-exercise-page-object';
import { errorRoute } from '../../../../main/webapp/app/layouts';
Expand Down Expand Up @@ -36,24 +36,22 @@ describe('quiz-exercise', () => {
await newCoursePage.setInstructorGroupName('ls1instructor');
await newCoursePage.clickSave();

browser.wait(ec.urlContains('/course'), 1000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains('/course'), 1000).then(result => expect(result).to.be.true);

// Sign in with instructor account
await navBarPage.autoSignOut();
signInPage = await navBarPage.getSignInPage();
await signInPage.autoSignInUsing(process.env.bamboo_instructor_user, process.env.bamboo_instructor_password);
});

beforeEach(async () => {
});
beforeEach(async () => {});

it('navigate into quiz-exercise', async () => {
await navBarPage.clickOnCourseAdminMenu();
courseId = await coursePage.navigateIntoLastCourseQuizzes();

//TODO: this does not seem to work properly
browser.wait(ec.urlContains(`${courseId}/quiz-exercise`), 5000).then((result) => expect(result).to.be.true);

browser.wait(ec.urlContains(`${courseId}/quiz-exercise`), 5000).then((result: any) => expect(result).to.be.true);
});

it('create quiz', async () => {
Expand All @@ -63,23 +61,23 @@ describe('quiz-exercise', () => {

//set title of quiz
const title = element(by.id('quiz-title'));
title.sendKeys("test-quiz");
title.sendKeys('test-quiz');

//set duration of quiz
const durationMinutes = await element(by.id('quiz-duration-minutes'));
durationMinutes.clear();
durationMinutes.sendKeys("0");
durationMinutes.sendKeys('0');
const durationSeconds = await element(by.id('quiz-duration-seconds'));
durationSeconds.clear();
durationSeconds.sendKeys("5");
durationSeconds.sendKeys('5');

//add MC question
const addMcButton = await element(by.id('quiz-add-mc-question'));
await addMcButton.click();

// set title of mc question
const mcQuestionTitle = await element(by.id('mc-question-title')); //TODO: we need to support multiple questions
mcQuestionTitle.sendKeys("test-mc");
const mcQuestionTitle = await element(by.id('mc-question-title')); //TODO: we need to support multiple questions
mcQuestionTitle.sendKeys('test-mc');

//deactivate random order to make the test case deterministic
const randomOrder = await element(by.css('[for="cbRandomizeOrderMC1"]'));
Expand All @@ -89,7 +87,7 @@ describe('quiz-exercise', () => {
expect(quizSaveButton.isPresent());
await quizSaveButton.click();

browser.wait(ec.urlContains(`${courseId}/quiz-exercise/new`), 1000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains(`${courseId}/quiz-exercise/new`), 1000).then((result: any) => expect(result).to.be.true);

const backButton = await element(by.id('quiz-cancel-back-button'));
expect(backButton.isPresent());
Expand All @@ -101,25 +99,28 @@ describe('quiz-exercise', () => {

it('participate in quiz', async () => {
const quizRows = element.all(by.tagName('tbody')).all(by.tagName('tr'));
quizId = await quizRows.last().element(by.css('td:nth-child(1) > a')).getText();
quizId = await quizRows
.last()
.element(by.css('td:nth-child(1) > a'))
.getText();

//set visible
const setVisibleButton = await element(by.id(`quiz-set-visible-${quizId}`));
expect(setVisibleButton.isPresent());
await setVisibleButton.click();

await browser.sleep(500); // let's wait shortly so that the server gets everything right with the database
await browser.sleep(500); // let's wait shortly so that the server gets everything right with the database

//start quiz
const startQuizInstructorButton = await element(by.id(`instructor-quiz-start-${quizId}`));
expect(startQuizInstructorButton.isPresent());
await startQuizInstructorButton.click();

await browser.sleep(500); // let's wait shortly so that the server gets everything right with the database
await browser.sleep(500); // let's wait shortly so that the server gets everything right with the database
//navigate to courses
await navBarPage.clickOnCoursesMenu();

browser.wait(ec.urlContains(`courses`), 1000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains(`courses`), 1000).then((result: any) => expect(result).to.be.true);

//open or start quiz (depends a bit on the timing)
let startQuizButton = await element(by.id(`student-quiz-start-${quizId}`));
Expand All @@ -129,7 +130,7 @@ describe('quiz-exercise', () => {
expect(startQuizButton.isPresent());
await startQuizButton.click();

browser.wait(ec.urlContains(`quiz/${quizId}`), 1000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains(`quiz/${quizId}`), 1000).then((result: any) => expect(result).to.be.true);

// deactivate because we use timeouts in the quiz participation and otherwise it would not work
browser.waitForAngularEnabled(false);
Expand All @@ -138,45 +139,50 @@ describe('quiz-exercise', () => {
//TODO the answer options are random, search for the correct and incorrect answer option before clicking in it
const firstAnswerOption = await element(by.id(`answer-option-0`));
expect(firstAnswerOption.isPresent());
await firstAnswerOption.click();//select
await firstAnswerOption.click();//deselect
await firstAnswerOption.click();//select
await firstAnswerOption.click(); //select
await firstAnswerOption.click(); //deselect
await firstAnswerOption.click(); //select

const secondAnswerOption = await element(by.id(`answer-option-1`));
expect(secondAnswerOption.isPresent());
await secondAnswerOption.click();//select
await secondAnswerOption.click();//deselect

await secondAnswerOption.click(); //select
await secondAnswerOption.click(); //deselect

//submit quiz
const submitQuizButton = await element(by.id(`submit-quiz`));
expect(submitQuizButton.isPresent());
await submitQuizButton.click();



//wait until the quiz has finished
await browser.wait(ec.visibilityOf(element(by.id('quiz-score'))), 10000).then(async (result) => {
await browser.wait(ec.visibilityOf(element(by.id('quiz-score'))), 10000).then(async (result: any) => {
//first possibility to check this
element(by.id('quiz-score-result')).getText().then(text => {
expect(text).equals('1/1 (100 %)');
});
element(by.id('quiz-score-result'))
.getText()
.then(text => {
expect(text).equals('1/1 (100 %)');
});

//second possibility to check this
const text = await element(by.id('quiz-score-result')).getText();
expect(text).equals('1/1 (100 %)');

element(by.id('answer-option-0-correct')).getText().then(text => {
expect(text).equals('Correct');
}).catch(error => {
expect.fail('first answer option not found as correct');
});

element(by.id('answer-option-1-correct')).getText().then(text => {
expect(text).equals('Correct');
}).catch(error => {
expect.fail('second answer option not found as correct');
});
element(by.id('answer-option-0-correct'))
.getText()
.then(text => {
expect(text).equals('Correct');
})
.catch(error => {
expect.fail('first answer option not found as correct');
});

element(by.id('answer-option-1-correct'))
.getText()
.then(text => {
expect(text).equals('Correct');
})
.catch(error => {
expect.fail('second answer option not found as correct');
});
});

await browser.sleep(500);
Expand All @@ -199,29 +205,29 @@ describe('quiz-exercise', () => {

//set title of SA quiz
const title = element(by.id('quiz-title'));
title.sendKeys("test-SA-quiz");
title.sendKeys('test-SA-quiz');

//set duration of quiz
const durationMinutes = await element(by.id('quiz-duration-minutes'));
durationMinutes.clear();
durationMinutes.sendKeys("0");
durationMinutes.sendKeys('0');
const durationSeconds = await element(by.id('quiz-duration-seconds'));
durationSeconds.clear();
durationSeconds.sendKeys("5");
durationSeconds.sendKeys('5');

//add short answer question
const addShortAnswerButton = await element(by.id('quiz-add-short-answer-question'));
await addShortAnswerButton.click();

// set title of short answer question
const shortAnswerQuestionTitle = await element(by.id('short-answer-question-title')); //TODO: we need to support multiple questions
shortAnswerQuestionTitle.sendKeys("test-short-answer");
const shortAnswerQuestionTitle = await element(by.id('short-answer-question-title')); //TODO: we need to support multiple questions
shortAnswerQuestionTitle.sendKeys('test-short-answer');

const quizSaveButton = await element(by.id('quiz-save'));
expect(quizSaveButton.isPresent());
await quizSaveButton.click();

browser.wait(ec.urlContains(`${courseId}/quiz-exercise/new`), 1000).then((result) => expect(result).to.be.true);
browser.wait(ec.urlContains(`${courseId}/quiz-exercise/new`), 1000).then((result: any) => expect(result).to.be.true);

const backButton = await element(by.id('quiz-cancel-back-button'));
expect(backButton.isPresent());
Expand Down Expand Up @@ -252,5 +258,4 @@ describe('quiz-exercise', () => {
expect(await rows.count()).to.equal(numberOfCourses - 1);
await navBarPage.autoSignOut();
});

});

0 comments on commit 5e8f470

Please sign in to comment.