What is the best way to compare two values using protractor?

How to Extract Values from Element

var projectOne = element.all(by.css('a[ng-click="setCurrentGroup(tab)"]')).get(6).getText().then(function(text){console.log(text);})

var projectTwo = element.all(by.css('a[ng-click="setCurrentGroupproject(tab)"]')).get(6).getText().then(function(text){console.log(text);})

After executing the above code, I get two values:

5,
6

Issue: I need to compare the two values and assert true if they are the same, otherwise assert false

Here is my attempt:

expect(values).not.toBeDefined(values)
expect(values).toEqual(values);
expect(values).not.toBe(values)

Any assistance on this matter would be greatly appreciated

Answer №1

Utilizing .then() chaining to obtain values separately is not necessary. The expect statement inherently resolves the promises returned by the methods. You simply need to incorporate them into your expect statement. Here is an example:

var saved_items_before = element.all(by.css('a[ng-click="setSelected(tab)"]')).get(4);    
var saved_items_before_1 = element.all(by.css('a[ng-click="setSelecteditem(tab)"]')).get(4);

expect(saved_items_before.getText()).toEqual(saved_items_before_1.getText()); //Verify equality of values

When the above expect statement is executed, it will pass if the values match. If not, it will generate an error in the following format-

Expected 10 to equal 12

Additionally, you can conduct tests for other conditions as needed, such as:

expect(saved_items_before.getText()).toBeDefined(); //Ensure value is defined and has a valid value
expect(saved_items_before_1.getText()).toBeDefined(); //Ensure value is defined and has a valid value

expect(saved_items_before.getText()).not.toEqual(saved_items_before_1.getText()); //Check for inequality of values. An error will be thrown if the values are equal in both type and content.

Hopefully, this information proves beneficial.

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

Issue with data synchronization in SAPUI5 custom control's two-way binding not resolved

As I work on creating a custom Control and binding data to it, I encounter an issue where upon clicking a button, the data in the Model is changed but not reflected in the DOM. Being new to SAP-UI5, I am struggling to identify the root cause of this proble ...

How to identify an element based on the text content of the element that follows it using XPath

I am working with this specific piece of HTML code <div class="a-expander-content a-spacing-base a-expander-inline-content a-expander-inner a-expander-content-expanded" style="" aria-expanded="true"> <form id="pp-yT-23" class="pmts-add-cr ...

Unleashing the Power of Dynamic JSON Data Access

I am facing an issue with my React Child component. Here is the code snippet: const SingleProject =(props)=>{ let data = projectData.VARIABLE_FROM_PROPS.projectDetails; let asideData = projectData.VARIABLE_FROM_PROPS.projectSideBar; useEffe ...

Innovative idea for a time management system based on timelines and scheduling

My latest project involves creating a scrollable scheduler, inspired by vis-timeline and built using Vue.js. One of the main challenges I'm facing is achieving smooth infinite scrolling in all directions (past and future). I must confess that I&apo ...

Can fetch be used to retrieve multiple sets of data at once?

Can fetch retrieve multiple data at once? In this scenario, I am fetching the value of 'inputDest' (email) and 'a' (name). My objective is to obtain both values and send them via email. const inputDest = document.querySelector('i ...

Incorporating a new textfield in Codeigniter through a button/link activation

Currently, I am working on designing a request form for my website. I am facing an issue with creating a button that can dynamically add new input fields when clicked. Unfortunately, I am unsure of how to resolve this problem. Picture this: [ button ] A ...

What is the best way to change the status of a disabled bootstrap toggle switch?

I'm working with a read-only bootstrap toggle that is meant to show the current state of a system (either enabled or disabled). The goal is for it to update every time the getCall() function is called. However, even though the console logs the correct ...

Encountering an issue where props are receiving a value of undefined within a component that is

After receiving a JSON response from getStaticProps, I double-checked the data by logging it in getStaticProps. The fetch functionality is working smoothly as I am successfully retrieving the expected response from the API. import Layout from '../comp ...

Merge the movements of sliding a block along with the cursor and refreshing a sprite displayed on the block

Confronted with the challenge of combining 2 animations, one to move the block behind the cursor inside the container and the other to update the sprite on the block. Let me elaborate further on my issue. The block should only move when the cursor is insi ...

JavaScript's functionality akin to PHP's exec() function

I am searching for a way to run a shell command through javascript, similar to the functionality of PHP's "exec()" function. I understand that executing shell commands in javascript may not be recommended due to security concerns. However, my javascri ...

I am looking to implement a sleep timer within a function in Python to automatically execute driver.close() for a Selenium script. How can I achieve this?

I'm dealing with a tricky selenium script that has an error response I need to avoid handling because it would mess up another selenium command in the script. To simplify things, I want to establish driver.close() at the start of the script and ensu ...

How can I design an avatar image within a button similar to Facebook's style?

I'm currently working on a project that involves adding an avatar and a dropdown menu for account settings to my navigation bar. I've already created the dropdown, but I'm having trouble styling the avatar within the button. The button is ta ...

Ways to confirm the tag of a web element once it has been retrieved using XPath

Currently, I am utilizing Selenium with Python along with Chrome driver. The situation at hand is as follows: On a webpage, I am extracting all elements that have either id==customer_info or class==prize_info by employing the subsequent code: customer_or ...

React does not always remove event listeners when using the useEffect hook's return callback

I have a functionality in my component where it initializes a key event listener. This event is supposed to trigger an API call to fetch random data. useEffect(() => { const keyUpEvent = (event) => { if (event.code === "Enter") { ...

Mastering the art of looping through JSON values using AngularJS ng-repeat

Is there a way to use ng-repeat in order to iterate and access the name values: test01, test02, and test03 from my JSON data? Any guidance on how to achieve this using ng-repeat would be greatly appreciated. Thanks in advance! Check out this Fiddle link. ...

Storage in Ionic and variable management

Hello, I'm struggling to assign the returned value from a promise to an external variable. Despite several attempts, I have not been successful. export class TestPage { test:any; constructor(private storage: Storage) { storage.get('t ...

react: implement custom context menu on videojs

Can someone assist me with adding a quality selector and disabling the right-click option in a webpage that uses videojs? I am unsure about using plugins, as there were no examples provided in react. Any guidance would be appreciated. VideoPlayer.js impor ...

Leveraging locators within Cucumber table elements

In my login Test, I conduct positive and negative scenarios using tables in cucumber. Scenario Outline: Login Given User navigates to Field And User enters a "<Username>" username And User enters a "<Password>" password When User clicks on th ...

Is it possible to create an array that organizes monthly income data from a JSON file?

I'm currently developing an Accounting System where I need to display a bar chart showing the monthly Incomes and Expenses. The data is retrieved from a database using AJAX, and it returns the following JSON: { "results":{ "his ...

The componentDidUpdate method is functioning by comparing the previous state with the current state on different triggers

I have a primary element that is invoking another element with specific attributes. // Primary Element <SecondaryElement className="EnterNumber-input" submitClicked={this.state.submitClicked} /> Upon clicking a button, I am modify ...