In my project I am using protractor + jasmine + TypeScript for e2e tests. I have already benefit from TypeScript glory of inheritance in my page object files (for example, I got some BasePageObject class with common methods/objects from which rest of PageObjects are derived). I would like to introduce same approach in my tests. Here example code, which I got right now:
Test suite A [ATest.ts]:
import {
SomePage,
LoginPage
} from '../pages';
describe('test suite A', () => {
let loginPage: LoginPage = new LoginPage();
let somePage: SomePage = new SomePage();
beforeAll(() => {
loginPage.login();
somePage.navigateTo();
});
it('my test 1', () => {
//test body, assertions etc.
});
it('my test 2', () => {
//test body, assertions etc.
});
});
Test suite B [BTest.ts]:
import {
AnotherPage,
LoginPage
} from '../pages';
describe('test suite B', () => {
let loginPage: LoginPage = new LoginPage();
let anotherPage: AnotherPage = new AnotherPage();
beforeAll(() => {
loginPage.login();
anotherPage.navigateTo();
});
it('my test 1', () => {
//test body, assertions etc.
});
it('my test 2', () => {
//test body, assertions etc.
});
});
As you can see, some of the code is common for both suites. What I would like to achieve is inheritance in my TCses, to write them more in Java Style and avoid code duplication (for example):
class BaseTestCase {
beforeAll() {
loginAction();
}
}
class TestA extends BaseTestCase {
beforeAll() {
specificStuff();
}
}
class TestB extends BaseTestCase {
beforeAll() {
specificStuff();
}
}
Is it possible in jasmine?
loginPageandanotherPagevariables used anywhere else? If they should be instantiated once per specs, they could be moved to a module and be singleton instances, couldn't they? - Estus Flaskdescribeis a function, not a class. So it does not have a class basedextends. You could use prototype inheritance but I would just create my own class and then have this calldescribe, something like this answer - Liam