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

What is the best way to extract data from a proxy in VUE3?

Currently, I am utilizing the ref() function to store data retrieved from Firebase. However, when attempting to filter and retrieve a single record, the outcome is not as expected. Instead of returning a single object, something different is being displaye ...

Learn how to trigger an HTTP exception after a failed command in a saga with NestJS CQRS

Currently utilizing the NestJS CQRS pattern to handle interactions between User and UserProfile entities within my system. The setup consists of an API Gateway NestJS server along with dedicated NestJS servers for each microservice (User, UserProfile, etc. ...

Troubleshooting Node.js import module errors

I have just discovered two files that I created using the TS language specification manual (on page 111). The first file, called geometry.ts, contains the following code: export interface Point { x: number; y: number }; export function point(x: number, y ...

Tips for integrating TypeScript with Vue.js and Single File Components

After extensive searching online, I have struggled to find a straightforward and up-to-date example of setting up Vue.js with TypeScript. The typical tutorials out there either are outdated or rely on specific configurations that don't apply universal ...

Using socket.io-client in Angular 4: A Step-by-Step Guide

I am attempting to establish a connection between my server side, which is PHP Laravel with Echo WebSocket, and Angular 4. I have attempted to use both ng2-socket-io via npm and laravel-echo via npm, but unfortunately neither were successful. If anyone h ...

Using the TypeScript NextPage function along with the getInitialProps static method and @typescript-eslint/unbound-method

After enabling typescript-eslint with its recommended settings, I encountered an issue in my code. I came across this helpful post on Stack Overflow: Using getInitialProps in Next.js with TypeScript const X: NextPage = props => {/*...*/} X.getInitialP ...

Simplify typing in TypeScript using default generic parameters

Imagine I came across the following object: const inquiries = { whoCreatesIssues: { options: { sameTeam: { id: 'SAME_TEAM' }, management: { id: 'MANAGEMENT' ...

What steps should I take to eliminate this issue in my Protractor tests: Error occurred while waiting for Protractor to synchronize with the page?

My Angular application is connected to AudioEye, Twitter, and a few other third-party apps. We employ lazy loading to bring in our components, so there is no rootElement app in our app. Our login page is actually a separate Angular application. However, wh ...

An informative step-by-step approach to constructing Angular applications utilizing npm and TypeScript

When I first encountered Angular2, I was introduced to TypeScript, npm, and more for the very first time. I was amazed by their power, but I know I've only scratched the surface. While I can navigate through the "development mode," my ultimate goal i ...

Having trouble retrieving the "history" from props?

I am working with a React component. import * as React from 'react'; import { Component } from 'react'; import { FormControl, Button } from 'react-bootstrap'; type Props = { history: any[]; }; // Question on defining Prop ...

The comparison between "rxjs-tslint" and "rxjs-tslint-rules" npm packages

Previously, I utilized the rxjs-tslint-rules package to identify RxJS-related issues in my projects. This package was included in the devDependencies section of my projects' package.json files. Now, there is a new rxjs-tslint package that introduces ...

Issue: Invalid parameter: 'undefined is not a numeric value' for DecimalPipe

Here is the HTML input code that I am using: <input class="number " type= "text" pInputText [readonly]="" formControlName="id" [required]="" plmNumberFormatter [value]="data?.id | numberPipe" /> However, when I place the cursor on the input fiel ...

The combination of Angular2, TypeScript, and moment.js is lacking in terms of available locales (only 'en' is supported)

Currently, I am following a tutorial in a book to grasp the concepts of TypeScript and AngularJS 2.0:(Become_a_Ninja_with_Angular2). In one section, the tutorial walks through creating a custom Pipe and demonstrates an implementation using moment.js. To ...

What steps should I take to fix this TypeScript error?

I've been struggling to fix this error, but I'm unsure of the best way to resolve it. Here is the code snippet I've been working with: Here is the specific error message: ...

Rendering illuminated component with continuous asynchronous updates

My task involves displaying a list of items using lit components. Each item in the list consists of a known name and an asynchronously fetched value. Situation Overview: A generic component named simple-list is required to render any pairs of name and va ...

Ways to prevent a user from reaching a specific page by entering the URL in a react and typescript application

Is there a way to restrict access to a specific page with the URL "myurl/view"? I want only admin users to be able to view this page, while preventing other users from accessing it. Currently, when the view button is clicked, it redirects to the URL "/vie ...

How can I add a parameter to a JSON URL in Angular?

I'm looking to enhance my URL by adding a new parameter, but I'm unsure of the steps needed. ts.file route(name:string) { this.router.navigate(['/homepage', (name)]); console.log('name); } service private url1 = './assets/ ...

Search through the directory of images and generate a JSON representation

I'm looking for a way to transform a URL-based directory of images into a Json object, which I can then utilize and connect within my Ionic project. Despite extensive searching, I have yet to find any satisfactory solutions to this challenge. Thus, I ...

Troubleshooting the issue of Angular 2 error: Cannot access the 'getOptional' property

Currently, I am navigating my way through angular 2 and attempting to define a service named searchservice. I want to inject this service in the bootstap part of my project: import {SearchService} from 'src/service'; Here is the code for the Se ...

TypeScript: By providing a variable CLASS as an argument to a function, automatically determine the return type to be an object of the specified class without any additional information

I am looking to create a function that accepts actual class objects themselves as arguments (within an object containing multiple arguments), with the return type of the function being inferred to be an instance of the class provided as the argument. In t ...