Skip a single test from a suite in Firefox using Protractor automation framework

I have a collection of tests in my tests folder, all named with the convention ending in spec.js. By using the */spec.js option in the Config file, I am able to run all tests seamlessly.

However, I encountered an issue where I needed to skip running a specific test in Firefox due to compatibility issues. Even after attempting to implement the necessary code, the test still runs on Firefox. Any guidance on how to resolve this would be appreciated.

multiCapabilities: [{
  'browserName': 'chrome',
  'chromeOptions' : {
    args: ['--window-size=900,900']
    // }
  },
},

{
  'browserName': 'firefox',
  'chromeOptions' : {
    args: ['--window-size=900,900']
    // }
  },
}],

specs: [
  '../tests/*.spec.js'
],

Within my onPrepare function, I've included the following:

browser.getCapabilities().then(function (cap) {
    browser.browserName = cap.caps_.browserName;
});

In the test file where exclusion for Firefox is required, the following condition is present:

if(browser.browserName=='firefox') { 
console.log("firefox cannot run *** tests")

} else { 

blah... rest of the tests which I want to execute for Chrome and IE I have put it in this block}

Despite these efforts, the test intended to be skipped in Firefox continues to run. Any suggestions on how to rectify this issue are welcome.

Answer №1

A simple method to achieve this is by updating the multicapabilities in Firefox to exclude specific test specs using the exclude tag. This eliminates the need for an if condition and reduces additional lines of code. For more information, refer to this link. Here's how you can do it:

multiCapabilities: [{
    browserName: 'chrome',
    chromeOptions : {
              args: ['--window-size=900,900']
                    }, 
    },
    {
    browserName: 'firefox',
    // Exclude certain spec files only from this capability.
    exclude: ['spec/doNotRunInChromeSpec.js'], //SPECIFY THE NAME OF THE SPEC YOU WANT TO EXCLUDE/SKIP
    }],

I hope this explanation proves helpful.

Answer №2

When using browser.getCapabilities(), which is asynchronous and utilizes Promises, it's important to note that the code inside .then() may execute at a later time than other parts of your code. If the if condition is within the describe block, it runs before the value for browser.browserName is set, resulting in a value of undefined, causing the condition to fail. To ensure that your tests run after all preparations are complete, return a promise from onPrepare:

onPrepare: function() {
    return browser.getCapabilities().then(function (cap) {
        browser.browserName = cap.caps_.browserName;
    });
}

Protractor will explicitly wait for this promise to resolve before executing the tests.

describe('Suite', function () {

    console.log(browser.browserName);  // 'firefox'

    it('spec', function () {
        expect(true).toBe(true);
    });
});

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

Managing the AJAX response from a remote CGI script

I'm currently working on a project that involves handling the response of a CGI script located on a remote machine within a PHP generated HTML page on an apache server. The challenge I am facing relates to user authentication and account creation for ...

Error encountered in my application due to Node.js (Error [ERR_HTTP_HEADERS_SENT]: Unable to change headers once they have been sent to the client)

Experiencing an error message in my application when typing nodeJS. Please assist. , Encountering an error after sending the first POST request while running the app. const express = require('express') const Workout = require("../models/work ...

What is the best way to retrieve the 'date,time' column from a MySQL database and use it as input for the google chart DateRangeFilter?

I am facing an issue with a column in my dataset that contains date-time values, such as '2017-2-2 10:30:20'. I need to use these rows as an input for a Date Range Filter in Google Chart. Can someone guide me on how to achieve this? I attempted ...

Is there a way to verify that all CSS files have been successfully downloaded before injecting HTML with JavaScript?

I am looking to dynamically inject HTML content and CSS URLs using JavaScript. I have more than 3 CSS files that need to be downloaded before the content can be displayed on the page. Is there a way to check if the aforementioned CSS files have finished ...

Exploring the Contrast between window.location.href and top.location.href

I'm curious about the distinction between window.location.href and top.location.href. Can anyone explain this to me? Furthermore, I'd like to know when it's appropriate to use each one. Which option is more suitable for redirection after a ...

What is the best way to implement a scrollbar in a specific div rather than the entire window?

Hey everyone! So, I have this window in electronJS with a div where I'm dynamically adding elements using Javascript and the function --> document.createElement('section'). Here's the loop in Javascript to add these elements: for (var ...

Is there a way to utilize Selenium in Python to click on numeric buttons with the onclick event?

Here is the HTML code I am working with: <ul aria-hidden="false" aria-labelledby="resultsPerPage-button" id="resultsPerPage-menu" role="listbox" tabindex="0" class="ui-menu ui-corner-bottom ui-widget ui-widget-content" aria-activedescendant="ui-id-2" a ...

Obtaining connected information in AngularJS with Firebase

After reviewing the example found at the following link: I am curious to know if AngularFire can be used to retrieve and show relational data (referred to as sparks) in a similar manner? ...

Guide on sending files through an API request with formData() using Vuejs and Axios

My goal is to utilize an API to upload a file to the server. The documentation on documenter.getpostman outlines how to use the API: --form 'type="1"' \ --form 'user_id="1"' \ --form 'file=@"/C:/U ...

Enlarge the div with a click

I was looking for a solution on how to make a div expand when clicked using jQuery I came across a tutorial that seemed simple and perfect, but I couldn't get it to work when I tried to replicate the code. Do you know if this code is still valid wit ...

Organize information in a React table following a predetermined sequence, not based on alphabetical order

As a beginner with React, I'm looking to sort my data by the column "Status" in a specific order (B, A, C) and vice versa, not alphabetically. The data structure looks like this: export interface Delivery { id: number; name: string; amount: num ...

"AngularJS makes it easy for the logged-in user's information to be accessible and available across

I need to ensure that user information is accessible across all views after logging in. How can I adjust the code to be able to retrieve the pseudonym from another view? Could you provide an example as well? Below is my login controller: app.controller ...

Is there a way to input data into an AngularJS modal?

I'm looking for some assistance : How do I go about loading data into the content of an angular modal? Is there a way to load custom data for a selected item? ............................................................. This is the code ...

The data is not being successfully transmitted to the controller method through the AJAX call

In my JavaScript file, I have the following code: $(document).ready(function () { $('#add-be-submit').click(function (event) { event.preventDefault(); $.ajax({ type: 'POST', url: '/snapdragon/blog/new&apos ...

Using nightwatch.js to verify elements across different parts of a webpage

Currently engaged in working with nightwatch.js and encountering an issue with a particular page file structure: sections: { table: { selector: '.sr-filterable-data-layout--collection', elements: { header: { ...

What is the best way to obtain just the name and phone number information?

Looking to extract the name and contact number from a div that can contain one, two, or three spans. The requirements are: Extract name and contact number only when available. If contact number is present but name is missing, assign 'N/A' to th ...

Is it possible to use contenteditable along with ng-model within an ng-repeat loop?

My current dilemma involves using the ng-repeat directive to generate a list of span elements. Each span includes both the contenteditable attribute and the ng-model directive for two-way data binding. Initially, everything functions as expected until I a ...

Getting a URL path in Next.js without relying on the Link component when the basePath is configured

Base Path from the next.js documentation states: For instance, by setting basePath to /docs, /about will automatically transform into /docs/about. export default function HomePage() { return ( <> <Link href="/about"> ...

I'm facing a challenge where Multer is preventing me from showing images in my React app

Hi there, I'm currently facing an issue where I am using multer to save files on my server and store their path in mongodb. However, I am struggling to display them on my React application. Any assistance would be greatly appreciated. Thank you in ad ...

What is the method to select a hyperlink that includes a variable in the "href" attribute and click on it?

Currently, I am in the process of creating acceptance tests utilizing Selenium and WebdriverIO. However, I have encountered a problem where I am unable to successfully click on a specific link. client.click('a[href=#admin/'+ transactionId + &apo ...