Using a boolean as the return value instead of using success or failure in Protractor

I am currently working on a feature that involves determining whether a logged-in user is a customer of a specific company. In the interface, there is a div that displays the manager ID if the user logging in is a manager, otherwise it redirects them to the login screen. I need to implement conditional testing to check if the account ID belongs to a customer or a manager and take different actions based on the result. However, when the test fails, instead of returning a false result, it gets stuck waiting for an answer.

.then(browser.executeScript('return window.find("isCompany:true");')), 
.then(function () {
        return expect(browser.wait(EC.textToBePresentInElement(element(by.id("url")), qr), wait)).toBe(true);
    }, function () {
          ....
    });

Answer №1

section, it appears that resolving the promises returned by browser.wait() is necessary. This can be achieved by using the following code snippet:
browser.wait(EC.textToBePresentInElement(element(by.id("isCompany")), 'true'), wait).then(function () {
    // user is identified as a customer
}, function () {
    // user is not recognized as a customer
});

Answer №2

To simplify the process, consider creating a helper function that retrieves the value of

ExpectedConditions.textToBePresentInElement
. This approach eliminates the need to manage promise chaining. I personally utilize a utility class named Utils for achieving a similar goal. Here's an illustration:

Within the Utils class, include the following:

function waitForElementText(element, expectedText) {
    return browser.wait(this.ec.textToBePresentInElement(element, expectedText), this.timeout);
}

If you were to integrate this code snippet into your project, it would look like this:

util.waitForElementText(element, expectedText)
    .then(function (isCompany) {
        if(isCompany) {
           // perform desired action
        } else {
           // take alternate action
        }            
}

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

Which phase is affected by the stopPropagation method?

Quirksmode explains that modern browsers have a capturing phase as well as a bubbling phase, which you can read more about here. If I decide to implement stopPropagation in my event handler with a Boolean argument specifying the phase, how will it behave? ...

How can default props be set for a nested object in Vue?

Here's how I've defined my props: myHouse = { kitchen:{ sink: '' } } I attempted to set the default props like this, but it didn't work as expected. props: { house: { type: Object, default: () => { ...

What is the best method to retrieve the initial elements from an array before proceeding to fetch the subsequent ones?

I'm currently in the process of setting up my blog page on my website, and I have a posts folder containing markdown files for all my blogs. I'm trying to find a way to efficiently display these blogs on a single page by initially loading only th ...

Filtering multiple disordered words using Angular

Currently, I am facing an issue with filtering elements from a list in my code. My goal is to filter elements when entering multiple words at once, regardless of their order. At the moment, I can only filter elements if I input the words in the correct seq ...

Refreshing a div using JQuery/Ajax upon an update to a column in a database table

I am interested in checking for database column value changes and utilizing jQuery/Ajax to load a specific page into a designated div container. For example, let's say that on the main page, I have 1.php displayed within a div with the id "status." ...

What would you name this particular element?

I want to create a unique slider design but I'm unsure where to begin or how to search for information because I don't know the correct terminology. Does this type of slider have a specific name? I heard about Marquee, but that seems like someth ...

Looking to create an anchor tag that navigates to a specific ID on the page while accommodating a fixed header placement

In my application, the homepage's carousel displays multiple images with dynamically generated anchor tags that link to different routes. When clicking on the anchor tag, the page scrolls to the linked image but is obstructed by a fixed header. I want ...

Sending a component as a prop to another component

I want to pass a component with props as a prop to another component. Here is an example of what I am trying to achieve: const App = ({ routes, graphqlProvider, themeProvider }) => { const GraphqlProvider = graphqlProvider const ThemeProvider = the ...

I'm experiencing difficulties with updating my model while utilizing the ngResource module

Encountering a minor issue with Angular at the moment. Employing the $ngResource module to fetch "comments" from my server: var app = angular.module('app', ['ngResource']); app.factory('comment', function($resource) { r ...

Problem with Node.js Sequelize ORM model

Experiencing an issue with my web application using Sequelize, the Node.js ORM. When starting the Node server, I encounter the following error: Error: project_directory_path\node_modules\sequelize\lib\sequelize.js:322 model.init(attr ...

The Xrm.Navigation function has not been defined

When attempting to open a modal dialog box, I used the following code: var addParams = "entityid=" + Xrm.Page.data.entity.getId() + "&entityName=" + Xrm.Page.data.entity.getEntityName(); var webresourceurl = "/webresources/pdfflr_selectorpage.html?Dat ...

Reducing the amount of data transmitted through the network with socket.io

Hello there fellow developers :) I am currently working on a simple network game using node-js and socket.io. I have managed to reduce the amount of bytes being sent over the network by utilizing ArrayBuffers, which has been quite successful so far. Howev ...

When using Node.js with Firebase, information is not stored in the session

I've been attempting to implement session management in my application to keep track of user log-ins and other activities. However... Whenever I try the simplest way, I consistently encounter this error: Warning: connect.session() MemoryStore is ...

Issue with dynamic creation of menu in React Material UI where onClose function is unable to reference a variable inside the function

As I develop an app, I have chosen to dynamically construct the settings menu based on a JSON file. { categories: [ { name: "General", index: 1, items: [{ name: "Dark Mode", index: 1 ...

Encountered a syntax issue when attempting to modify state in React.js

I encountered a syntax error when trying to update the state in React.js with the following code. import { FETCH_POSTS } from '../actions/index'; const INITIAL_STATE = { all:[], post: null }; export default (state = INITIAL_STATE, action) => ...

Real estate listing featuring unique symbols

How do I include the ' character in properties when writing my object, like this: const championsList = { Kha'Zi: '...', }; Any suggestions on how to achieve this? ...

Oh no, there seems to be an issue with accessing the 'map' property in REACT JS. It appears to

Upon attempting to delete an item, I encountered an error message stating "cannot read notes, property of undefined". Despite this issue, the map function seems to be functioning as expected. It is my belief that there may be an error within the filter fun ...

Tips for transforming a string into an object using AngularJS

Here is a string I'm working with: $scope.text = '"{\"firstName\":\"John\",\"age\":454 }"'; I am trying to convert it into a JavaScript object: $scope.tmp = {"firstName":"John","age":454 }; Please note: J ...

The process of deep copying a Javascript object is not functioning properly within the Vue.js framework

When passing a clone of an object from a parent component to a child component using props, I encounter an issue where changing the value of the status property in the parent component's object also updates the value in the "cloned" object within the ...

Invoke functions within a separate function

I am facing an issue when it comes to invoking functions within another function. Below is a snippet of the code I am working with: <script> function saveInfo() { function returnEmail() { var _e = document.getElementById("em ...