Create a dynamic list of specifications within Protractor

Our goal is to have the capability to execute a dynamic group of spec files.

// This approach would be perfect, but unfortunately it's not functional
exports.config = {
    specs: () => {
        /* Retrieve a list of tests to be executed from an API or CSV file
    },
......
}

If you have any suggestions, please feel free to share them.

Answer №1

I will tackle this question specifically for JavaScript, rather than TypeScript. This should give you a good understanding of the options available to you.

If you are interested in using pre-defined test suites, there are two main approaches:

1. Protractor

To set this up, modify your configuration file as shown below:

exports.config = {
    // ...

    specs: function (option) {

        let suites = require("./suites.json");

        return suites[option]
    }(process.env.SUITE)

    // ...
};

You will also need to create a suites.json file with the following structure:

{
  "providers": [
    "tests/providers/*.spec.js"
  ],
  "users": [
    "tests/users/*.spec.js"
  ],
  "production": [
    "tests/*/expected-configs.spec.js",
    "tests/*/environment-configuration.spec.js",
    "tests/*/last-claim-filter.spec.js",
    "tests/*/diagnosis-bh-filter.spec.js"
  ],
  "sanity": [
    "tests/*/expected-configs.spec.js",
    "tests/*/environment-configuration.spec.js",
    "tests/*/info-panel.spec.js",
    "tests/*/robohelp.spec.js"
  ]
}

To run Protractor with a specific suite, use the command

SUITE="production" protractor protractor.conf.js
(may be different on Windows).

Unfortunately, CSV files cannot be used with this method, and it may not be practical. Additionally, I am unsure about starting Protractor from an API, as you mentioned.

2. Grunt

Setting this up can be complex, so there is no one-size-fits-all solution. However, it seems like this could meet your needs.

Grunt is a task runner. You would need to configure a task that involves:

  • Accepting parameters from the command line;
  • Cleaning up temporary files;
  • Converting CSV files into JSON in a temporary folder;
  • Generating additional files based on parameters, such as config files;
  • Finding the desired test suite based on the provided parameter and passing it to Protractor before execution begins;
  • Initiating Protractor.

Answer №2

If you're up for a challenge, consider utilizing the getMultiCapabilities configuration method:

https://github.com/angular/protractor/blob/master/lib/config.ts#L383

The concept is simple - your capabilities object can include a specs property: specs?: string[];. This allows you to add specs to your config dynamically and even use exclude?: string[]; to exclude specific test files during execution.

Your code could resemble something like this:

exports.config = {
    specs: [] // initially empty, will be updated through capabilities

    // When getMultiCapabilities is utilized, both capabilities and multiCapabilities are disregarded
    getMultiCapabilities: async function () {
         // For instance, fetching specs from an HTTP response
         const request = require('request-promise-native')
         const specsFromAPI = await request.get('http://some.api/specs')
         // should return an array of Capabilities objects
         return [{
             browserName: 'chrome',
             specs: specsFromAPI
         }]
    }
}

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

Can someone explain how to showcase a collection attribute in Angular?

I am working with a collection of objects called "ELEMENT_DATA". Each object in the collection has an attribute named "Activite", which is also a collection. My goal is to display this attribute in a specific way. Below is my app.component.ts: export cla ...

Ensuring proper validation of sinon stub parameters in TypeScript

One of the unit tests in my code is responsible for checking the function arguments. it('Should retrieve product from the database', () => { stub(ProductModel, 'findById').returns({ lean: stub().returns({ total: 12 }), }); ...

Modify a single parameter of an element in a Map

Imagine I have a map data type exampleMap: Map<string, any> The key in the map is always a string, and the corresponding value is an object. This object might look like this: { name: 'sampleName', age: 30} Now, let's say the user se ...

One-liner in TypeScript for quickly generating an object that implements an interface

In Typescript, you can create an object that implements an interface using a single expression like this: => return {_ : IStudent = { Id: 1, name: 'Naveed' }}; Is it possible to achieve this in just one statement without the need for separate ...

I am attempting to select the second checkbox within a nested ng-repeat in my Protractor Test

Here is the snippet of my code: <div class="sl" ng-repeat="qual in mQuals | orderBy : 'order'"> <div ng-repeat="cList in tList | orderBy:'Priority' " ng-if="c == qualifier.Id"> <p class="sl-text-body--small ...

Is React 18 compatible with both react-redux and react-router?

At present, my react application is running on the following versions: react 17.0.x react-dom 17.0.x react-redux 7.2.x react-router-dom 5.x.x react-scripts 4.0.x redux 4.x.x My initial step towards upgrading to react@18 involved updating react-scripts to ...

Just getting started with Typescript and Angular and encountering issues with sending POST requests using Http

Recently, I started learning Angular and Typescript. One of the tasks I attempted was creating a basic login page. To achieve this, I developed a service in typescript that triggers upon clicking the 'Login' button. The input fields for username ...

The functionality of the Vert.x event bus client is limited in Angular 7 when not used within a constructor

I have been attempting to integrate the vertx-eventbus-client.js 3.8.3 into my Angular web project with some success. Initially, the following code worked perfectly: declare const EventBus: any; @Injectable({ providedIn: 'root' }) export cl ...

Tips for incorporating a mesh into Forge Viewer v6 with Typescript

Is there a way to add meshes to Forge Viewer v6 using Type script? I've tried various methods that worked with v4, but I'm encountering issues now. private wallGeometry: THREE.BoxBufferGeometry; drawWalls() { ...

What causes React component state initialization to return a `never` type when set to null?

Initializing a component's state to null outside of the constructor results in the state having the type never in the render function. However, when the state is initialized within the constructor, the correct type is maintained. Despite many StackO ...

options argument containing a keyof this

When defining a method type signature, it is possible to use keyof this to restrict an argument to the string name of a valid key of the class. However, using this approach does not work when the method accepts options-style arguments instead of positional ...

Validator in Angular FormControl ensures that two fields have the same value or both are empty

When filling out a form with four fields, I have encountered a specific requirement. Two of the fields are mandatory, which is straightforward. However, the other two must either both be empty or both have a value - essentially resembling an XNOR logic sta ...

Modifying the website favicon based on the URL address

I am currently working with a client who wants our web application to reflect their branding through the URL. They have requested that we change the favicon on the page to display their private label logo, as well as changing the title. However, I am strug ...

Searching through all values can be done by following these steps

Need help with implementing a search feature that can search all values in Angular2. Here's the current code snippet: import { Pipe, PipeTransform } from '@angular/core'; @Pipe({ name: 'filter' }) export class FilterPipe implem ...

Downloading files (PDF, JPG, PNG) instead of automatically opening in a new tab

Is there a way to automatically download PDF and JPG files instead of opening them in a new tab like .docx files? Currently, when clicking on a PDF or JPG link, it opens in a new tab rather than downloading the file. The desired behavior is for these files ...

Changing a photo into base64 format using Angular 2

How can I convert an image to base64 in Angular 2? The image is uploaded from the local filesystem. Currently, I am using fileLoadedEvent.target.result to achieve this. However, when I try to send this base64 string through REST services to Java, it fails ...

Ways to describe an item using a mix of determined and undetermined attributes

I am attempting to create a TypeScript type that includes properties I know and properties I do not know. Here is what I have tried: type MetaType = { res?: HttpResponse; req?: HttpRequest; [key: string]: string | number | boolean | string[] } ...

Ionic Vue is throwing an error indicating that a property is not found on the type '{ $route(currentRoute: any): void; }'

Currently, I am developing an Ionic WebApp using Vue and TypeScript. My current task involves retrieving the current id parsed by the route. To achieve this, I have been working on a watcher: export default { data() { return { ...

Using webpack to group files from the "src" directory into the "public" folder

What is the best way to package all the files within the “src” folder and update the current bundled files in the “Public” folder of a Node.js web application? The structure of my project resembles this example: https://github.com/googlearchive/fr ...

What is the best way to convert a `readonly string[]` to a regular `string[]`?

My data setup is as follows (I am not declaring it as an enum because it is used in both TypeScript server code and non-TypeScript client code): import { enumType } from 'nexus'; export const TYPE_ENUM = Object.freeze({ H: 'H', S: ...