Protractor tests encounter issues when working with Select2 within a modal in Angular

I am facing a challenge while running my angular e2e tests using protractor. In some cases, I have a select element inside a modal. The issue arises when the test fails to locate the select element with the following error message:

NoSuchElementError: No element found using locator: By.cssSelector("div#s2id_items”)

Interestingly, on slower machines, this works consistently, but on faster machines, it tends to fail. My assumption is that the modal might still be in the process of animating when protractor attempts to access the selector, resulting in a failure.

I made an attempt to disable animations without success by incorporating the code below within the onPrepare directive in my protractor configuration file:

var disableNgAnimate = function() {
  angular.module('disableNgAnimate', []).run(['$animate', function($animate) {
    $animate.enabled(false);
  }]);
};
browser.addMockModule('disableNgAnimate',disableNgAnimate);

My setup includes angular 1.4.3, bootstrap 3.3.5, and protractor 2.1.0.

Thank you

Edit:

1 - I'm not utilizing explicit waits and would prefer not to, as they could significantly slow down the tests or still be susceptible to failure under certain circumstances.

Answer №1

To add a waiting feature in your tests, consider utilizing Protractor's Expected Conditions. Here's an example of how you can use it:

var EC = protractor.ExpectedConditions;
var myElement = element(by.css('div#s2id_items'));

browser.wait(EC.presenceOf(myElement), 5000);
//continue with your code

This wait function will efficiently pause the test execution until the specified element appears, allowing your tests to proceed without unnecessary delays.

For interactive and animated elements, you can explore the predefined "elementToBeClickable" condition or create a custom one tailored to your specific requirements. Remember that E2E testing should mimic user behavior, so including waits for animations can enhance the accuracy of your tests.

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

Converting a JSON object to a string and replacing specific text can be achieved by following

I have a JSON object that I need to convert to a string and then perform substring replacements using JQuery var data = JSON.stringify(object); data = data.replace("meat", "vegetables"); console.log(data); However, when I attempt to run this code, I enco ...

Error: The property 'rtl' is not defined and cannot be read

I'm currently in the process of developing a vuejs component library that utilizes vuetify 2.1.4 and attempting to import it into another application locally through npm link. However, I'm encountering numerous errors such as TypeError: Cannot ...

Interop-require-default is nowhere to be found in the babel-runtime

I'm really stuck on how to resolve this error. I've tried searching online and followed the suggestions given by others. I even went as far as deleting 'node_modules' and reinstalling, but nothing seems to be working. The specific erro ...

What does the cb parameter represent when null in the context of multer?

Why do the cb functions in the code snippet below from the multer API take null as their first argument? What are the implications of using null in this context, and what alternative values could be passed besides null? var storage = multer.diskStorage( ...

A guide on implementing Angular-DataTable within a TypeScript project

Hey everyone, I'm currently working on a TypeScript and Angular application. To create a data table, I decided to use Angular-DataTable. After creating a sample application using it, I added the following code to my Controller: constructor(protecte ...

Insert a stylish border to frame the Google pie chart

I recently created a Google Pie chart and I'm looking to add a border around it. Can anyone provide assistance with this task? Below is the code for the Google Chart along with an image of how I would like it to appear. <!DOCTYPE html> ...

Enhancing UI Design with Styled-Components and Material Components using Media Queries

Struggling to grasp media queries with MUI and styled components. Take a look at the following syntax using styled-components: Syntax 1: const Video = styled.video` width: 860px; @media ${device.mobileSM} { width: 90%; } `; Additionally, there ...

Partial functionality noticed in Bootstrap navbar CSS

I seem to be encountering a peculiar issue with Bootstrap 3.3.6 CSS, where it is only partially functioning. Despite ensuring the proper structure of the site (correct classes in the right places, etc.), it appears that some of the CSS styles are missing. ...

Incorporate data into the div element

I've been attempting to populate a div after selecting 3 different options from select boxes, but nothing seems to be happening. I have confirmed that the PHP function works as expected when tested manually, but I'm unable to get it to populate a ...

Acquire the <li> element when it is clicked using vanilla JavaScript

Whenever a user enters a value in an input field, my function automatically adds a <li> element to a <ul>. Additionally, the function assigns the attribute ( onclick="doneToggle" ) to the created <li>. function createListElement() { ...

The functionality of the Eslint object-property-newline feature is not functioning as expected

Within my configuration file .eslintrc, I have set "object-property-newline": ["error", { "allowAllPropertiesOnSameLine": true }], and "max-len": "off". However, objects like const something = {a: 5, ffsdfasdasdsddddd: 'asdasdasdddddddddddssssssddddd ...

Retrieve and modify the various elements belonging to a specific category

I'm currently developing a chrome extension and I need to access all elements of this specific type: https://i.stack.imgur.com/sDZSI.png I attempted the following but was unable to modify the CSS properties of these elements: const nodeList = documen ...

"Encountering problem with Angular HTTP services: the requested URL is not

Attempting to send data to API servers is resulting in a 404 error. Testing it on Postman shows that everything works fine. JSONP is being used for posting data due to cross-domain issues. The console displays the following: GET http://myapi.com/registrat ...

What's the rationale behind receiving the second before the first?

I've been digging into ES6 promises, and I thought I had a handle on it for a moment. However, it seems like I may have hit a roadblock. What I'm aiming to do is handle a series of file operations where each operation depends on the completion o ...

Exploring Angular 6 with Universal Karma for effective module testing

Issue I have been facing challenges while testing my Angular 6 application with Karma. I am encountering errors such as: Can't bind to 'ngModel' since it isn't a known property of 'mat-select'. Although the import works in ...

Is it possible to align the navigation within the Bootstrap (5) grid structure like I have shown in my example?

Can this be achieved? Any tips on how to do it while sticking within the Bootstrap framework would be greatly appreciated. Text blocks should align with the navigation border on the left and right side: <link rel="stylesheet" href="https://cdn.jsd ...

Is it possible to customize the selected color of the Chip component?

Is there a way to change the clicked color of a Chip component without modifying the theme.js file? I attempted to override the classes with the desired colors, but it still defaults to primary/secondary colors. This information was found in the source co ...

Display elements on the side of the page using jQuery as the user scrolls

I'm in search of a helpful jQuery plugin that I can't quite put a name to! Can anyone point me in the right direction? Take a look at this website for inspiration: On that page, you'll notice that as you scroll down, elements smoothly appe ...

The configuration of flexDirection seems to be making images vanish

I have successfully arranged my images to display one after another, but I want them to be positioned horizontally instead of vertically. I attempted to achieve this by using flexDirection: 'row' and setting scrollview to horizontal, however, the ...

Tracking the progress of file uploads using Ajax

Currently, I am working on integrating file upload using Ajax and Php on my local Apache server. This is strong text. $('.uploadButton').click(function(){ var formData = new FormData($(this).closest('.fileUploadFor ...