Initially, the code provided below appears to be functioning properly. However, I have not come across anyone using this method before, leading me to question its validity and potential unforeseen drawbacks.
The scenario involves writing an end-to-end test with Protractor utilizing Jasmine-style describe/it blocks. The objective is to load a page and execute a series of it
test blocks without having to reload the page each time (due to the time it consumes).
The structure I have implemented is as follows:
describe("Homepage", function () {
beforeEach(function () {
browser.get("/"); // loads the page
});
it('elements', function () {
describe('test group', function () {
it('test 1', function () {
// perform action 1
});
it('test2', function () {
// perform action 2
});
})
});
});
It is noted that an alternative approach could simply be:
describe("Homepage", function () {
beforeEach(function () {
browser.get("/"); // navigates to the homepage
});
it('elements', function () {
// perform action 1
// perform action 2
});
});
However, the challenge arises where tests cannot be separated, resulting in a large consolidated it
block. It is desired to circumvent running beforeEach every single time while still maintaining neatly organized test blocks.
Furthermore, an attempt was made with the following format:
describe("Homepage", function () {
browser.get("/"); // navigates to the homepage
it('elements', function () {
// perform action 1
// perform action 2
});
});
Regrettably, this approach fails when multiple specs are involved. All instances of browser.get() run consecutively prior to executing the tests.