The execution of the Selenium TestNG executable JAR is encountering errors and not

I have created a Selenium + TestNG maven project in Java using Eclipse IDE, located in the directory I:\Projects\. When I run the testng.xml file by right-clicking the project, it successfully launches the Chrome browser. I decided to export this project as a 'Runnable JAR file' and saved it on my Desktop (C:\Users\Programmer\Desktop).

Now,

  1. If I execute the saved executable jar from my project directory by double-clicking it, the Chrome browser is launched. For example,
    I:\Projects>java -jar "C:\Users\Programmer\Desktop\runnable.jar"
    , however,
  2. If I attempt to launch the browser by executing the executable jar from the desktop, it fails. For instance,
    C:\Users\Programmer\Desktop>java -jar runnable.jar

Below is a snippet of my simple selenium code:

public class GoogleSearch {

WebDriver driver;

@Test
public void launchBrowser() {
    String PWD = System.getProperty("user.dir");
    System.out.println(">>>>>>" + PWD);
    System.setProperty("webdriver.chrome.driver", PWD + "\\lib\\chromedriver");
    driver = new ChromeDriver();
    driver.get("https://www.google.com");
    WebElement search = driver.findElement(By.name("q"));
    search.sendKeys("Selenium monk");
}

@Test
public void tearDown() {
    if (driver != null) {
        driver.close();
        driver.quit();
    }
}
}

Project directory structure..

https://i.stack.imgur.com/Ag6dY.png

It seems that when I run the jar from the Desktop, it can't locate the chromedriver in the lib folder. How can I resolve this issue?

What else could be missing here?

Answer №1

To execute the following command on your desktop, make sure you are in the C:\Users\you\Desktop directory:

java -cp runnable.jar;path-to-your-proj\lib\* org.testng.TestNG path-to-your-proj/testng.xml -Duser.dir=path-to-your-proj

Answer №2

After encountering an issue where the jar was unable to find the chromedriver in the lib folder while running from Desktop, I took matters into my own hands and found a solution.

To fix this problem, I decided to set the chrome driver as part of the environment variables. By updating the chrome driver property using

System.getenv("chrome_driver_path");
, I was able to overcome the issue.

I want to express my gratitude to those who dedicated their time to provide answers to my question. Your help is greatly appreciated!

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

Launching an Angular JS application with a Java Spring backend on a standalone Tomcat server

Utilizing Intellij IDE, I developed a Java Spring and AngularJS application. After creating a war (Web Application:Exploded) file in Intellij, I placed it in the Tomcat webapps directory. Although the AngularJS code deployed successfully and was accessible ...

DataTables: Reordering array elements while rendering

When utilizing DataTables with server-side processing, I encounter a json object that contains an array of LocalDateTime elements: ... "SimpleDate": [ 2000,12,31,0,0 ] ... In the initialization script, my columns definition is as follows: "columns": [ ...

What is the best technique for scrolling multiple times to locate a specific element?

I am trying to develop a script that will continuously scroll until it finds the specific element using: from appium.webdriver.common.touch_action import TouchAction The webpage in question is an Events page featuring various game titles. Currently, I ha ...

Error message displayed when building a Cordova project: "Build Failed" due to issues

Encountering issues when attempting to build a Cordova project using cmd with Android 6.4.0 and also trying Android 7.1.0, but consistently getting a build failed message. The following error occurs after building the Cordova project: cordova build an ...

Ways to discover the present date and transition to the following date?

Currently, I am encountering an issue with my automation script. My script utilizes the selenium tool along with Java language. The specific problem I am facing involves the need to view the current date after clicking on a calendar and verifying if a flig ...

Initializing Page Elements with Selenium 4 using PageFactory

I am currently in the process of upgrading my outdated Selenium library to the latest version. However, I'm encountering issues with the PageFactory.InitElements method, which is not available in the default Selenium 4 but can be found in DotNetSeleni ...

Guide to retrieving PDFs and images from a Spring Application as an API response and manipulating the data using JS/React

For my current project, I am working on a Spring Boot and React application where I need to create an API that takes the file name as input and returns the file content in Java/Spring Boot. The goal is to display the content in a new browser tab. Below is ...

Can Maven be utilized solely for executing the Selenium plugin?

In our current pom.xml file, we have both the build settings and the selenium execution using the selenium-maven-plugin. I am interested in separating these into two separate pom files - one for building and running unit tests, and another dedicated speci ...

Error message: "Execution of taskkill executable not found in Selenium WebDriver"

Every time I run the driver.quit() command, it successfully opens and quits the firefox browser but I keep getting an error message saying "Unable to find executable for: taskkill". I have already set the environment variable PATH to "C:\Windows&bso ...

Utilize VBA-Selenium to export table data into separate Excel sheets

My current task involves extracting information from a website in tabular format based on specific keywords. Below are the keywords and the sample website: apple LG Samsung Nokia Website = www.wikipedia.com I have organized the keywords in Sheet 1 and th ...

Navigate to precise location using Selenium with Python

Is there a way to scroll down a specific area of a webpage? I'm trying to scroll down on the LinkedIn message section only, not the entire screen. Can someone assist me with this? Please refer to the image for clarification. CLICK HERE ...

Different ways in which a selenium script can be run

I've developed a selenium script using python 3. The script needs to run daily at 7AM for approximately 5 minutes. However, I don't want to keep my laptop running all the time just for this task. Can anyone suggest an alternative that is convenie ...

Using Selenium WebDriver in Java: clicking at specific x and y coordinates

I am having trouble with clicking a Point in Flash Player within a Flash Iframe that is embedded in a browser. I want to click on a specific button, but I find it difficult to code for Flash and interact with Flash Elements. Therefore, I would like to be ...

building a diverse language website on amazon web services

In our upcoming project, we aim to develop a multilingual website utilizing AngularJS and AWS. The website will feature dynamic data sourced from the back end. We are contemplating the best approach for handling language-specific content - should we store ...

Using Selenium to input text into the password input field

I am encountering an issue while attempting to log in to my profile. The problem arises when I try to input the password as the cursor appears in the password box, but an exception is thrown when trying to send the keys. Could this be due to a security mea ...

Error: The session ID is not currently active

I encountered a problem with my tests failing when running them on TFS, showing the following error: WebDriverError: No active session with ID Failed: No active session with ID Interestingly, these same tests are passing locally. Everything was working ...

Structure of JSON for a Collection of Items

I'm curious about the correct JSON structure for a list of objects. In our project, we are using JAXB to convert POJOs to JSON. Here are the options. Can you please advise on the right approach? foos: [ foo:{..}, foo:{..} ...

Discovering a way to extract the URL link for the "View Deal" option and the deal price from Kayak.com through BeautifulSoup

Currently seeking assistance with extracting price and deal link data from a list of Kayak URLs. Specifically, interested in retrieving information from the "Best" and "Cheapest" HTML cards, which correspond to the first two results after sorting the URLs ...

Using Python with Selenium, retrieve the number of elements impacted by the find_element_by_css_selector method

I am attempting to obtain the count of affected elements through my CSS query. Unfortunately, I have been unsuccessful in retrieving this count. browser = webdriver.Firefox() browser.get("http://just-a-example.site") td_weeks = browser.find_element_by_cs ...

What is the best way to create a divider between tab panes in JavaFX?

I created a unique vertical tabpane, but I am struggling to insert horizontal lines between each label. Below is the code snippet I have used: .tab *.tab-label { -fx-rotate: 90; } .tab { -fx-padding: 3em 0.5em; } .tab-pane .tab-header-area .tab ...