The setTimeout function does not seem to be triggering within Protractor when utilizing JavaScript

I have encountered an issue with a function I created that is meant to read a file after a delay of 2 minutes.

function checkInLogs(logFilPath, logMessage){

    setTimeout(() => {

        fs.readFile(logFilPath, 'utf8', function (err,data){
            console.log('I am inside the checkInLogs function')
         })

    }, 120000);

    console.log('outside the function');
}

The function is being called using the following code:

fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms25', '[Port:8090] successfully started');

However, I am facing an issue where the code inside the setTimeout is not being executed. The message 'outside the function' is displayed in the console but the inner code is not running. I tried another approach by modifying the function as follows:


function checkInLogs(logFilPath, logMessage){

    fs.exists(logFilPath, function(exists) {
        fs.readFile(logFilPath, 'utf8', function (err,data){
            console.log(data.toString());
            console.log(err.toString());
         })

    })



}

and calling it like:

setTimeout(function() {
            fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms21', '[Port:8090] successfully started')
        }, 120000);

Unfortunately, despite trying different approaches, the code inside the setTimeout is still not executing. Any suggestions or solutions would be greatly appreciated.

Answer №1

To successfully execute the test, make sure to instruct it to wait initially without using setTimeout function. Assuming that the timeouts are appropriately set in your protractor.conf file, this method should work as intended.

it('waits for two minutes', async ()=>{
  await browser.sleep(120000);

  // Check if specific log is present
  fileUtil.checkInLogs('D:/Installation/V114_new/be/5.6/rms/bin/logs/CCARms21', '[Port:8090] successfully started');
})

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

GraphQL query must receive an object for the Mongo filter, but instead, it received a string

Is there a way to pass a filter option to MongoDB using GraphQL? I attempted to do it in a certain way, but encountered an error that stated: "message": "Parameter \"filter\" to find() must be an object, got {email: "<a href="/cdn-cgi/l/email ...

Creating a JavaScript library

Looking to develop a JavaScript library and manage it in the following manner: var c1 = Module.Class(); c1.init(); var c2 = Module.Class(); c2.init(); It's crucial that c1 and c2 do not share the same variables. My initial thought is to use objects: ...

What could possibly be the reason for the malfunctioning light in this particular setting?

Recently, I developed a game class using Coffeescript that showcases both a static and rotating cube. If you are interested in checking out the code, you can find it here: http://jsfiddle.net/6eRzt/6/ Despite everything working smoothly, there are two iss ...

Eliminate unnecessary repetition of code in JavaScript

Is it possible to avoid repeating the same code in JavaScript and instead write it once but still use it multiple times? I tried using a class, but it didn't work as expected. Here is the HTML: <img id="Image" src="1.jpg" alt="1" style="width:50% ...

Exporting modules in Node.js allows you to use functions

Can you explain why this code snippet is successful: exports.foo = 'foo'; var bar = require('./foo'); console.log(bar); // {foo: 'foo'} While this one fails to produce the desired output: var data = { foo: 'foo' ...

Is there a way to obtain the current time upon clicking the timepicker?

Here is a snippet of my code: // TIME $('#timepicker').datetimepicker({ minDate: minTime, }) .on('dp.show', function(e){ console.log(selectedDate); if($(this).val()==""){ $(this).val(minTime.format("HH:mm") ...

Is there a method to place two items in a flex container while only centering one of them?

I managed to achieve the desired effect using absolute positioning, but I know this is not the most elegant solution and it lacks re-usability. Is there a way for me to group these two elements in a flex container and center only the text? Also, I'm f ...

Utilizing conditional formatting to set background colors in an HTML table

Our manufacturing company collects and documents data for the parts we produce. Currently, this information is logged on a spreadsheet with drawing dimensions in one column and actual measured values in another. The cell where the actual measured value i ...

Transform gregorian calendar dates into persian (jalali) dates within an Angular 2 and Ionic 2 project

I've come across a package on npm that can convert gregorian date to persian (jalali), but I'm unsure of how to implement it in my ionic 2 angular 2 projects. Jalali-date Alternatively, there's a package for angular 1: ADM-dateTimePic ...

What is the best way to create a React filter utilizing the Autocomplete component from MaterialUI and incorporating state management?

I am currently in the process of creating a filter using the Autocomplete component from MaterialUI. As I select options from the dropdown menu, several things are happening: The Autocomplete automatically adds the selected options to the Chip Array. The ...

Discover the best method for retrieving or accessing data from an array using Angular

In my data processing task, I have two sets of information. The first set serves as the header data, providing the names of the columns to be displayed. The second set is the actual data source itself. My challenge lies in selecting only the data from th ...

Having trouble connecting DB and D3 using PHP. Struggling to follow D3noob's tutorial to completion

First and foremost, I want to express my gratitude to the amazing community here for all that I have learned. However, I'm currently facing some difficulties in finding the solution I need. I've encountered issues while trying to follow the inst ...

What is the simplest method for fetching and parsing JSON data with jQuery and JavaScript?

I'm having trouble making this code snippet work. I can't seem to figure it out. The objective is to retrieve and parse a JSON object in the simplest and easiest way possible. Here's the code snippet. <!DOCTYPE html> <html> &l ...

Generating landscapes with longitude and latitude coordinates in three.js

Is there a way to transform a cube geometry into a terrain based on latitude and longitude data? I have an array of objects with latitude, longitude, and deformation values for specific coordinates. var geo = new THREE.CubeGeometry( 10, 20, 40, 40, worldW ...

Can you explain how the Facebook Like button code functions and how I can create a similar feature on my own platform?

I have a website with 250 different items, each containing its own Like button using the standard Facebook "Like" code: div class="fb-like" data-href="http://www.mywebpage.com/myproductpage" data-send="false" data-layout="button_count" data-width="80" dat ...

Different ways of manipulating images with JavaScript

I attempted to tackle the issue independently, but I'm stumped. Is there a way to adjust the width of an image in JS when the screen dimensions are changed? ...

Ways to accomplish a task prior to form submission without relying on preventDefault

How can I perform an action before form submission without using e.preventDefault();? I am faced with a situation where I have two form buttons and need to set a hidden field value before submitting the form. In my Symfony2 framework, when I submit the fo ...

jquery mobile page navigation option

I am a big fan of the navigation system in jQuery Mobile: <a href="page-transitions-page.html" data-transition="slidedown" class="ui-btn ui-corner-all ui-shadow ui-btn-inline">page</a> () It is incredibly user-friendly, and I really enjoy th ...

Exploring ways to eliminate an item from a dropdown list within an array using Vue JS

I am currently utilizing an array named 'itemsCart' in my data() and presenting this array within a dropdown list. I have implemented a button to remove items from the array, but I am unsure of how to proceed. Below is my code snippet: <Breeze ...

What are the steps to reset the default global path for npm on an Ubuntu system?

After altering the default global path for the node-sass package, I noticed that other globally installed packages are not working as expected. Any suggestions on how to resolve this issue? ...