Protractor's use of dynamic variables

Do you find it challenging to utilize global variables in ptor? Using the "window" prefix doesn't seem to be effective.

element(by.id("priceNet")).getText().then(function (getNet) {
        net = getNet;
    });
element(by.id("priceVat")).getText().then(function (getVat) {
        vat = getVat;
    });
console.log(vat + " " + net);
expect(element(by.id("priceTotal")).getText()).toContain(net + vat);

Is there a way to enable window.net usage in ptor so that vat and net can be utilized in the expect method?

Answer №1

Issue resolved with this effective solution. Just need to ensure proper parsing to either Integer or Float.

        element(by.id("priceNet")).getText().then( function (getNet) {
            element(by.id("priceVat")).getText().then( function (getVat) {
            expect(element(by.id("priceTotal")).getText()).toContain(getNet + getVat);   
        })
    });

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

Trouble with Mongoose's findByIdAndUpdate function persisting even with {new: true} parameter added

I attempted to modify and update the information, but encountered an issue with mongoose findByIdAndUpdate. Even though {new: true} is included, it continues to display the original data. The database does not reflect any updates as well. The console outpu ...

Is it possible to close a MongoDB connection using a different method other than the one mentioned in this function?

I am facing a challenge with uploading a substantial data set from my node.js application to a mongodb. The process involves running a for loop to fetch each result. Initially, I established the connection to the MongoDB within every iteration of the loop, ...

applying a timeout for the .on(load) event

My goal is to dynamically load images using .on('load') in the script below: .on('load', function() { if (!this.complete || typeof this.naturalWidth == "undefined" || this.naturalWidth == 0) { alert('broken i ...

Activation code for the "Delete" key prompts the browser's return function - jQuery

I'm currently working on creating a digital keyboard that associates images with keycodes and adds them as spans after a keydown event. However, I have run into an issue with the DELETE feature. if (e.keyCode == 8) { $('span:last').remo ...

Expanding the size of an array list item in React

I have an array containing various currencies: const currencies =['USD','EUR','AUD','CNY','AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS', 'A ...

When the browser's back button is clicked, no action occurs with Next/router

I am confused about why my page does not reload when I use the browser's back button. On my website, I have a catalog component located inside /pages/index.js as the home page. There is also a dynamic route that allows users to navigate to specific p ...

Switch Places Once the Video is Complete

Is there a way to make a video play automatically and then redirect to another page once it's finished, without any user interaction? <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transition ...

Change the color of the line segment connecting two points on a line

In my three.js project, I am working on drawing a line based on an array of vertices. One challenge I am facing is setting the color of the line to a specific value between two points along the line that are not actual vertices. These two points exist at a ...

Is there a way to remove any incomplete information from the output (window.alert) in JavaScript when a user does not fill in all the prompts?

I am seeking input for 8 pieces of information to be displayed in an alert box, only if the user enters something in each field. All the gathered data will be shown in a single alert box once the user confirms their desire to review it. If the user choos ...

Creating a dynamic field using Apollo GraphQL

Hey there, I've encountered an issue and despite my efforts to search for a solution, I couldn't find one. The problem at hand is creating a dynamic field in my GraphQL Type where the value depends on other fields. Essentially, if any of the oth ...

How do I utilize Protractor to target a specific div element with a distinctive class and verify its visibility on the page?

Below is the view.html for a unique class: <div class="appExperience small-tile"> </div> This is the code snippet that I attempted to use: var displayedTile = element(by.css('.appExperience small-tile')); expect(displayedTile.i ...

Using tabs within a textarea element in Typescript/Angular

I am struggling to find a solution for the issue I'm experiencing with tabs inside a textarea. Every time I press the tab button, it jumps to another textarea. I have found some solutions written in JavaScript and jQuery, but unfortunately, I can&apos ...

Developing a search feature using Ajax in the MVC 6 framework

Embarking on a new project, I have chosen c# .net 6 MVC in VS2022... In my previous projects, this code has run flawlessly. @section Scripts { <script type="text/javascript"> $("#Klijent_Name").autocomplete({ ...

Encountering an issue with googleapis in Vue.js: Error - The argument labeled as "original" must be of type Function

Attempting to retrieve rows from a Google Spreadsheet using googleapis for a Vue project. I have set up the necessary project and service account credentials in the Google console. However, upon clicking the button, I encounter this error: TypeError: The " ...

Can you access the Erlang shell using your web browser?

I need a solution for accessing my Erlang app from a web browser instead of the command line. This is important because the app will be used by administrators who may not be comfortable with terminal commands. I want them to be able to easily inspect the s ...

What is the best way to access a child element using getElementsByClassName?

I am struggling with a basic JavaScript script to select a child element using getElementsByClassName, but it does not seem to be working as expected: var parent = document.getElementsByClassName('parent'); var child = parent.getElementsByClassN ...

Vue's v-for directive is resulting in surprising extra elements being generated

Currently, I'm in the process of utilizing Nuxt Content to build a blog section for my website. After setting up the directory structure and testing some posts, I proceeded to create a query that fetches the posts and stores them as a ref for page usa ...

Transforming hierarchical data into a flat table view using AngularJS by iterating through the structure

I'm grappling with creating valid tabular markup using AngularJS and struggling to find a solution. While I've come across similar inquiries, none seem to cater specifically to my requirements. My race result data is organized in the following s ...

Attach the keyboard to the screen in a fixed position

How can I keep the keyboard always visible on the screen? The screen contains: one TextInput (multiline) two FlatList Typing in the TextInput is fine, but when interacting with the FlatList, the keyboard disappears. I want the keyboard to remain visib ...

Utilizing JavaScript to redirect post google map location insertion into SQL database

Recently, I've started experimenting with javascript (only two days in!) and one of the features I'm trying to implement on my website is enabling users to add markers to a Google Map. After delving into the Google Maps API for the past couple of ...