I am using Protractor and Jasmine to create end-to-end tests for a webpage. To test this initial page, I have abstracted made some common utility functions to create about 20 test cases for this particular page. An example of this is shown.
describe('User is on the page and', function () {
beforeEach(function () {
browser.get('http://test.test');
});
it('page title of the page should be blahblah', function () {
expect(browser.getTitle()).toEqual('blahblah');
});
it('main header of the page should be test', function () {
expect(element(by.css('#entry-header h1')).getText()).toEqual('test');
});
...
}
The issue is I now have 6 other pages have extremely similar functionality. I don't like the thought of duplicating all these tests and maintaining them for each page, so I'm tempted to abstract out these test cases so that they could be reused across the different pages by passing in page specifics as parameters.
However, this also seems like a bad practice. Test cases are no longer descriptive, they are functions with passed parameters. The test cases also won't be as readable, as they would have to deal with some slightly different logic across the pages. Also, changes to the test cases might actually cause regressions for other pages.
Is there an accepted best practice or pattern for this use case?