I have a Spring Boot project which is using selenium for automation testing of different application. The output archive of project is a JAR file. I have below code to initiate chrome browser.
static {
try {
Resource resource = null;
String osName = System.getProperty("os.name").toLowerCase();
if (osName.contains(IAutomationConstans.WINDOWS_OS_NAME)) {
resource = new ClassPathResource("chromedriver.exe");
} else if (osName.contains(IAutomationConstans.LINUX_OS_NAME)) {
resource = new ClassPathResource("chromedriver");
}
System.setProperty("webdriver.chrome.driver", resource.getFile().getPath());
ChromeOptions capabilities = new ChromeOptions();
webdriver = new ChromeDriver(capabilities);
Runtime.getRuntime().addShutdownHook(CLOSE_THREAD);
} catch (Exception e) {
System.out.println("Not able to load Chrome web browser "+e.getMessage());
}
}
Apart form this I have below Spring Boot code which executes automation code.
@SpringBootApplication
@ComponentScan("com.test.automation")
@PropertySource(ignoreResourceNotFound = false, value = "classpath:application.properties")
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class,
DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class})
public class TestAutomation{
public static void main(String[] args) {
System.out.println("&&&&&&&&&&&&&&&&&&&&&");
SpringApplication.run(TestAutomation.class, args);
System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%");
}
}
I have placed chromedriver.exe under src\main\resources. If I am executing TestAutomation class from eclipse by doing right click everything is working fine.
But If I generate jar file by mvn package command and executing JAR file I am getting below error.
Not able to load Chrome web browser class path resource [chromedriver.exe] cannot be resolved to absolute file path because it does not reside in the file system: jar:file:/C:/user/automation/target/automationapp-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/chromedriver.exe