简体   繁体   中英

(TestNg) When i change the location in base class of driver location it is not reflecting it is showing IllegalStateException?

In BASE CLASS

public class BaseClass {

    public static WebDriver driver;

    public void getDriver() {
        System.setProperty("webdriver.chrome.driver",
                "D:\\Assignments\\Tasks\\Framework_Task\\adactinhotelapp\\adactinhotelapp\\Drivers\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.manage().window().maximize();
    }

    public void launchUrl(String url) {
        driver.get(url);
    }
}    

In then while I running it

public class SampleClassWithTestNg extends BaseClass {
    static BaseClass global = new BaseClass();
    
    @BeforeTest
    public void driverConfiguring() {
        global.getDriver();
        global.launchUrl("http://adactinhotelapp.com/");
    }
}    

but I'm getting error

java.lang.IllegalStateException: The driver executable does not exist: D:\Assignments\Tasks\Framework_Task\adactinhotelapp\Drivers\chromedriver.exe

I changed the location in base class ,

but it is showing the exception and change is not affected

Please check the chromedriver.exe file because the exact code is working fine for me.

Screenshot:

在此处输入图像描述

在此处输入图像描述

java.lang.IllegalStateException: The driver executable does not exist:

The above error, clearly indicate that there is some issue with the chromedriver.exe file.

As per the path mention, I can assume you are using windows, so make sure:

  1. Chromrdriver path is correct - If possible provide screenshot of the directory with path.

  2. You have permission to execute the chromedriver .

  3. Download the correct Chromedriver version for platform:

    https://sites.google.com/a/chromium.org/chromedriver/downloads https://chromedriver.chromium.org/downloads https://chromedriver.storage.googleapis.com/index.html

Note: For ubuntu and Mac the chromedriver shouldn't contain.exe as extension.


You can also remove the hassle of defining
System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver"); by using WebDriverManager .

To use WebDriverManager from tests in a Maven project, you need to add the following dependency in your pom.xml (Java 8 or upper required).

<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>4.4.3</version>
</dependency>

Just use:
WebDriverManager.chromedriver().setup(); instead of System.setProperty("webdriver.chrome.driver", "/path/to/chromedriver");

Ref: https://github.com/bonigarcia/webdrivermanager

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM