Steps for executing the function in the specifications - Protractor

My script is written within the following module:

   var customSearch = function () {

this.clickSearch = function (value) {
    element(by.id('searchbutton')).click();
};


this.waitElementFound = function (value) {
    var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceof(value), 35000);
};

};
module.exports = new customSearch();

In order to call this function in my spec file, I have included the following code:

var searchFunction =  require('customSearch');
var inputText = element(by.id('text'));

it('waits for the element', function(){
  searchFunction.waitElementFound(inputText);
  searchFunction.clickSearch();
});

Upon running the test, I encountered an error stating 'undefined function'. I am unsure of what the issue might be. Any assistance would be appreciated. Thank you.

Answer №1

If you want to use functions from one file in another, the best way to do so is to export the function and then require it in the other file. Here's an illustration -

File test.js

var search =  require('./helper.js');
var loadtxt = element(by.id('text'));

it('waits for the element', function(){
    search.waitElementFound(loadtxt);
});

File helper.js

var waitElementFound = function (value) {
    var EC = protractor.ExpectedConditions;
    browser.wait(EC.visibilityOf(value), 35000);
};

module.exports = new waitElementFound(); //export the function

I trust this explanation is beneficial to you.

Answer №2

After some trial and error, I figured it out - simply needed to declare my variables outside the function in the var x = function.. The struggles of a beginner :) Appreciate the help, @Girish Sotur!

Answer №3

   var initiateSearch = function () {

this.searchClick = function (value) {
    element(by.id('searchbutton')).click();
};


this.waitForElement = function (value) {
    var EC = protractor.ExpectedConditions;
    browser.wait(EC.presenceof(value), 35000);
};

};
module.exports = new initiateSearch();

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

Error message indicating that a selenium script has encountered an invalid argument

I am facing a task where I have to open around 3000 URLs from a file, one by one in a browser tab and simply click on each page that is loaded. The objective is for the page to redirect to a different URL upon clicking it. Even though I have written code ...

extract information from a document and store it in an array

As I delve into the realm of programming, I find myself grappling with the best approach to extract data from a file and store it in an array. My ultimate aim is to establish a dictionary for a game that can verify words provided by players. Despite my no ...

I am encountering an issue with my code where the function this.ProductDataService.getAllProducts is not recognized when

Encountering an issue while running unit test cases with jasmine-karma in Angular 7. The error received is: ProjectManagementComponent should use the ProjectList from the service TypeError: this.ProjectManagementService.getProject is not a function If I ...

Discover the best way to retrieve attribute values using jQuery

I'm struggling to retrieve the value of the attribute "_last_val" from my input, but I'm having trouble getting it. Here is what I have attempted: demo // Here is the HTML code <form method="post" action="" id="feedback_form"> <inpu ...

You are unable to establish headers once they have already been sent to the client, as indicated by the error

Github : https://github.com/UJJWAL2001/Pro-Shop/tree/main/backend My current objective is to implement JWT token for securing my routes using the middleware provided below import jwt from 'jsonwebtoken' import User from '../models/userModel ...

Sending messages on Discord.js at one-minute intervals

Hey there, I'm currently facing an issue while trying to automate a message sending process on Discord. The specific error that keeps popping up is: bot.sendMessage is not a function I'm puzzled as to why this error occurs, so I've include ...

What could be the reason for the container div's height not being properly refreshed?

When adding elements to a container div with an initial height of 'auto', I assumed that the height would adjust based on the children elements added. However, this is not happening. Can anyone assist me in ensuring that the container div's ...

Disregard any unrecognized variables associated with the third-party package

I've been working on integrating the bluesnap payment gateway into a react/ts project. I added their hosted javascript code to my public/index.html and started the integration within a component. However, when compiling, an error pops up saying ' ...

Querying the database to check for the presence of a file in a .js file on Google App Engine

I'm currently working on implementing an upload button for users to upload files to our storage system using Google App Engine with Python, as well as HTML and JavaScript for the views. To achieve this, we have an HTML file and a.js script that promp ...

Is it possible to submit a HTML5 form and have it displayed again on the same page?

Is it possible to simply reload the sidebar of a page containing an HTML5 form upon submission, or is it necessary to load a duplicate page with only the sidebar changed? I am unsure of how to tackle this situation; firstly, if it is achievable in this m ...

Having trouble with protractor's sendKeys function when trying to interact with md-contact-chips

Does anyone know how to set a value using sendKeys in Protractor for md-contact-chips? I attempted to use element(by.model('skills')).sendKeys('Java'); but it doesn't seem to be working. Any suggestions on how to approach this in ...

Troubleshooting Problems with Deploying Next Js on Firebase

I am currently working on a new Next Js application and have successfully deployed it on Vercel by linking the GitLab project. Now, I need to deploy the same project on Firebase. Here's what I have tried so far: - Ran firebase init This command gen ...

Steps to display the datatable footer on the printed page

I am having trouble understanding the solutions provided for my table query. The current table setup is as follows: <table class="table table-bordered make_datatable"> <thead> <tr> <th>SL No</th> ...

Merge arrays to form nested structures

Here's a mind-bending scenario for you. Imagine I have two arrays - one containing categories and the other containing arrays that follow the structure of those categories. For example: var categoryArray = ["Name", "Title", "Hire Date"]; var infoArr ...

Issues with border/padding and overlay in Packery Grid Layout

After spending some time working on a grid layout using the metafizzy isotope packery mode, I have encountered a few issues. To illustrate my problem, I have provided a link to a codepen below: http://codepen.io/anon/pen/EgKdpL Although I am satisfied wi ...

using an array as an argument in the filtering function

Is there a way to pass an array to the filter method in JavaScript? I have successfully filtered an array using another array. However, my filter array currently has a global scope. How can I pass the array to make my code cleaner? var array = [1, 2, 3, ...

ERROR: Expo TaskManager Notifications [TypeError: Attempting to call an undefined function (near '...Notifications.presentLocalNotificationAsync...')]

I'm currently trying to figure out how to send notifications whenever a task is triggered, but I keep encountering an error that I can't seem to fix. Here's the error message: TaskManager: Task "background-fetch" failed:, [TypeError: unde ...

Retrieving results from PostgreSQL database using pagination technique

When I'm pagination querying my data from a PostgreSQL database, each request involves fetching the data in this manner: let lastNArticles: Article[] = await Article.findAll({ limit: +req.body.count * +req.body.page, or ...

The majority of the sliding banner is crafted using 90% HTML and CSS3, with just a touch

I devised a clever script to smoothly slide an image back and forth across the screen using CSS3. Unfortunately, I encountered a problem with CSS animations - they do not support changing the background-image directly. Attempting to overcome this limitatio ...

Redirect middleware for Next.js

I am currently working on implementing a log-in/log-out feature in my project using nextjs, redux-saga, and mui libraries. // middleware.ts import { NextRequest, NextResponse } from 'next/server'; import { RequestCookies } from 'next/dist/c ...