Skip to content

Commit

Permalink
Merge pull request #379 from adessoSE/dev
Browse files Browse the repository at this point in the history
Seed v1.6.2
  • Loading branch information
dsorna authored Dec 4, 2022
2 parents 5d534e5 + 6a599c9 commit b545298
Show file tree
Hide file tree
Showing 41 changed files with 1,904 additions and 191 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ backend/features/reporting_html*.html
*.bat
*.sh
*.ps1
!runDocker.bat

# Website Deployment with IIS
**/web.config
Expand Down
1 change: 1 addition & 0 deletions backend/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*node_modules
1 change: 0 additions & 1 deletion backend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ webdriver/*

# logs
.log

18 changes: 6 additions & 12 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ RUN yes | apt-get install wget
# Create app directory
WORKDIR /usr/src/app

# Install app dependencies
# A wildcard is used to ensure both package.json AND package-lock.json are copied
# where available (npm@5+)
COPY package*.json ./

RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

# install chrome
RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN yes | apt install ./google-chrome-stable_current_amd64.deb
Expand All @@ -36,7 +27,7 @@ RUN curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > mic
RUN install -o root -g root -m 644 microsoft.gpg /etc/apt/trusted.gpg.d/
RUN sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/edge stable main" > /etc/apt/sources.list.d/microsoft-edge-dev.list'
RUN rm microsoft.gpg
RUN apt update && yes | apt install microsoft-edge-stable
RUN apt update && yes | apt install microsoft-edge-stable

# install msedgedriver
# get the latest stable version number and remove two FF FE Bytes at start and OD Byte at end (DataStreamBytes)
Expand All @@ -49,11 +40,14 @@ RUN unzip /tmp/msedgedriver.zip msedgedriver -d /usr/local/bin/
RUN rm -f latest_stable_with_weird_chars.txt
RUN rm -f latest_stable.txt


# Bundle app source
COPY . .

EXPOSE ${PORT}
RUN npm install
# If you are building your code for production
# RUN npm ci --only=production

EXPOSE 8080

# Start dbus-daemon for google-chrome
RUN service dbus start
Expand Down
100 changes: 57 additions & 43 deletions backend/features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ edgeOptions.addArguments('--start-maximized');
edgeOptions.addArguments('--lang=de');
edgeOptions.addArguments('--excludeSwitches=enable-logging');
// chromeOptions.addArguments('--start-fullscreen');

chromeOptions.setUserPreferences({ 'download.default_directory': 'C:\\Users\\Public\\seed_Downloads' });

chromeOptions.bynary_location = process.env.GOOGLE_CHROME_SHIM;
let currentParameters = {};

Expand Down Expand Up @@ -99,7 +102,7 @@ Before(async function () {
// / #################### GIVEN ########################################
Given('As a {string}', async function (string) {
this.role = string;
// await driver.sleep(currentParameters.waitTime);
// await driver.sleep(100 + currentParameters.waitTime);
});

Given('I am on the website: {string}', async function getUrl(url) {
Expand All @@ -113,7 +116,7 @@ Given('I am on the website: {string}', async function getUrl(url) {
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

Given('I add a cookie with the name {string} and value {string}', async function addCookie(name, value) {
Expand All @@ -126,7 +129,7 @@ Given('I add a cookie with the name {string} and value {string}', async function
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

Given('I remove a cookie with the name {string}', async function removeCookie(name) {
Expand All @@ -139,7 +142,7 @@ Given('I remove a cookie with the name {string}', async function removeCookie(na
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Take a Screenshot
Expand All @@ -157,7 +160,7 @@ Given('I take a screenshot', async function () {
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Take a Screenshot and optionally scroll to a specific element
Expand All @@ -182,7 +185,7 @@ Given('I take a screenshot. Optionally: Focus the page on the element {string}',
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// ################### WHEN ##########################################
Expand All @@ -198,7 +201,7 @@ When('I go to the website: {string}', async function getUrl(url) {
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// clicks a button if found in html code with xpath,
Expand All @@ -207,26 +210,37 @@ When('I click the button: {string}', async function clickButton(button) {
const world = this;
const identifiers = [`//*[@id='${button}']`, `//*[contains(@id,'${button}')]`, `//*[text()='${button}' or @*='${button}']`, `//*[contains(text(),'${button}')]`, `${button}`];
await driver.getCurrentUrl()
.then(async (currentUrl) => {
// prevent Button click on "Run Story" or "Run Scenario" to prevent recursion
if ((currentUrl === 'http://localhost:4200/' || currentUrl === 'https://seed-test-frontend.herokuapp.com/') && button.toLowerCase()
.match(/^run[ _](story|scenario)$/) !== null){
throw new Error('Executing Seed-Test inside a scenario is not allowed, to prevent recursion!');
.then(async (currentUrl) => {
// prevent Button click on "Run Story" or "Run Scenario" to prevent recursion
if ((currentUrl === 'http://localhost:4200/' || currentUrl === 'https://seed-test-frontend.herokuapp.com/') && button.toLowerCase()
.match(/^run[ _](story|scenario)$/) !== null)
throw new Error('Executing Seed-Test inside a scenario is not allowed, to prevent recursion!');
});
// for DAISY only:
// don't throw an error and end the testcase if "Alte Sitzung Beenden" is not found
if (button === 'Alte Sitzung beenden') {
try {
await driver.sleep(100);
await driver.wait(until.elementLocated(By.xpath(`//*[@name='kill-session']`)), 3 * 1000).click();
} catch (e) {
console.log('Button "Alte Sitzung beenden" not found. Skipping the Step...');
}
});
const promises = []
for(const idString of identifiers){
promises.push( driver.wait(until.elementLocated(By.xpath(idString)), searchTimeout, `Timed out after ${searchTimeout} ms`, 100) )
return;
} else {
const promises = [];
for(const idString of identifiers){
promises.push( driver.wait(until.elementLocated(By.xpath(idString)), searchTimeout, `Timed out after ${searchTimeout} ms`, 100) )
}
await Promise.any(promises)
.then((elem) => elem.click())
.catch(async (e) => {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
});
throw Error(e);
});
}
await Promise.any(promises)
.then((elem) => elem.click())
.catch(async (e) => {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// selenium sleeps for a certain amount of time
Expand Down Expand Up @@ -271,7 +285,7 @@ When('I insert {string} into the field {string}', async function fillTextField(v
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// "Radio"
Expand All @@ -290,7 +304,7 @@ When('I select {string} from the selection {string}', async function clickRadioB
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Select an Option from a dropdown-menu
Expand Down Expand Up @@ -324,7 +338,7 @@ When('I select the option {string}', async function selectviaXPath(dropd) {
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Hover over element and Select an Option
Expand Down Expand Up @@ -367,7 +381,7 @@ When('I hover over the element {string} and select the option {string}', async f
}
}
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// TODO:
Expand Down Expand Up @@ -404,7 +418,7 @@ When('I check the box {string}', async function checkBox(name) {
});

// await driver.wait(async () => driver.executeScript('return document.readyState').then(async (readyState) => readyState === 'complete'));
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

When('Switch to the newly opened tab', async function switchToNewTab() {
Expand All @@ -418,7 +432,7 @@ When('Switch to the newly opened tab', async function switchToNewTab() {
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

When('Switch to the tab number {string}', async function switchToSpecificTab(numberOfTabs) {
Expand All @@ -439,7 +453,7 @@ When('Switch to the tab number {string}', async function switchToSpecificTab(num
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// TODO: delete this following step (also in DB), once every branch has the changes
Expand All @@ -454,7 +468,7 @@ When('I switch to the next tab', async function switchToNewTab() {
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

When('I want to upload the file from this path: {string} into this uploadfield: {string}',
Expand All @@ -473,7 +487,7 @@ When('I want to upload the file from this path: {string} into this uploadfield:
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// ################### THEN ##########################################
Expand All @@ -490,7 +504,7 @@ Then('So I will be navigated to the website: {string}', async function checkUrl(
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Search a textfield in the html code and assert it with a Text
Expand All @@ -517,7 +531,7 @@ Then('So I can see the text {string} in the textbox: {string}', async function c
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Search if a is text in html code
Expand All @@ -539,7 +553,7 @@ Then('So I can see the text: {string}', async function (string) { // text is pre
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Search a textfield in the html code and assert if it's empty
Expand All @@ -564,7 +578,7 @@ Then('So I can\'t see text in the textbox: {string}', async function (label) {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
});
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

Then('So a file with the name {string} is downloaded in this Directory {string}',
Expand All @@ -585,7 +599,7 @@ Then('So a file with the name {string} is downloaded in this Directory {string}'
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Search if a text isn't in html code
Expand All @@ -606,7 +620,7 @@ Then('So I can\'t see the text: {string}', async function checkIfTextIsMissing(t
});
throw Error(e);
}
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Check if a checkbox is set (true) or not (false)
Expand All @@ -632,21 +646,21 @@ Then('So the checkbox {string} is set to {string} [true OR false]', async functi
});
throw Error(e);
})
await driver.sleep(currentParameters.waitTime);
await driver.sleep(100 + currentParameters.waitTime);
});

// Closes the webdriver (Browser)
// runs after each Scenario
After(async () => {
if (currentParameters.oneDriver) {
scenarioIndex += 1;
await driver.sleep(500);
await driver.sleep(1000);
if (scenarioIndex === testLength) {
await driver.quit();
}
} else {
scenarioIndex += 1;
await driver.sleep(500);
await driver.sleep(1000);
await driver.quit();
}
});
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "seed-test-backend",
"version": "1.6.1",
"version": "1.6.2",
"engines": {
"node": "16.17.0"
},
Expand Down
3 changes: 2 additions & 1 deletion backend/src/database/DbServices.js
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ async function updateStory(updatedStory) {
try {
const db = dbConnection.getConnection();
const collection = await db.collection(storiesCollection);
updatedStory._id = ObjectId(updatedStory._id.toString())
return await collection.findOneAndReplace({_id: ObjectId(updatedStory._id.toString())}, updatedStory, {returnDocument: "after"})
} catch (e) {
console.log(`ERROR updateStory: ${e}`);
Expand Down Expand Up @@ -781,7 +782,7 @@ async function updateRepository(repoID, newName, user) {
const repoFilter = { owner: ObjectId(user), _id: ObjectId(repoID) };
const db = dbConnection.getConnection();
const collection = await db.collection(repositoriesCollection);
return collection.findOneAndUpdate(repoFilter, { $set: {"repo.repoName": newName} });
return collection.findOneAndUpdate(repoFilter, { $set: {"repoName": newName} }, { returnNewDocument: true });
} catch (e) {
console.log(`ERROR updateRepository: ${e}`);
throw e;
Expand Down
Loading

0 comments on commit b545298

Please sign in to comment.