Try skipping ahead to the following spec file even if the initial spec has not been completed yet

I have encountered an issue when trying to execute two spec files for Angular.js. The problem arises when I attempt to run both files consecutively - the browser initially opens for angular.js, then switches to angularCal.js without executing angular.js at all. I also tried using 'src/test/*.js' and suites, but encountered the same issue. Interestingly, when I executed the spec files separately, they worked fine.

// Configuration
import { Config, browser } from 'protractor';
import { testConfig, platform } from 'protractor-html-reporter-2'

let HtmlScreenshotReporter = require('protractor-html-reporter-2');
let jasmineReporters = require('jasmine-reporters');

let reportsDirectory = './reports';
let dashboardReportDirectory = reportsDirectory + '/dashboardReport';

// Example configuration file
exports.config = {
    directConnect: true,

    capabilities: {
        browserName: 'chrome'
    },

    specs: ['src/test/angularCal.js'],

    jasmineNodeOpts: {
        showColors: true,
    }, onPrepare: function () {
        // xml report generated for dashboard
        browser.manage().timeouts().implicitlyWait(5000);
        jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
            consolidateAll: true,
            savePath: reportsDirectory + '/xml',
            filePrefix: 'xmlOutput'
        }));

        var fs = require('fs-extra');
        if (!fs.existsSync(dashboardReportDirectory)) {
            fs.mkdirSync(dashboardReportDirectory);
        }

        jasmine.getEnv().addReporter({
            specDone: function (result) {
                if (result.status == 'failed') {
                    browser.getCapabilities().then(function (caps) {
                        var browserName = caps.get('browserName');

                        browser.takeScreenshot().then(function (png) {
                            var stream = fs.createWriteStream(dashboardReportDirectory + '/' + browserName + '-' + result.fullName + '.png');
                            stream.write(new Buffer(png, 'base64'));
                            stream.end();
                        });
                    });
                } else if (result.status == 'passed') {
                    browser.getCapabilities().then(function (caps) {
                        var browserName = caps.get('browserName');

                        browser.takeScreenshot().then(function (png) {
                            var stream = fs.createWriteStream(dashboardReportDirectory + '/' + browserName + '-' + result.fullName + '.png');
                            stream.write(new Buffer(png, 'base64'));
                            stream.end();
                        });
                    });
                }
            }
        });

    },

    onComplete: function () {
        var browserName, browserVersion;
        var capsPromise = browser.getCapabilities();

        capsPromise.then(function (caps) {
            browserName = caps.get('browserName');
            browserVersion = caps.get('version');

            var HTMLReport = require('protractor-html-reporter-2');
            let testConfig = {
                reportTitle: 'Protractor Test Execution Report',
                outputPath: dashboardReportDirectory,
                outputFilename: 'index',
                screenshotPath: './',
                testBrowser: browserName,
                browserVersion: browserVersion,
                modifiedSuiteName: false,
                screenshotsOnlyOnFailure: false,
            };
            new HTMLReport().from(reportsDirectory + '/xml/xmlOutput.xml', testConfig);
        });
    },
};

//angular.js =spec 1

import { browser, by, element } from "protractor";
import { BaseTest } from "../common/BaseTest";
import { angularsite } from "../pageobjects/angular_site";

describe('Angular site', function () {
    let base = new BaseTest()
    browser.get("https://material.angular.io/components/autocomplete/overview")
    let ang = new angularsite();

    it('Scroll down', function () {
        ang.scrollSettingSeparate();
    })

    it('Select Text (Alert)', function () {
        ang.autocom(2, 2);
    })

    it('Checkbox', function () {
        ang.checkboxtab();
        ang.clickcheckbox();
    })

    it('DatePicker', function () {
        ang.clickdatetab();
        ang.clickdatemenu();
        ang.clickcurrentdate()
    })

    it('Radiobutton', function () {
        ang.clickradiobuttontab();
        ang.clickradiobutton();
    })

    it('Slider', function () {
        ang.clickslidertab()
        ang.clicksliderop(3, 2, 3, 3)
    })

    it('Switch Alert', function () {
        browser.get("http://www.way2automation.com/angularjs-protractor/banking/#/manager/addCust")
        ang.alert(2)
    })

    it('Switch windows', function () {
        browser.ignoreSynchronization = true;
        browser.get("https://skpatro.github.io/demo/links/")
        ang.switch_windows()
    })
})

angularCal.js = spec2 

import { browser, element, by } from "protractor";
import { BaseTest } from "../common/BaseTest";
import { datatable } from "../pageobjects/table_data";
import { calculator } from "../pageobjects/calculator_page";

describe('Calculator Page', function () {
    let base = new BaseTest()
    let calcu = new calculator();

    beforeEach(function() {
        calcu.clear_num1()
        calcu.clear_num2()
      });

    afterEach(function() {
        calcu.clear_num1()
        calcu.clear_num2()
      });

    browser.get(base.StartTest(1))

    it('Validate Calculator Page Addition feature', function () {
        calcu.enter_num1(2)
        calcu.addition_Operator()
        calcu.enter_num2(3)
        calcu.click_Button();

        calcu.validate_OutPut(4);

    })

    it('Validate Calculator Page Subtraction feature', function () {
        calcu.enter_num1(2)
        calcu.subtract_Operator()
        calcu.enter_num2(3)
        calcu.click_Button();

        calcu.validate_OutPut(5);

    })

    it('Validate Calculator Page Multiplication', function () {
        calcu.enter_num1(11)
        calcu.multi_Operator()
        calcu.enter_num2(12)
        calcu.click_Button();

        calcu.validate_OutPut(4);

    })

    it('Validate Calculator Page Division', function(){
        calcu.enter_num1(2)
        calcu.division_Operator()
        calcu.enter_num2(3)
        calcu.click_Button();

        calcu.validate_OutPut(7);
    })

    it('Validate Calculator Page Modulo', function(){
        calcu.enter_num1(2)
        calcu.modulo_Operator()
        calcu.enter_num2(3)
        calcu.click_Button();

        calcu.validate_OutPut(8);
    })

    it('Get Table data', function () {
        let table = new datatable()
        table.get_dataTable();
    })
})


Answer №1

In Jasmine, any code placed within a describe block that is not contained within an it statement or one of the hooks (such as beforeAll or beforeEach) will be executed before any tests are run. This can lead to unexpected behavior in how Jasmine operates.

The reason you are seeing both of your URLs being hit immediately is because both browser.get commands are running before your tests.

To address this issue, consider changing your code to the following:

describe('Calculator Page', function () {
   beforeAll(function(){
     browser.get(base.StartTest(1))
   })
})

Update: Revised structure slightly

describe('Angular site', function () {
    let base = new BaseTest()
    let ang = new angularsite()

    beforeAll(function(){
       //browser.get(base.StartTest(2));
       browser.get("https://material.angular.io/components/autocomplete/overview")
    })
})

Answer №2

If you want to incorporate suites into your configuration file:

suites: {
react: './src/test/react.js',
reactCal: './src/test/reactCal.js'
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips for successfully mocking axios.get in Jest and passing AxiosPromise type value

I attempted to simulate the axios.get() function using the code below, however TypeScript is returning an error stating "argument of type '{ data: expectedResult }' is not assignable to parameter of type 'AxiosPromise<{}>'". Can any ...

Tips for effectively utilizing TypeORM transactions

I'm encountering an issue with transactions in TypeORM. Here's a snippet of the code causing me trouble: const someFunction = async () => { try { await this.entityManager.transaction(async (manager) => { //some opera ...

Distributing a library of components using Vite, Vue 3, and Typescript to npm

My current challenge involves publishing a Vue 3 component library with Vite, all written in Typescript. The issue I'm facing is that the type definitions are not being included in the package when imported into another project. Upon importing the co ...

Is it possible to determine the specific type of props being passed from a parent element in TypeScript?

Currently, I am working on a mobile app using TypeScript along with React Native. In order to maintain the scroll position of the previous screen, I have created a variable and used useRef() to manage the scroll functionality. I am facing an issue regardi ...

having trouble retrieving information from mongodb

Currently working with nestjs and trying to retrieve data from a collection based on the 'name' value. However, the output I am getting looks like this: https://i.stack.imgur.com/q5Vow.png Here is the service code: async findByName(name):Promi ...

Utilizing web components in React by solely relying on a CDN for integration

I have a client who has provided us with a vast library of UI elements that they want incorporated into our project. These elements are stored in javascript and css files on a CDN, and unfortunately I do not have access to the source code. All I have at my ...

What improvements can I make to enhance my method?

I have a block of code that I'm looking to clean up and streamline for better efficiency. My main goal is to remove the multiple return statements within the method. Any suggestions on how I might refactor this code? Are there any design patterns th ...

The functionality of CDK Drag Drop is not accurately adjusting the placement of images

I have implemented an image gallery and am working on rearranging the position of the images using the Drag & Drop cdk library. However, I am facing an issue where the swapping of images does not always occur correctly; sometimes when attempting to exchan ...

Lazy loading in Angular 2 hits a snag when using a module that is shared

After successfully lazy loading my AccountModule, I encountered an issue when adding my SharedModule to it. All of my eagerly loaded modules seemed to be forgotten and I started receiving the following error: The component FoodComponent is not part of a ...

Why does WebStorm fail to recognize bigint type when using TSC 3.4.x?

Currently, I am working on the models section of my application and considering switching from using number to bigint for id types. However, despite knowing that this is supported from TSC 3.2.x, WebStorm is indicating an error with Unresolved type bigint. ...

Mistakes that occur while trying to expand a base class to implement CRUD functionality

Creating a base class in TypeScript for a node.js application to be extended by all entities/objects for CRUD operations is my current challenge. The base class implementation looks like this: export class Base { Model: any; constructor(modelName ...

What is the best way to generate conditional test scenarios with Protractor for testing?

Currently, there are certain test cases that I need to run only under specific conditions. it ('user can successfully log in', function() { if(siteAllowsLogin) { ..... } The problem with the above approach is that even when sitesNo ...

`Achieving efficient keyboard navigation with MUI Autocomplete and SimpleBar integration in React``

Currently, I am attempting to integrate the Simplebar scrollbar into the MUI Material Autocomplete component in place of the default browser scrollbar. While everything is functioning correctly, this customization has caused me to lose the ability to use t ...

Angular - personalized modal HTML

I am facing a challenge where I need to trigger a popup when a button is clicked. There can be multiple buttons, each with its own overlay popup, and these popups should close when clicking outside of them. Currently, I am using TemplateRef (#toggleButton ...

Bringing in SCSS using Typescript, React, and Webpack

I am trying to utilize .scss classes by importing them and applying them to the className property of a React component. Here is the structure of my project : root/ ... config/ ... webpack.config.js src/ ... global.d.ts app/ ...

What kind of impact on performance can be expected when using index.ts in a Typescript - Ionic App?

When setting up the structure of a standard Ionic app, it typically looks like this: app pages ----page1 ---------page1.ts ----page2 ---------page2.ts If I were to include an index.ts file in the pages folder as follows: pages/index.ts export { Page1 } ...

Creating a function that is accessible to the entire module

Creating a universal function in a file that is not a module: example.ts: function example() {} You can easily call this function from another file, say test.ts, without needing to import the function from example.ts: test.ts: example(); // calling univ ...

Choose from the Angular enum options

I am working with an enum called LogLevel that looks like this: export enum LogLevel { DEBUG = 'DEBUG', INFO = 'INFO', WARNING = 'WARNING', ERROR = 'ERROR' } My goal is to create a dropdown select el ...

Error: Unable to generate MD5 hash for the file located at 'C:....gradle-bintray-plugin-1.7.3.jar' in Ionic framework

When attempting to use the command ionic cordova run android, an error occurred that prevented the successful execution: The process failed due to inability to create an MD5 hash for a specific file in the specified directory. This issue arose despite suc ...

What is the best way to transform a JavaScript object into an array?

Here is the information I have: {product_quantity: {quantity: 13, code: "AAA", warehouse: "1000",}} The product_quantity field is part of a JSON object in a MongoDB database. I am looking to convert it into this format: {"produ ...