Dynamic Setting of Protractor Driver Path

I have a test that needs to be executed on IE, CEFmp, and Chrome. The requirements are as follows:

  1. There should be a single conf.js file for IE, Cefmp, and Chrome.
  2. The test should dynamically read the browser type from a file and run the test accordingly.
  3. For Chrome and CEFmp runs, direct connect should be set to true.
  4. For Chrome and CEFmp runs, the test should only use specific drivers located in the local path instead of the default Protractor path.

I have successfully implemented picking the browser type based on the value mentioned in the file and running the test with direct connect enabled for Chrome and CEFmp. However, I am struggling to find a solution for specifying a particular Chrome driver. Currently, it is using the default driver from node_modules/protractor/selenium. Is there a way to dynamically select a driver from a specific path?

Thank you in advance.

Answer №1

Here are some steps you can follow:

  • Include additional values in your text file, such as "chrome-x", "chrome-y"
  • Create a new folder called "webdrivers" within your project
  • Store all required chromedrivers inside this folder (including different versions)

Next, adjust your code accordingly:

File chromeDriverFile = new File("webdrivers/" + webdriverAsRetrievedInYourTextFile); // Specify the path here
System.setProperty("webdriver.chrome.driver", chromeDriverFile.getAbsolutePath());
WebDriver driver = new ChromeDriver();

Answer №2

After much trial and error, I believe I have discovered a workaround for this issue. If anyone knows of a more efficient method, please share it with me.

Since I couldn't figure out how to direct the driver path to the local folder for retrieval, we came up with a solution by copying and replacing the default location driver (in the node_modules folder) with the local driver that we wanted to use. Here is the code snippet that accomplishes this:

var fs = require('fs');
fs.createReadStream(path.resolve(__dirname + '/bin/Drivers/CefMp/chromedriver.exe')).pipe(fs.createWriteStream(path.resolve('C:/node_modules/protractor/selenium/chromedriver.exe')));

This approach ensures that even though protractor initially selects the default driver from the node_modules folder, it ultimately utilizes the specific driver we intended for it to use.

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 disable the readonly attribute in Selenium?

I am trying to remove the readonly property from an Input tag using Selenium in Java. Below is the code I am using to achieve this, where I am accessing the Input tag via xpath: WebElement InTag = driver.findElement(By.xpath("//div[@arid='7']//i ...

Navigation bar in reactjs remains visible even after clicking on an icon button, causing a temporary issue with

I'm facing an issue with my navigation bar created using material-ui. I have an onClick function set up so that when the user clicks the icon button, the navigation redirects to a new page and then should close. However, no matter what I try, the navi ...

Is it possible to implement formvalidation.io in a React project that is using Materialize-css?

Can the formvalidation.io plugin be used with React and Materialize-css in a project? My project consists of multiple input components that may or may not be within a form. I want to utilize formvalidation for input validation. However, I am unable to find ...

What is the method for choosing an Object that includes an Array within its constructor?

Is there a way to retrieve a specific argument in an Object constructor that is an Array and select an index within the array for a calculation (totaling all items for that customer). I have been attempting to access the price value in the Items Object an ...

Storing a child in an existing object with Firebase and Angular 6

How can I save a new form to an existing list with the following code snippet: createNewTumeur(newTumeur: Tumeur) { this.tumeurs.push(newTumeur); const id: string = this.route.snapshot.params['id']; firebase. ...

Establish the geolocation within the data object once Vue.js has been mounted

Just dipping my toes into the world of VueJS. I've got a side project in the works that hinges on fetching User's Geolocation Data right after the main component has mounted. My code snippet is as follows: var app = new Vue({ el: '#app&a ...

Error encountered when trying to load Ajax script

As a beginner in the learning process, my code may appear messy. I am currently wrapping up my second project, which is a photo viewer. On the main page, there is a navigation system that loads different sections of the website using ajax. Since this proje ...

Upon selecting multiple checkboxes, corresponding form fields will be displayed based on shared attributes

When multiple checkboxes are selected by the user, corresponding form fields should appear based on the checkboxes. For example, if both flight and hotel checkboxes are checked, then the full name and last name fields should be displayed while other fields ...

Having trouble finding the element using Python and Selenium - Trying to click on this particular button

Trying to locate a button without an id or name, I've attempted xpath, class name, CSS selector, and more. Here is the snippet of HTML code: https://i.sstatic.net/5P5Tj.png Your help is much appreciated. Thank you in advance. ...

Learn the technique for displaying various content in pop-up windows when clicking on HTML links

I have a code snippet that I am using and I want to display different content when clicked. <style> #overlay_form { position: absolute; border: 5px solid gray; padding: 10px; background: white; width: 270px; height: 190px; } ...

Automating the completion of online forms using Python and Selenium

Currently, I am attempting to populate this particular form in order to enhance my job. However, I have been encountering issues with Selenium: driver = webdriver.Chrome('/Users/48604/Desktop/kyk/chromedriver') driver.get('https://quintadb.c ...

What is the best method for accessing the HTML element specified in React JSX?

Consider this custom component example: import React, { Component } from 'react'; class Canvas extends Component { componentDidMount() { let canvas = this.refs.canvas; const ctx = canvas.getContext('2d'); ctx.fillRect(0, ...

Upon successful registration, users will be automatically redirected to their profile page

Having trouble with the redirection to the login page from my profile page, which is an HTML file and the main page is the login page. I've tried redirecting to both pages, but it always lands in the catch block whenever a redirect is attempted. angu ...

Exploring Linked Data in JSON API Response with Rails API, Active Model Serializer, and Vue.js Single Page Application

I am working with data structured in a tree/hierarchical model for climbing areas, where they are connected through parent and child relationships. By utilizing the JSON API adapter along with my Active Model Serializer, class AreaSerializer < ActiveM ...

Securing Objects in Parse with the JavaScript API - Linking Users to their saved entities

When managing entities in Parse, I often need to associate various objects with the user currently logged in. My main concerns are: There is no backend code in place to ensure that the User being passed in is actually the logged-in user. Users could poten ...

Access the value using Selenium in Python

I need help with extracting the dollar amount from this HTML element: <span class="a-color-price hlb-price a-inline-block a-text-bold">$399.98</span> The task is to retrieve the price value (in dollars) that is displayed within the text of th ...

Selecting Content Dynamically with jQuery

I have a webpage with multiple dynamic content sections. <div id="content-1"> <div id="subcontent-1"></div> <i id="delete-1"></i> </div> . . . <div id="content-10"> <div id="subcontent-10"></d ...

What is the most effective way to transfer data from a child component to a parent component when the child component contains multiple input fields?

Passing data from a parent component to a child component is something I need help with. Let's say I have a parent component with the following data: Parent component <template> <NameUser :data="userData"></Name ...

Incorporate JSON data into a JavaScript search in CouchDB

I am currently working with a CouchDB database that contains approximately one million rows. My goal is to query for specific rows in the database using the keys provided in an external JSON file. The approach I am currently using to achieve this involves ...

Methods for applying a style property to a div element with JavaScriptExecutor in Selenium utilizing C#

I have been attempting to change the style of a div element using JavascriptExecutor in C#, but so far, nothing has happened. IJavaScriptExecutor js = (IJavaScriptExecutor)driver; IWebElement element = driver.FindElement(By.XPath("//div[contains(@class, ...