Can config values be dynamically set from an Excel file in Protractor?

I am currently working on parameterizing capabilities using an Excel sheet. For this task, I am utilizing the npm exceljs package for both reading and writing data. Below is a snippet of the code that demonstrates how I am trying to achieve this:

//This function reads values from the Excel sheet

    this.getValueFromExcel = function getValueFromExcel(cellAddress) {
      return  workbook.xlsx.readFile('data.xlsx').then(function () {
            var worksheet = workbook.getWorksheet(sheetName);
            var excelData = worksheet.getCell(cellAddress).value.toString();
            console.log(excelData);
            return excelData;
        })
    }

var browserValue = this.getvalueFromExcel(cellAddress);

//If the browser value is Chrome, then execute this configuration
var Chrome = {    
     browserName: 'chrome',
    'chromeOptions': {
        'args': ["--disable-infobars"]
    }  
};

//Using the browservalue here in capabilities
exports.config = {

capabilities: browserValue,

}

I seem to be facing an issue where I'm receiving an error despite successfully fetching data from the Excel sheet. The error message states: '[15:53:43] E/launcher - Error: TypeError: Target browser must be a string, but i s ; did you forget to call forBrowser()?'

I am unsure whether what I am attempting is feasible or if there is something I am missing.

Previously, I have referred to the following links for guidance: Parametrize protractor-config file and How can I use command line arguments in Angularjs Protractor?

Answer №1

Just to reiterate what was mentioned earlier, the issue lies in passing a string instead of a variable name into the capabilities option. The statement browservalue = Chrome works because it correctly uses the variable name. It's an important distinction to keep in mind.

Nevertheless, there is a workaround for achieving your desired outcome.

Consider the following approach:

var browserValue = this.retrieveDataFromExcel(cellAddress);

var Chrome = {    
     browserName: 'chrome',
    'chromeOptions': {
        'args': ["--disable-infobars"]
    }  
};

exports.config = {  
    capabilities: eval(browserValue),    
}

By utilizing eval(), the provided string will be interpreted as code, effectively evaluating the string "Chrome" as the variable name.

It's crucial to exercise caution when using eval() since it can execute any code provided as a string, potentially posing security risks. Nonetheless, in this scenario, it seems like the most suitable solution.

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

Translate the DateTime to the local time zone

As a newcomer to AngularJS, I am working on capturing a DateTime attribute in the UI and passing it to an Odata endpoint. However, the time being sent is not in the current local time. How can I convert this time to local time before sending it to the Odat ...

What steps can be taken to address issues with the counting system in a lootbox opening

I am currently developing a virtual loot box simulator and have encountered a challenging issue. My goal is to track the quantity of Normals, Legendaries, Epics, and Rares obtained by the user. However, I am facing a problem where instead of updating the c ...

Using a variable to replace the filter expression in AngularJS

I am facing an issue with a table object where I need to filter out a specific "index" row using the filter function. The code snippet below demonstrates my attempt, but unfortunately, $controller.expression is not functioning correctly. IF `$controller.e ...

Revamping the ejs template using an AJAX call

In my web app, users can search for recipes based on specific ingredients using the Edamam API. I implemented pagination to allow users to load more recipes when they click the "Load more" button, as Edamam only returns 20 recipes at a time. Here's ho ...

Generating a fresh object from an existing object by incorporating updated values using Angular and Ionic version 3

Currently, I am actively working on an Ionic 3 project that utilizes Angular framework. Within my project, I have a JSON object called 'person' which consists of data fields such as name, job, and home. One feature in my app is an Ionic toggle b ...

Updating dropdown selection with JavaScript

I have a dropdown select menu with two options. I am using JavaScript to retrieve the selected value from the drop-down menu and display it in a text area. Here is my code: $(document).ready(function () { $('#pdSev').change(function () { ...

What is the best way to invoke a controller function from within a directive's link function using '&' and passing a parameter?

Trying to pass a parameter into a function within a directive link function has been a bit challenging. I've come across questions and examples like this one on Stack Overflow, as well as blog posts such as What IBroke. While I've seen paramete ...

What steps should I follow to create a Lunr search functionality for Markdown MD files?

Currently, I am in search of a suitable lunr search implementation for my MD (Markdown) documents spread throughout my React/NextJS website. Our website contains a plethora of Markdown docs within both blog and regular "docs" sections, necessitating a robu ...

What is the purpose of running npm i react-{...}?

While going through a tutorial, I came across the following syntax. Can you explain what it means to install both react-router and react-redux? npm i react-{router,redux} ...

Override existing Keywords (change false to true)

Are there any ways to overwrite reserved words? It's not something I would typically consider, but it has sparked my curiosity. Is it feasible to set false = true in JavaScript? I've come across instances on different websites where individuals ...

The functionality of Angular bootstrap scrollspy is hindered when dealing with dynamically changing image content

I recently came across an answer that guided me to fork an example for implementing scrollspy in Angular.js. My goal is to populate dynamic content using a template that includes images. You can find the example here: http://plnkr.co/edit/OKrzSr Here are ...

What is the process for triggering an unordered list when I click on a table data cell within the Hospitals category?

Hi there! I need help with writing a JavaScript function for Hospitals in the code below. When I click on Hospitals, I want to display the values in the unordered list. Expected output: Hospitals--->onclick Bangalore| salem |Goa| Mangalore| Visakhapat ...

Utilizing data as a substitute when creating a SearchBar using Vue3

My VueJs3 application has a search bar implemented using .filter(), and it seems to be working fine. However, when I try to pass the value from my methods to the template, an error occurs. My data becomes a proxy and I am unable to use it in that format. ...

Incorporating images into CSS using an npm package

My npm package has the following structure: --src --styles -image.png -style.scss In the style.scss file, the image is referenced like this: .test { background-image: url(./image.png); } The issue arises when consuming the package, as th ...

What is the best way to switch between components when clicking on them? (The component displayed should update to the most recently clicked one

I am facing a challenge in rendering different components based on the navbar text that is clicked. Each onclick event should trigger the display of a specific component, replacing the current one. I have 5 elements with onclick events and would like to re ...

Unable to save the current light/dark mode preference to local storage

Being a beginner in JavaScript, I am currently working on implementing a simple light mode button for my website which defaults to dark mode. The transition between JS/CSS dark and light modes is seamless, giving the site an appealing look when switching t ...

Utilize the key-value pair from ng-repeat to expand the scope of the expression

In an attempt to utilize the key value from ng-repeat as an extension of another scope.arrayResult, I aim to achieve arrayResult.q1/q2/q3 etc... <ul ng-repeat="(key,x) in data"> <li><h4>Question: {{x}}</h4> <p>{{ ar ...

Is Javascript necessary for submitting a form to a PHP script?

In my current project, I am working on a page to edit information in a database. While I know how to create the form in HTML and the PHP script that runs on the server, I am facing a challenge with JavaScript. My understanding of JavaScript is limited, and ...

"Exploring ways to implement validation for multiple email addresses in a textarea using JQuery or JavaScript, while allowing the addresses to be separated by semicol

NOTE: Each email ID must be unique. An empty string value is allowed to be added. Email IDs should be separated by semicolons and commas. Basic validation of email IDs is necessary for entry. [![ $("#d-notification").focusout(function () { var ...

Utilize Django's TemplateView in ModelAdmin's add_view for seamless integration

As per the Django Admin site documentation, I have discovered that I can customize ModelAdmin.add_view to inject a custom view. My intention is to include a TemplateView to modify an admin page for adding or changing models. This unique view will feature ...