Skip to content

Commit

Permalink
New selectors for designer page and testcafe tests for Issue #216 (#902)
Browse files Browse the repository at this point in the history
* Added npm start script to package.json

* ACTUALLY added npm start script to package.json

* Added xunit output file

* test script in package.json

* New nagivation tests

* New tests, switched to headless mode, xUnit reporter file

* changed test script to dev env

* spelling error in reporter

* Switched to junit reporter, changed testdata to automation user and email, updated tests with new testdata
  • Loading branch information
trymen authored Jan 22, 2019
1 parent 34a3dd6 commit 7b9c86c
Show file tree
Hide file tree
Showing 9 changed files with 1,298 additions and 28 deletions.
1 change: 1 addition & 0 deletions src/test/Testcafe/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
/Screenshots
**/junit.xml
4 changes: 2 additions & 2 deletions src/test/Testcafe/config.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"local": {
"baseUrl": "http://altinn3.no"
"baseUrl": "http://altinn3.no/"
},
"dev": {
"baseUrl": "https://dev.altinn.studio"
"baseUrl": "https://dev.altinn.studio/"
},
"uat": {
"baseUrl": "base for uat"
Expand Down
75 changes: 75 additions & 0 deletions src/test/Testcafe/designer_tests/navigation-tests.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { t } from 'testcafe';
import { waitForReact } from 'testcafe-react-selectors';
import DesignerPage from '../page-objects/designerPage';
import CommonPage from '../page-objects/common';
import TestData from '../TestData';
import App from '../app';
import LoginPage from '../page-objects/loginPage';

let app = new App();
let common = new CommonPage();
let loginPage = new LoginPage();
let designerPage = new DesignerPage();
const testUser = new TestData('AutoTest', '[email protected]', 'test123', 'basic');

fixture('Navigating the Service designer')
.page(app.baseUrl)
.before(async () => {
})
.beforeEach(async () => {
await common.login(testUser.userEmail, testUser.password, loginPage);
await waitForReact();
//app.before();
})
.after(async () => {
//await app.after();
})

test('Om tab navigation', async () => {
await t
.navigateTo(app.baseUrl + 'designer/AutoTest/testcafe01#/aboutservice') //navigate to the designer on test user repo
.click(designerPage.omNavigationTab)
.hover(designerPage.leftDrawerMenu)
.expect(designerPage.omLeftMenuItems[0].visible).ok()
.expect(designerPage.omLeftMenuItems[1].visible).ok()
.expect(designerPage.omLeftMenuItems[2].visible).ok()
.expect(designerPage.omLeftMenuItems[3].visible).ok()
.expect(designerPage.omLeftMenuItems[4].visible).ok()
.expect(designerPage.omLeftMenuItems[5].visible).ok()
});

test('Lage tab navigation', async () => {
await t
.navigateTo(app.baseUrl + 'designer/AutoTest/testcafe01#/aboutservice')
.click(designerPage.lageNavigationTab)
.hover(designerPage.leftDrawerMenu)
.expect(designerPage.lageLeftMenuItems[0].visible).ok()
.expect(designerPage.lageLeftMenuItems[1].visible).ok()
.expect(designerPage.lageLeftMenuItems[2].visible).ok()
});

test('Språk tab navigation', async () => {
await t
.navigateTo(app.baseUrl + 'designer/AutoTest/testcafe01#/aboutservice')
.click(designerPage.spraakNavigationTab)
.hover(designerPage.leftDrawerMenu)
.expect(designerPage.spraakLeftMenuItems[0].visible).ok()
.expect(designerPage.spraakLeftMenuItems[1].visible).ok()
});

test('Teste tab navigation', async () => {
await t
.navigateTo(app.baseUrl + 'designer/AutoTest/testcafe01#/aboutservice')
.click(designerPage.testeNavigationTab)
.hover(designerPage.leftDrawerMenu)
.expect(designerPage.testeLeftMenuItems[0].visible).ok()
});

test('Publisere tab navigation', async () => {
await t
.navigateTo(app.baseUrl + 'designer/AutoTest/testcafe01#/aboutservice')
.click(designerPage.publisereNavigationTab)
.hover(designerPage.leftDrawerMenu)
.expect(designerPage.publisereLeftMenuItems[0].visible).ok()
.expect(designerPage.publisereLeftMenuItems[1].visible).ok()
});
10 changes: 10 additions & 0 deletions src/test/Testcafe/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion src/test/Testcafe/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "UI tests for Altinn tjenester 3.0",
"main": "app.js",
"scripts": {
"start": "cross-env NODE_ENV=test && testcafe chrome ."
"test": "node .\\testRunner --env=dev"
},
"keywords": [],
"author": "",
Expand All @@ -15,5 +15,9 @@
"process": "^0.11.10",
"testcafe": "^0.22.0",
"tslint": "^5.11.0"
},
"dependencies": {
"testcafe-react-selectors": "^3.0.3",
"testcafe-reporter-junit": "^3.0.0"
}
}
71 changes: 57 additions & 14 deletions src/test/Testcafe/page-objects/designerPage.js
Original file line number Diff line number Diff line change
@@ -1,34 +1,77 @@
import { t, Selector } from 'testcafe';
import { ReactSelector } from 'testcafe-react-selectors';
import App from '../app';


export default class designerPage {
export default class DesignerPage {
constructor() {
this.header = Selector(".button").withText("Header");
this.inputBtn = Selector(".button").withText("Input");
this.dropDown = Selector(".button").withText("Dropdown");
this.checkBoxes = Selector(".button").withText("Checkboxes");
this.radioButtons = Selector(".button").withText("RadioButtons");
this.textArea = Selector(".button").withText("TextArea");
this.fileUpload = Selector(".button").withText("FileUpload");
this.submit = Selector(".button").withText("Submit");
this.addContainer = Selector(".button").withText("Add Container");
this.saveButton = Selector(".button").withText("Save");
this.header = Selector("#schema-components").withText("Header");
this.inputBtn = Selector("#schema-components").withText("Input");
this.dropDown = Selector("#schema-components").withText("Dropdown");
this.checkBoxes = Selector("#schema-components").withText("Checkboxes");
this.radioButtons = Selector("#schema-components").withText("RadioButtons");
this.textArea = Selector("#schema-components").withText("TextArea");
this.fileUpload = Selector("#schema-components").withText("FileUpload");
this.submit = Selector("#schema-components").withText("Submit");
this.addContainer = Selector("#schema-components").withText("Add Container");
this.saveButton = Selector("#schema-components").withText("Save");
this.addApiConnection = Selector(".d-block").withText("Api connections").child(0);
this.addRuleConnection = Selector(".d-block").withText("Rule connections").child(0);
this.addConditionalRendering = Selector(".d-block").withText("Conditional Rendering").child(0);

//left drawer menu
this.leftDrawerMenu = Selector('#root > div > div:nth-child(2) > div:nth-child(1) > div > div > div');
this.leftMenuList = Selector('li') //all unordered list elements to be filtered

//"Om" navigation tab selectors
this.omNavigationTab = Selector('div').withExactText('Om');
this.omLeftMenuItems = [
this.leftMenuList.withExactText('Om tjenesten'),
this.leftMenuList.withExactText('Roller og rettigheter'),
this.leftMenuList.withExactText('Produksjon'),
this.leftMenuList.withExactText('Versjonshistorikk'),
this.leftMenuList.withExactText('Om sluttbrukeren'),
this.leftMenuList.withExactText('Altinn.no')
];

//"Lage" navigation tab selectors
this.lageNavigationTab = Selector('div').withExactText('Lage');
this.lageLeftMenuItems = [
this.leftMenuList.withExactText('Datamodell'),
this.leftMenuList.withExactText('GUI'),
this.leftMenuList.withExactText('API')
];

//"språk" navigation tab selectors
this.spraakNavigationTab = Selector('div').withExactText('Språk');
this.spraakLeftMenuItems = [
this.leftMenuList.withExactText('Tekst'),
this.leftMenuList.withExactText('Flere språk')
];

//"teste" navigation tab selectors
this.testeNavigationTab = Selector('div').withExactText('Teste');
this.testeLeftMenuItems = [
this.leftMenuList.withExactText('Test')
];

//"publisere" navigation tab selectors
this.publisereNavigationTab = Selector('div').withExactText('Publisere');
this.publisereLeftMenuItems = [
this.leftMenuList.withExactText('Produksjonsette'),
this.leftMenuList.withExactText('Status')
];

//preview tab
this.previewSaveButton = Selector(".a-btn-success").withText("Save");
this.controlAndSubmit = Selector(".a-btn-success");

//tekst tab
this.nyTextButton = Selector(".btn").withText("Ny tekst");
this.nyTittelButton = Selector("#schema-texts").withText("Tittel");
this.addNewLanguage = Selector("#newtab > a");
}


deleteDataModelTexts(numberToDelete) {
async deleteDataModelTexts(numberToDelete) {
let deleteButtons = await Selector(".tbn").withText("Slett");
let count = deleteButtons().count;

Expand Down
2 changes: 1 addition & 1 deletion src/test/Testcafe/page-objects/loginPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default class LoginPage {
this.welcomeLoginButton = Selector('[value ^= "Logg inn"]');
this.userInput = Selector('#user_name');
this.passwordInput = Selector('#password');
this.loginButton = Selector('.ui.green.button');
this.loginButton = Selector('.button').withExactText('Logg inn');
}

}
25 changes: 15 additions & 10 deletions src/test/Testcafe/testRunner.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,35 @@
const createTestCafe = require('testcafe');
const fs = require('fs');
let testcafe = null;

createTestCafe()
.then(tc => {
testcafe = tc;
const runner = testcafe.createRunner();
const stream = fs.createWriteStream('junit.xml');

return runner
.browsers(['chrome'])
.browsers(['chrome:headless'])
.concurrency(1)
//.speed(0.75)
.screenshots('./screenshots', { takeOnFails: false })
.reporter('spec')
.src(['./repository_tests/login_create_new_repo.js'])
.screenshots('./screenshots', { takeOnFails: true })
.reporter('junit', stream)
.src(['./designer_tests/navigation-tests.js'])
.run({
skipJsErrors: true,
quarantineMode: false,
selectorTimeout: 2000,
assertionTimeout: 1000,
pageLoadTimeout: 1000,
selectorTimeout: 5000,
assertionTimeout: 5000,
pageLoadTimeout: 5000,
speed: 1,
debugOnFail: true,
stopOnFirstFail: true
stopOnFirstFail: false
})
.then(failedCount => {
console.log('Total tests failed ' + failedCount);
stream.end();
})
})
.then(failedCount => {
console.log('Total tests failed: ' + failedCount);
.then(() => {
testcafe.close();
});
Loading

0 comments on commit 7b9c86c

Please sign in to comment.