What is the process for testing an Angular multi-select dropdown using Protractor?

Currently, I am utilizing the angular-multi-select dropdown feature available at https://github.com/isteven/angular-multi-select. My next step involves writing test cases in Protractor for this specific functionality.

<div ng-show="!attribute.isMultivalued && page != 'view'" 
     class="select-group" 
     multi-select 
     input-model="typesDataDup"
     output-model="attribute.types"
     button-label="typeName"         
     item-label="typeName" 
     tick-property="ticked" 
     selection-mode="single"
     helper-elements="filter"
     is-disabled = "page == 'view'">
</div>

An issue I'm facing is the inability to send data using the model because the ng-model tag is not specified. Any guidance on how to write a test case for this scenario would be greatly appreciated.

Answer №1

To locate the element, you have the option to utilize alternative attributes and employ by.css. For instance:

element(by.css('div.select-group'))

or

element(by.css('div[multi-select]'))

Based on my examination of the angular-multi-select source code, the select options are denoted by button elements. To locate and interact with these buttons, use element.all() to find all buttons within and select the desired one, such as Select All:

element.all(by.css('div[multi-select] button')).then(function(options) {
    options.forEach(function(option) {
        option.getText().then(function(text) {
            if (text.indexOf("Select All") != -1) {
                option.click();
            } 
        });
    });
});

Answer №2

When trying to solve this issue, I sought help from CSS. By inspecting the element in the browser's developer tools, I was able to find the necessary solution.

element.all(by.buttonText('None selected')).then(function(items) {
   items[1].click();
}); 
element.all(by.model('inputLabel.labelFilter')).then(function(items) {
   items[1].sendKeys(protractor.Key.DOWN+protractor.Key.DOWN);
});
ptor.sleep(200);
element.all(by.css('.multiSelectFocus')).then(function(items) {
   items[0].click();
});

In this code snippet, I am utilizing the DOWN key to select a specific option.

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

Discovering the oldest date in an array with JavaScript

Is there a way to identify the earliest date, also known as the minimum date, within an array using JavaScript? For instance: ["10-Jan-2013", "12-Dec-2013", "1-Sep-2013", "15-Sep-2013"] The desired output would be: ...

Initiate a function once the innerHTML content in Angular has been completely loaded

I'm curious to know if it's possible in Angular to receive a notification when the Inner HTML has finished loading. I have a web application that retrieves an SVG image from a server and I need to display it as innerHTML in order to interact with ...

Looking to retrieve the value of an input element within an ng-select in Angular 6?

Currently, I am working on a project where I aim to develop a customized feature in ng-select. This feature will enable the text entered in ng-select to be appended to the binding item and included as part of the multiselect function. If you want to see a ...

Ways to guarantee that a function is executed only once within an object notation

Although there are numerous techniques available on Stack Overflow to ensure a function is only called once, none of them seem to fit my specific scenario and objectives. In this case, the function is nested within an object literal, and I aim to either ad ...

After the page has finished loading, I aim to have the modal window pop up after 10 seconds. Thank you to all!

$(document).ready(function() { var id = "#dialog"; //Calculate screen dimensions var maskHeight = $(document).height(); var maskWidth = $(window).width(); //Adjust mask to cover entire screen $('#mask').css({'wid ...

When utilizing drag and drop in HTML5, the items.webkitGetAsEntry() method is not available

Hey there, I am attempting to drag and drop files into my file system using Chrome, but I encountered the following error in the console: var dnd = new DnDFileController('body', function(files, e) { var items = e.dataTransfer.items; for ...

"Upon submitting a post request on my Heroku express app, an unexpected application error

Just deployed my app on heroku for the first time. Everything runs smoothly with GET requests, but encountering an application error when attempting to make a POST request with a body. After checking the logs on heroku, it appears that there is an issue w ...

having difficulty preserving the edited HTML document with JSoup and Java

I am facing an issue with modifying and saving changes to an existing HTML file. I can make modifications, but when it comes to saving the changes back to the HTML file, I encounter difficulties. https://i.sstatic.net/CRhUV.jpg The specific modification ...

Tips on sending JSON string from Controller action to View and utilizing it as a parameter for a JQuery function

$(document).ready(function () { function initializeMap(data) { var map; alert(data); map = new L.Map('map', { zoom: 8, layers: [OSM] }); var array = $.parseJSON(data); alert( ...

Converting a jQuery DOM element into a string representation

Currently, I am working with a textarea that contains the contents of an HTML file. This textarea includes all elements of my HTML page such as doctype, head, html, etc. My goal is to save the content of the textarea into a DOM variable using $.parseHTML: ...

Using jQuery to retrieve the initial object in an array following an Ajax request

I need to retrieve the first object returned by an AJAX call before looping through it with the each() function. Here's the current code that successfully loops through the data: $.each(obj.DATA, function(indexInArray, value) { var depts ...

Activate function when list item is clicked

My goal is to execute a function when users click on the li elements in the snippet below without relying solely on onclick. For instance, clicking on the first li element (with a value of 1) should trigger a function where the value "1" is passed as an ar ...

Javascript - Issue with Ajax causing additional commas in JSON responses

I'm attempting to send a request to a RESTful server using the HTTP module in Node.js. Due to the large response size (64 chunks, approximately 100kb), the HTTP module combines the chunks into a single string response like this: res.setEncoding(& ...

Tips for using Cypress to confirm that an HTML element's height or width exceeds a specific value

This thread on Github demonstrates the method for using Cypress to verify that an element has a specific height. cy.get(mainMenu).should('have.css', 'height', '55px') How can I utilize Cypress to confirm that an element exce ...

Guide for serving multiple SVG files to a browser using Node.js

First time delving into Node and server-side code, working on retrieving multiple svg files from the server. Check out my client-side code using jQuery: $.ajax({ url: someURL, data: someData }) .done(function(data) { console.log('data received ...

The JSON array retrieved from the $http.GET request is coming back as undefined, which is not expected

Presenting my code below: function gatherDataForGraph(unit, startTs, endTs, startState, endState){ points = []; console.log('/file/tsDataPoints/'+unit+"?startDate="+startTs+"&endDate="+endTs+"&startState="+startState+"&endState="+en ...

Self-reference within a JavaScript object involves creating a property that points

Can you reference another part of a JSON object within the same JSON object? In the code snippet below, there is an object that refers to the "home" object within the "MapParameters" object. { "parameters": { "data": { "URL": "http://SC.json ...

Show User Input as a dynamic tool-tip in Highcharts

Is it possible to gather 12 user inputs through multiple text areas in a popup dialog box, and then use these inputs as tooltips for various points on a graph like the one shown in this demo: http://www.highcharts.com/demo/line-labels? I haven't found ...

Displaying PDF files on the internet without allowing them to be downloaded

How can I display PDF files on my website without allowing them to be saved or downloaded? Is there a way to prevent browsers from saving or downloading the PDF files? ...

Serializing ASP.NET WebApi's DateTimeOffset to Json/JavaScript in Angular2

Struggling to properly handle a DateTimeOffset value for JavaScript (specifically angular2). RecordModifiedAt : "2016-03-08T17:27:11.9975483+01:00" Unfortunately, JavaScript/angular2 doesn't seem to recognize this as a valid datetime value. I have ...