Guide on ensuring a website is fully loaded in Protractor

Currently, I am in the process of developing test scripts for a non-angular JS website using Protractor. Below is a snippet of my code:

var co = require('co');
var path = require('path');

describe("TEST", function () {

    it("test", co.wrap(function* () {
        browser.ignoreSynchronization = true;

        yield browser.get(URL, 60000);
        browser.sleep(5000);// I want to remove the sleep statements
        var elmOK = browser.driver.findElement(by.css('a[href="#login"]'));
        yield elmOK.click();
        expect(browser.getCurrentUrl()).toContain("login");
        yield browser.switchTo().frame('here-account-sdk').then(function () {
            browser.driver.findElement(by.id('sign-in-email')).sendKeys("uid");
            browser.driver.findElement(by.id('sign-in-password-encrypted')).sendKeys("password");
            browser.driver.findElement(by.xpath(' //*[@id="sign-in-form"]/div[2]/div[6]/form/fieldset[3]/button')).click();

        });
        browser.sleep(5000);// I want to remove the sleep statements
        var elmOK = browser.driver.findElement(by.xpath('//*[@id="lnav"]/li[3]/a'));
        yield elmOK.click();
        browser.sleep(1500);// I want to remove the sleep statements
        browser.driver.findElement(by.xpath('//*[@id="administration"]/div/div[1]/select/option[2]')).click();
        browser.sleep(5000);// I want to remove the sleep statements

        browser.driver.findElement(by.xpath('//*[@id="administration"]/div/div[2]/table/tbody/tr[1]/td[10]/span')).click();
        browser.sleep(5000);// I want to remove the sleep statements

        browser.driver.findElement(by.xpath('//*[@id="content"]/div/div[2]/div/div/div/div[3]/button[1]')).click();//Delete the file
        browser.sleep(5000);// I want to remove the sleep statements
    }));




});

Although adding sleep statements makes the test run as intended, I am looking to eliminate them from my code altogether. Despite consulting various Stack Overflow threads, I have yet to find a solution. :(

Initially, I tried

browser.manage().timeouts().implicitlyWait(5000);
, but there seemed to be no delay in loading my URL.

I also experimented with expected conditions, but unfortunately, that did not work either.

When I incorporated browser.wait(1000), my script failed. I would greatly appreciate any advice or guidance on this matter as I am feeling quite stuck.

Answer №1

It seems like the issue lies within this specific line of code:

browser.ignoreSynchronization = true;

According to information found on this Stack Overflow thread,

this setting causes Protractor to not wait for Angular promises, such as those from $http or $timeout, to resolve

Since Protractor element functions rely on promises, this could potentially be the source of your problem.

Additionally, the code structure appears to be a bit convoluted:

var elmOK = browser.driver.findElement(by.css('a[href="#login"]'));
yield elmOK.click();

A more straightforward approach would be:

element(by.css('a[href="#login"]')).click();

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

What is the best way to calculate the variance between the most recent and previous data points in an array in the span of an hour using JavaScript

Here is an array of objects I am working with: 0: {time: '2021-12-02T23:53:54.062Z', value: 558316} 1: {time: '2021-12-03T00:53:53.959Z', value: 558452} 2: {time: '2021-12-03T01:53:53.934Z', value: 558588} 3: {time: '2021 ...

Executing the constructor-defined method following the retrieval of a document from the database

UPDATE (AN ALTERNATIVE SOLUTION) Upon further exploration, I discovered that what I needed was the ability to make the method static so that it could be applied independently from the class. Let's consider the following constructor: export const Use ...

The error message states that the property "user" is not found in the type "Session & Partial<SessionData>"

I recently had a javascript code that I'm now attempting to convert into typescript route.get('/order', async(req,res) => { var sessionData = req.session; if(typeof sessionData.user === 'undefined') { ...

Struggling to reset the jscrollpane scroller

When using jscrollpane in my horizontal division to enable scrolling, I encounter an issue when loading data with ajax. The scrollbar doesn't appear until the browser width is changed. To address this, I currently utilize the following method to rein ...

Developing a website with multiple pages using Vue.js CLI allows for

I am struggling to understand how to implement multiple pages in a Vue CLI project. Currently, I have my home page set up with a few components, but I am unsure of how to create additional pages. Should I be creating multiple HTML files where the index.htm ...

Is there a way to prevent users from downloading PDFs or docs when they are opened in a new tab in a React application?

I recently encountered a situation where I needed PDF files to open in a new tab, but restrict the download for certain users. Despite trying out various third-party packages in React, none of them successfully rendered the PDF files as required. If poss ...

Execute JavaScript function when the page is being refreshed or accessed from an external link

On the Home page, we have a special Lottie animation that serves as a preloader. This animation should only display under certain conditions: Accessing the home page by clicking on a link from an external page (not on your website) Refreshing the brow ...

Using Javascript, it is possible to generate a new JSON object through manipulation of an already

I have a JSON object that I am manipulating to create a new JSON object. The challenge lies in dynamically constructing a part of the JSON object. Below is the original JSON object: [{"acptFlag":true,"count":14288,"limsFlag":true,"plantId":30,"plantName": ...

Basic math tool using JSP/Servlet combination and Ajax

I have a follow-up question to my previous inquiry on Stack Overflow. I believe this topic deserves its own discussion due to the thorough response I received. My goal is to develop a straightforward calculator using JSP. The calculator will include two t ...

The jquery function is not functioning properly within a javascript code block, however it performs perfectly when placed outside

In my php page, I have included jQuery and a script.js file. When I insert this function into my php file, it runs successfully: <script> $('#scoreboard-overview').load('getusers.php?q=<?php echo $NewString; ?>').fadeIn ...

Mobile devices experiencing issues in loading Javascript scripts

Let me start by sharing my JS code: function getTimeRemaining(endTimeInput) { var endTime = new Date(endTimeInput); var currentTime = new Date(); var t = endTime - currentTime; var seconds = Math.floor((t / 1000) % 60); var minutes = Math.floor((t / 100 ...

The transparency level of materials in THREE.js

When using the lambert shader, I encountered an issue with setting the material. In the example provided, it sets the material as follows: this.material.uniforms.emissive.value = new THREE.Color( Math.random(), Math.random(), Math.random()); Prior ...

Uncovering the hidden treasures of checkbox values using jQuery

I've encountered an issue with a form containing checkboxes. Some values are meant to be true by default, so I've hidden them using the following method: <input type=checkbox name="<%= _key %>" checked="checked" style="display:none" /& ...

I aim to retrieve the names of all directories

I am seeking assistance from seniors in creating a dropdown list of root directories using PHP. I have almost completed the task, but I am facing an issue with not being able to retrieve the root directory. For example, I want all directories like home/ab ...

What is the best way to store various types of functions within a single object key?

I have a dilemma where I am storing values and individual typed functions in an array of objects. Whenever I loop through the array, all the types of all typed functions in the array are required for any value. How can I make this more specific? Check it ...

Switching between sockets on a rotational basis

Imagine there is a division in the HTML file, and an interesting game is being played where each player has the opportunity to change the color. However, there’s a twist – they can only switch colors after the other player has taken their turn. The pla ...

JavaScript Function to Retrieve URL Parameter in PHPIn this tutorial

I'm currently working on an HTML5 game where each level has its own dedicated HTML page. The results of each level are saved in a JavaScript variable. My question is, how can I pass this information to the next page using the URL? I was considering ...

Using JavaScript, verify if a textbox is blank when utilizing the AJAX Control Toolkit's TextBoxWatermark feature

I am currently utilizing the AjaxControlToolkit's TextBoxWatermark feature with an asp.net TextBox to display placeholder text when the box is empty. However, I have encountered an issue where on the client click of a specific button, I need to check ...

What is the best method for inserting the HTML content from a specific div into a textarea?

Everything seems to be working fine, but once I insert the HTML into the textarea, an issue arises where the div gets wrapped within another div, causing the layout to break. var urls = []; $('body').on('click', '.btn_video&apos ...

I need help extracting an array name from a JavaScript array. I think it might be a syntax problem, but I am new to programming

In the process of developing a program where a video plays, featuring a person speaking along with chunks of text appearing in a div as the words are spoken alongside their translation. As part of this project, I'm working on writing a JavaScript func ...