Protractor Encounters Error When Assigning Variable

var itemStatus =  element(by.model('item.statusId')).getText();

This issue is causing Protractor to raise an error:

Uncaught exception: Error while waiting for Protractor to sync with the page: "Angular could not be found on the window" Process exited with error code 1.

I'm trying to understand why this throws an error, whereas this doesn't:

var itemStatus = element(by.model('item.statusId'))

Could it have something to do with promises? Maybe it can't execute .getText() until the element is located?

It seems like I need to grasp the fundamentals better.

In the updated version of the code:

var itemStatus = element(by.model('item.statusId'))
// var itemStatus =  element(by.model('item.statusId')).getText(); //was throwing with this

And then in the test case below, before commenting out the `.getText()`, I made sure not to run it within expect.

it('Should check item status, verify it is Checked Out.', function(){
    expect(itemStatus.getText()).toBe('Checked Out');
    //expect(itemStatus).toBe('Checked Out'); //this is how it was during error
}); 

And the corresponding HTML snippet:

<div class="form-control ng-binding ng-scope ng-isolate-scope ng-valid" ng-model="item.statusId" disabled="disabled">Checked In</div>

Even when all expect statements are commented out, the script would still throw an error when attempting to getText() for var itemStatus.

Apologies for forgetting to include the config:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['transfer_spec.js']  
}

Answer №1

It seems that the issue may be related to the scope in which the itemStatus variable is defined. If it's declared outside of the describe/it block, there could be a synchronization problem between protractor and angular. This occurs because when getText() is called, Protractor has not yet received the signal from Angular that it is ready. Make sure to declare your variables inside the describe/it block or within a Page Object:

var MyPage = function () {
    this.status = element(by.model('item.statusId'));
};
module.exports = new MyPage();

Example of how to use it:

var myPage = require("MyPage.js")

describe("My test", function () {
    it("Should verify that the item status is 'Checked Out'", function () {
         expect(myPage.status.getText()).toEqual("Checked Out");
    });
});

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

Ways to retrieve the mapState property within a method

Is there a way to access the count property within the method while working with vuex? Take a look at my code provided below: Screenshot of Code: https://i.stack.imgur.com/xNUHM.png Error Message [Vue warn]: Computed property "count" was assigned to bu ...

Make sure two elements are siblings in JavaScript / jQuery

Looking at the HTML structure below: <div class="wrap"> <div id="a"></div> <div id="b"></div> </div> A statement is presented as false: ($('#a').parent() == $('#b').parent()); //=> false ...

Pass an image into an input field with the attribute type="filename" using JavaScript directly

My goal is to automate the process of uploading images by passing files directly to an input type="filename" control element using JavaScript. This way, I can avoid manually clicking [browse] and searching for a file in the BROWSE FOR FILES dialog. The re ...

What could be causing the frontend to receive an empty object from the express server?

Struggling to understand how to execute this request and response interaction using JavaScript's fetch() along with an Express server. Here is the code for the server: var express = require('express'), stripeConnect = require('./r ...

Uncertain about troubleshooting the `uid: prismicDocument.uid ?? void 0` error on a Prismic and Next.js website?

Currently, I am working on a Next.js project integrated with the Prismic CMS. The website runs smoothly in my local environment, however, after some recent updates to the content, I encountered the following error during production builds: 2:42:19 PM: /opt ...

Navigating through angularjs is as simple as following these steps

My main directory folder is named angularjs and contains the following files: 1.index.html 2.main.html 3.blue.html 4.red.html 5.green.html I am trying to set up routing using AngularJs, but I am encountering an error. Can you help me figure out what I am ...

What techniques can be used to avoid blinking while forcefully scrolling to the left?

In my previous inquiry about dynamically adding and removing divs on scroll, I was unable to find a satisfactory solution among the responses provided. However, I decided to take matters into my own hands and attempted to implement it myself. My approach ...

Understanding the use of "el" in a function parameter in Vue Js

I am new to VueJS, so please be patient with me. I am trying to code a function that will scroll to an element with a specific ID when a "?" is used in the URL. I want it to have the same effect as demonstrated here. My assignment requires me to follow a ...

Ensure that each number is entered only once in the input field

Is there a way to use javascript/jquery to prevent a user from entering the same number twice in an input box? Users can enter multiple numbers one at a time, but I need to notify them or take action if they try to input the same number again. I attempted ...

What is the best way to convert a circular JSON object to a string

Is there a way to stringify a complex JSON object without encountering the "Converting circular structure to JSON" error? I also need its parser. I am facing issues every time I try to use JSON.stringify and encounter the "Converting circular structure to ...

Statement after post is not yielding any result

Below is a javascript function that I'm struggling with: function loginsubmit() { var url = "../php/loginsubmit.php"; var data = ""; ajaxRequest(url, "POST",data , true, insertNewBody); } This function is responsible for sending an ajax ...

Tips for using Python Selenium to execute browser shortcut commands

When attempting to utilize browser shortcuts with Python Selenium, I have been unable to successfully get any shortcuts to function. For instance, I have been trying to open a new tab (Control + T) using ActionChains(). I have attempted the following two ...

How does BullMQ stand out from other message queue implementations?

Recently, I've been exploring the documentation for BullMQ: https://github.com/taskforcesh/bullmq One thing that caught my eye in its comparison chart was the absence of projects like RabbitMQ or NATS Streaming. It seems that BullMQ is focused on ha ...

Show nested arrays in Vue.js exhibition

As a newcomer to vue, I've been navigating my way around with some success. Lately, I've been dealing with JSON data structured like this: [ { "name": "jack", "age": "twenty", "Colors&qu ...

Utilizing JavaScript to retrieve input names from arrays

This is the HTML form that I am currently working with: <form action="#" method="post"> <table> <tr> <td><label>Product:<label> <input type="text" /></td> <td><label>Price:<label> ...

Selenium error: Element is unclickable due to ElementClickInterceptedException

Although I have examined several similar questions that address the issue, such as Debugging "Element is not clickable at point" error , Selenium Webdriver - element not clickable error in firefox, ElementClickInterceptedException: Message: Eleme ...

Strange HTML antics

On my website, I encountered an issue when trying to register without entering any information into the required fields. The errors were correctly displayed in this screenshot: However, after inserting random characters into each field and attempting to r ...

Simulating a mobile device screen size using an embedded iframe

Imagine this scenario: What if instead of adjusting the browser window size to showcase a responsive web design, we could load the site into an IFRAME with the dimensions of a mobile screen. Could this concept actually work? Picture having an IFRAME like ...

Struggling to access Excel spreadsheet with POI library and Java for Selenium automation

Currently, I am working on a script that involves comparing two Excel files (exported as xlsx from a web application) at different intervals - once before an update and once after an update. These files have the same number of tabs with multiple columns, a ...

Is verifying email and password with jquery possible?

I am currently working on a jQuery form validation project: While the password and username validation are working fine, I am facing issues with email and password confirmation validations. Surprisingly, I have used the same technique for both. If you wa ...