Checking with Protractor to see if the modal is displayed

I am currently working on a Protractor test to check if a bootstrap modal window that confirms the deletion of a record is visible at this time.

The record that needs to be deleted is displayed in an angular ng-repeat, so I have to trigger the delete button from there.

When I use isPresent for testing, it always returns true because it checks the DOM for the modal window, which will always exist. However, when I use isDisplayed, it consistently returns false instead of the expected true.

Below is a snippet of the code...

// Use the .all repeater to search the array of presented records
element.all(by.repeater('entries in presentData')).then(function(presentData) {
    // get the first record and open the options menu
    presentData[0].element(by.css('.dropdown-toggle')).click();
    // In that first record click the delete button
    presentData[0].element(by.css('.delete-link')).click();
    browser.waitForAngular();
    // Remove the 'fade' class from the Bootstrap modal, as animations can sometimes interfere with testing
    browser.executeScript("$('.modal').removeClass('fade');");
    // Expect that the .modal-dialog is true
    expect(element(by.className('modal-dialog')).isDisplayed()).toBe(true);
});

I have tried various combinations based on solutions from stackoverflow and github, but nothing has worked for me so far.

Any help or insight you could provide would be greatly appreciated!

Answer №1

Transforming the comment into a response.

If inserting browser.sleep(5000) before the final expect function resolves the issue, it could be a timing problem. Consider implementing an active wait method as detailed here, which involves using the waitReady.js script. Add require('./waitReady.js'); in your onPrepare block and replace the last expect with:

var elm = element(by.className('modal-dialog');
expect(elm.waitReady()).toBeTruthy();

This expect statement will wait for the element to appear and then become visible.

By utilizing the waitReady.js script, you can avoid using sleep in such scenarios.

You might also consider placing another browser.waitForAngular(); immediately after the browser.executeScript command and relying on Protractor to handle the JS injection waiting process.

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

Steps to assign a value to an input element using the state in a React application

Hey there, I hope everything is going well for you! I have a question regarding setting the value of an input field based on the state received from props. I've tried to populate the input with data from the "profile" state using placeholders, but it ...

What are the best strategies for enhancing the performance of the jQuery tag:contains() selector

My goal is to extract all elements from a webpage that contain a specific set of words. For example, if I have an array of random words: words = ["sky", "element", "dry", "smooth", "java", "running", "illness", "lake", "soothing", "cardio", "gymnastic"] ...

What is the method for executing a function enclosed within a variable?

As someone new to the world of Java, I have encountered a puzzling issue with some code related to a game. Specifically, there seems to be an obstacle when it comes to utilizing the navigator function. When I click on this function in the game, some sort o ...

Firestore version 9 - Retrieve nested collection depending on a string being present in an array

Working on a new chat application here. It has been a while since I last used Firestore. I am currently using v9 and facing an issue with retrieving the nested "messages" collection when the "users" array in the document contains a specific ID. I have man ...

Angular Material Drop Down menu with UI-Router Integration

When the user clicks on the person icon, it triggers a form (form.html) using the ui-router logic defined in app.js. There are two types of dropdown boxes - one using the select tag and the other using the md-select tag. Everything works fine until I click ...

Determining height of an element in AngularJS directive prior to rendering the view

As I dive into the world of Angular, any assistance is greatly welcomed. My goal is to vertically align a div based on screen size (excluding the header and footer) when the page loads, the window resizes, and during a custom event triggered by the user ex ...

Check if there are any child nodes before executing the RemoveChild JavaScript function to avoid any errors

function delete(){ let k = document.getElementsByClassName('row'); for(let i=0; i<k.length; i++) { if(k[i].hasChildNodes()){ k[i].removeChild(k[i].childNodes[2]); } } } <div id="table"> <div class="row"& ...

I am seeking a solution to this error that occurs whenever I attempt to call a function using a button

Issue " _ctx.hello is not a function TypeError: _ctx.hello is not a function at onClick._cache.<computed>._cache.<computed> (webpack-internal:///./node_modules/babel-loader/lib/index.js??clonedRuleSet-40.use[0]!./node_modules/vue-loader/di ...

`@keyup.enter event listener will only be triggered upon pressing the Enter key if the focus is on

My login button only seems to work when I press the tab button after entering my email and password. I would like it to work whenever I press the enter key while on the Login page of this VueJS application. This is the HTML template: <template> ...

modify header when button is clicked

I am trying to create a JavaScript function that will update the name of an HTML table header when a button is clicked. However, I am having trouble accessing the text content within the th element. document.getElementById("id").text and document.getEl ...

Performing three consecutive Ajax requests in a Rails application

Recently, I developed a custom admin system for a local gym to manage payments, attendance, mailing, sales, and more. While everything is functioning smoothly, there seems to be an issue with the attendance feature. Occasionally, when taking attendance, an ...

Picture in the form of a radio button

Is there a way to use an image instead of a radio button in my AngularJS form? I have managed to hide the radio button using CSS, but it disables the checked event. How can I make the image clickable? position: absolute; left: -9999px; Here is the code s ...

Is there a way to retrieve a single value using AJAX instead of returning the entire HTML page?

(edited after initial version) I'm facing an issue where my AJAX call is returning the header.php page instead of just the $result value which should be 0 or 1. The AJAX function calls generateTicket.php, where I want to generate tickets only if no o ...

What is the method for launching a new tab within an incognito window that is already open?

In the process of developing a Chrome extension, I am focusing on the functionality of creating a new tab from context menus within an incognito window. My current approach involves using the following script: chrome.windows.create({url: "https://google.c ...

Is there a way to configure multiple entry points in a package.json file?

I am looking to execute various commands using npm: "scripts": { "v1": "node v1.js", "v2": "node v2.js" } I would like to use npm start v1 or npm start v2 for this purpose, however, these commands do not seem to trigger the intended Node command. ...

Link JSON filters to specific JSON nodes on the map

I have data representing nodes and links for a force directed graph. The links can have different numbers of connections between them, such as one, two, or three links: {"nodes": [{"id": "Michael Scott", "type": "boss"} ,{"id": "Jim Halpert", "t ...

Unlock real-time alerts with the power of JavaScript and PHP!

I am currently working on enhancing my skills in javascript. I have a basic idea of what I want to achieve. My goal is to create an automated javascript function that accesses a php page. This php page will create an array of new notifications for the ja ...

Obtain the content enclosed by HTML tags

Looking to extract text between html tags? Imagine having a list of cities in California, each within paragraph tags. Can you retrieve only the text inside the paragraph tags? <div class="cities"> <div><p>Los Angeles</p><h5 ...

There are no warnings or errors when running Yeoman grunt build, however, the dist folder that is generated is not functioning

When working on an Angular application, I typically run either grunt build or grunt serve:dist to generate my production files and deploy them to a remote server. Despite everything appearing fine with no warning messages in the Yeoman logs and yo doctor g ...

Validating an email address without the "@" symbol or if the "@" symbol is the last character

I've been working on validating email addresses using regex, but I'm encountering an issue. The problem is that the validation fails for emails that don't contain the "@" character or have it at the end of the word. For example, if I type "a ...