I have created script using TestNG annotation and maven. It runs expected in Eclipse, I also tried to run testng.xml file which looks good. and then I configured Jenkins but now Its not running. Jenkins giving error as below : (FYI : I have successful built in Jenkins previously , how this could broken in one day ???)
Starting ChromeDriver 72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38) on port 48847
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Tests run: 7, Failures: 1, Errors: 0, Skipped: 6, Time elapsed: 4.774 sec <<< FAILURE! - in TestSuite
launchBrowser(com.pages.VisibilityAnnotationDemo) Time elapsed: 4.208 sec <<< FAILURE!
org.openqa.selenium.WebDriverException:
unknown error: Chrome failed to start: crashed
(unknown error: DevToolsActivePort file doesn't exist)
(The process started from chrome location C:\Program Files (x86)\Google\Chrome\Application\chrome.exe is no longer running, so ChromeDriver is assuming that Chrome has crashed.)
(Driver info: chromedriver=72.0.3626.69 (3c16f8a135abc0d4da2dff33804db79b849a7c38),platform=Windows NT 10.0.19042 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 872 milliseconds
I added below Jenkins config Root POM =
C:\Users....\workspace\VRsessions\pom.xml
Goals and options = clean install
The code I am try to run , Its script to do UI validation.
**public String baseUrl = " URL OF PAGE";
String driverPath = "C:\\Selenium\\chromedriver_win32\\chromedriver.exe";
public WebDriver driver;
JavascriptExecutor js = (JavascriptExecutor) driver;
#BeforeTest
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver();
driver.get(baseUrl);
}**
Tests on chrome, as far as I know, must be in headless mode to run on Jenkins. You'll need to set chrome options like this:
import org.openqa.selenium.chrome.ChromeDriver;
...
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.addArguments("--headless");
driver = new ChromeDriver(chromeOptions);
To fix this:
Add the the --disable-dev-shm-usage, --headless, --no-sandbox command line option to Chrome. And you also need to pass the ChromeOptions object to new ChromeDriver(options);
Code:
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--no-sandbox");
options.addArguments("--disable-dev-shm-usage");
options.addArguments("disable-infobars");
System.setProperty("webdriver.chrome.driver", driverPath);
driver = new ChromeDriver(options);
driver.get(baseUrl);
My coworker using MacOS sent me their Selenium project, containing this:
System.setProperty("webdriver.chrome.driver", "resources\\chromedriver");
driver = new ChromeDriver();
Because I'm using Windows, I downloaded chromedriver.exe in the same folder and changed the previous lines to:
System.setProperty("webdriver.chrome.driver", "resources\\chromedriver.exe");
driver = new ChromeDriver();
However, the test doesn't launch the driver, then fails after some time and I'm getting this error message:
caused by java.io.IOException: Cannot run program "blablabla\resources\chromedriver"
So this means the project is looking for chromedriver and not chromedriver.exe. How come? How can I fix it?
Thank you!
I have a C# setup but the way it works for me is that I specify the folder (full path) where the driver is located.
Config class, notice I have specified the location of the driver and not the .exe-file.
"selenium": {
"screenShots": "C:\\ScreenShots",
"chromeDriver": "C:\\webdrivers",
"driverUrl": "https://www.google.se"
}
Driver init.
Driver = new ChromeDriver(Conf.Selenium.ChromeDriver)
{
Url = Conf.Selenium.DriverUrl,
};
Driver.Manage().Window.Maximize();
My code is very simple
code:
WebDriver wd =new ChromeDriver();
System.setProperty("webdriver.chrome.driver",
"D:\\List_of_Jar\\chromedriver.exe");
String baseUrl = "https://www.google.com";wd.get(baseUrl);
have downloaded and added jar as "Java-3.4.0" from selenium hq site.
Download Google Chrome Driver-2.29 from the same website and located it in "D:\List_of_Jar" path.
When I run the above code I getting an error as
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property; for more information, see https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver. The latest version can be downloaded from http://chromedriver.storage.googleapis.com/index.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:738)
Getting version error though did proper configuration. so kindly help me for fixing the issue.
Details:
OS: Windows XP.
Java : JDK1.8 and JRE1.8.
Selenium : version 3.4
Driver path should be set before browser launch as given below.
System.setProperty("webdriver.chrome.driver","D:\List_of_Jar\chromedriver.exe");
WebDriver wd =new ChromeDriver();
String baseUrl = "https://www.google.com";
wd.get(baseUrl);"
You are setting chrome driver path incorrectly. Property must be set before WebDriver initialization.
Set property like this -
System.setProperty("webdriver.chrome.driver","D:\\List_of_Jar\\chromedriver.exe")
WebDriver wd =new ChromeDriver();
String baseUrl = "https://www.google.com";
wd.get(baseUrl);"
If you are using IntelliJ IDE, then on IntelliJ without setting up within the 'Run > Edit configurations > VM Options' i will just meet this error:
Failed scenarios:
C:/Users/DATestAdmin/IdeaProjects/TestLogin/src/test/resources/login.feature:4 # Scenario: Successfully logging in
1 Scenarios (1 failed)
3 Steps (3 skipped)
0m0.194s
java.lang.IllegalStateException: The path to the driver executable must be set by the webdriver.chrome.driver system property;
So once i've added the path to my chromedriver locally in 'Run > Edit configurations > VM Options':
-Dwebdriver.chrome.driver="C:\\Users\\This\\Is\\Where\\ChromeDriverIs\\chromedriver_win32.exe"
I'm now able to launch my Chrome browser successfully.
I totally agree with Murthi, but better is to set relative path to the driver, NOT the absolute.
Relative path looks like:
System.setProperty("webdriver.chrome.driver", "src/test/resources/drivers/chromedriver.exe");
Abosulte: is the path to the driver in your PC.
System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");
Why?
It is a good practice to have driver inside your project, not just in your computer. Just find or create folder f.e. resources, inside resources create folder called f.e. drivers and import your driver/drivers exe files there.
The below lines works fine
public class TestNGFile {
public String baseUrl = "https://google.com";
String driverPath = "C:\\\\Users\\\\Documents\\\\selenium\\\\chromedriver_win32\\\\chromedriver.exe";
#Test
public void verifyHomepageTitle() {
System.out.println("launching chrome browser");
System.setProperty("webdriver.chrome.driver", "C:\\Users\\Documents\\selenium\\chromedriver_win32\\chromedriver.exe");
//System.setProperty("webdriver.gecko.driver", driverPath);
WebDriver driver = new ChromeDriver();
driver.get(baseUrl);
String expectedTitle = "Google";
String actualTitle = driver.getTitle();
Assert.assertEquals(actualTitle, expectedTitle);
driver.close();
Try:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Demo2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.setProperty("webdriver.chrome.driver", "I:\\Bhasker-ShiroCode\\work\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://google.com");
}
}
To avoid Error:
webdriver.chrome.driver ( should be in small letters )
have to give correct chromedriver.exe ( correct path )
Import all Selenium jars under class Path
I was getting the same error, since chrome driver was not installed on my machine.
Install the chrome driver. Follow:
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
You should use Chocolatey as the Selenium wiki dictates. It will work straight away.
Windows users with Chocolatey installed: choco install chromedriver
https://github.com/SeleniumHQ/selenium/wiki/ChromeDriver
I also encountered the same problem. Following fix, made my application run smoothly.
Firstly, the required version of chrome driver could be found from below link.
http://chromedriver.storage.googleapis.com/index.html
It is best to use always the latest version. After downloading, set the path of chrome driver in System.setProperty("webdriver.chrome.driver","{Your path Chrome Driver}");
Follow the code fragment.
System.out.println("Creating Chrome Driver");
// Set Chrome Driver
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("{Your URL}");
System.out.println("Wait a bit for the page to render");
TimeUnit.SECONDS.sleep(5);
System.out.println("Taking Screenshot");
File outputFile = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
String imageDetails = "D:\\Images";
File screenShot = new File(imageDetails).getAbsoluteFile();
FileUtils.copyFile(outputFile, screenShot);
System.out.println("Screenshot saved: {}" + imageDetails);
I faced the same issue.
"The path to the driver executable must be set by the webdriver.chrome.driver system property."
downloaded the driver and have set in system property.
https://www.youtube.com/watch?v=Ny_8ikCbmcQ
I'm trying to use headless webkit of PhantomJs for opening google.com through selenium webdriver but when I execute the code system throws an error. phantomJs.exe is placed in E directory. Please help me resolve this issue.
public static void main(String[] args) throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "E:\\phantomjs.exe");
WebDriver driver = new PhantomJSDriver();
driver.get("http://www.google.com");
}
Error:
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable; for more information, see https://github.com/ariya/phantomjs/wiki. The latest version can be downloaded from http://phantomjs.org/download.html
at com.google.common.base.Preconditions.checkState(Preconditions.java:197)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.findPhantomJS(PhantomJSDriverService.java:236)
at org.openqa.selenium.phantomjs.PhantomJSDriverService.createDefaultService(PhantomJSDriverService.java:181)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:104)
at org.openqa.selenium.phantomjs.PhantomJSDriver.(PhantomJSDriver.java:94)
at multidrivers.main(multidrivers.java:35)
Exception in thread "main" java.lang.IllegalStateException: The path to the driver executable must be set by the phantomjs.binary.path capability/system property/PATH variable;
The above issue is due to the driver not being initialized with the DesiredCapabilities object:
WebDriver driver = new PhantomJSDriver();
Updating the code as below should solve your issue:
WebDriver driver = new PhantomJSDriver(caps);
Let me know if you have any queries.
I am trying to upload a file using Safari Driver.
Here is my code:
DesiredCapabilities browserCapabillities = DesiredCapabilities.safari();
RemoteWebDriver driver = new SafariDriver(browserCapabillities);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("myAppURL");
WebElement upload = driver.findElementByXPath("//input[#id='fileElementId']");
RemoteWebElement webElement = ((RemoteWebElement) upload);
LocalFileDetector detector = new LocalFileDetector();
webElement.setFileDetector(detector);
File f = detector.getLocalFile("myFilePath");
upload.sendKeys(f.getAbsolutePath()); // Generating exception:
// org.openqa.selenium.WebDriverException: Unknown command: uploadFile
driver.findElement(By.id("uploadButton")).click();
Only thing that is working for me right now is AppleScript. Thanks to Using AppleScript to choose a file in Safari. But with Apple Script I had to keep my machine unlocked.
I feel LocalFileDetector is a better solution as I would like to run my tests even when the machine is locked.
I am not sure whether the following helps ?
driver.setFileDetector(new LocalFileDetector()); // I am getting
// org.openqa.selenium.WebDriverException: Setting the file detector only
// works on remote webdriver instances obtained via RemoteWebDriver
Change
RemoteWebDriver driver = new SafariDriver(browserCapabillities);
to
RemoteWebDriver driver = new RemoteWebDriver(urlofhub,browserCapabillities);
Refer this post for an example code.