Hi I have been trying to run a test on a virtual machine. I have gone through the Internet and none of the solutions worked for me.
I want to open firefox on Windows virtual machine. Here is my code:
#BeforeTest
public void launchapp() throws MalformedURLException
{
System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe");
String URL = "http://www.google.com";
System.out.println(" Executing on FireFox");
String Node = "http://XX.XX.X.XX:5555/wd/hub";
URL url = new URL(Node);
DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();
desiredCapabilities.setCapability("marionette", true);
desiredCapabilities.setBrowserName("firefox");
//driver = new FirefoxDriver(cap);
driver = new RemoteWebDriver(url, desiredCapabilities);
driver.manage().timeouts().implicitlyWait(60, TimeUnit.SECONDS);
driver.navigate().to(URL);
driver.manage().window().maximize();
}
The error I get on the virstual machine is:
The path to the driver executable must be set by the webdriver gecko.driver system property....
On my PC I only see on the console that its trying to connect the node but it fails:
Marking the node http://.... as down: cannot reach the node for 2 tries
and
Unregistering the node http://... because it's been down for XXX ms
and in Eclipse:
org.openqa.selenium.SessionNotCreatedException: Unable to create new remote session. desired capabilities = Capabilities [{marionette=true, browserName=firefox, version=, platform=ANY}], required capabilities = null
Do you have any idea why this is not working? What should I check?
Related
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);
I am able to run my test on a local machine with IWebDriver but
unable to run the test on a remote computer with Selenium.
DesiredCapabilities capability = new DesiredCapabilities();
capability.SetCapability(CapabilityType.BrowserName, DesiredCapabilities.InternetExplorer());
capability.SetCapability(CapabilityType.Platform, new Platform(PlatformType.Windows));
capability.SetCapability("webdriver.ie.driver", #"E:\WebDriver\Browser\");
string host = "localhost:4444/wd/hub";
RemoteWebDriver driver = new RemoteWebDriver(new Uri("http://" + host), capability);
The error I am getting is
Additional information: The path to the driver executable must be set by the webdriver.ie.driver
system property; for more information, see http://code.google.com/p/selenium/wiki/InternetExplorerDriver.
The latest version can be downloaded from http://code.google.com/p/selenium/downloads/list
Getting error:
FAILED CONFIGURATION: #BeforeMethod setUp
org.openqa.selenium.WebDriverException: The path to the driver
executable must be set by the webdriver.chrome.driver system property;
for more information, see
http://code.google.com/p/selenium/wiki/ChromeDriver. The latest
version can be downloaded from
http://chromedriver.storage.googleapis.com/index.html
My code :
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
String strChromePath = System.getProperty("user.dir")
+ "\\webdrivers\\chromedriver.exe";
System.setProperty("webdriver.chrome.driver", strChromePath);
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On the above code chromedriver it self is not getting invoked.
Then i tried with code:
ChromeDriverService chromeService = new ChromeDriverService.Builder()
.usingDriverExecutable(new File("webdrivers/chromedriver.exe"))
.usingAnyFreePort().build();
chromeService.start();
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
return new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),
capability);
On executing above code the executable is launched but chrome is not invoked. It throws the same error. Code is working fine for firefox. Any help please?
Download the relevant Chrome driver as per your system(32-bit/64-bit), from here . Try setting the property of ChromeDriver first, like this:
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
Then use this code:-
DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setVersion("38.0.2125.122 m");
WebDriver driver = new RemoteWebDriver(new URL("http://192.168.1.77:5555/wd/hub"),capability);
If there is no need of using "RemoteWebDriver", you can code just use this below :
File file = new File("D:\\chromedriver.exe"); //path to the chromedriver.exe so downloaded
System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
WebDriver driver = new ChromeDriver();
Try below :
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "properties/chromedriver.exe");
driver = new ChromeDriver();
driver.get("www.google.com");
Put chrome driver in properties folder.
I'm trying to run Safari from WebDriver. When i start the project it cant build beacouse it cannot find safari. Safari is installed on the machine, i am registered as an developer.
Does anyone have a solution?
Code:
if(browser.equalsIgnoreCase("firefox")) {
capability = DesiredCapabilities.firefox();
capability.setBrowserName("firefox");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
}
if(browser.equalsIgnoreCase("iexplore")) {
capability = DesiredCapabilities.internetExplorer();
capability.setBrowserName("iexplore");
capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);
}
if(browser.equalsIgnoreCase("chrome")) {
capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
}
if(browser.equalsIgnoreCase("safari")) {
capability = DesiredCapabilities.safari();
capability.setBrowserName("safari");
capability.setPlatform(org.openqa.selenium.Platform.ANY);
}
driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
driver.navigate().to(test_data.BASE_URL);
Stacktrace:
FAILED CONFIGURATION: #BeforeClass setup("safari")
org.openqa.selenium.WebDriverException: Error forwarding the new session cannot find : {platform=ANY, browserName=safari, version=}
Command duration or timeout: 203 milliseconds
The new version of selenium i.e. selenium 2.30.0 is released.Grab it as it has built in support for safari driver...Enjoy!!!
I am using the code from this site (http://darrellgrainger.blogspot.com/2011/02/using-selenium-20-with-webdriver-and.html) to run Selenium tests in Safari 5. The code goes like this:
Selenium sel = new DefaultSelenium("localhost", 4444, "*safari", baseURL);
CommandExecutor executor = new SeleneseCommandExecutor(sel);
DesiredCapabilities dc = new DesiredCapabilities();
WebDriver browser = new RemoteWebDriver(executor, dc);
browser.get("http://www.google.com");
WebElement input = browser.findElement(By.name("q"));
input.sendKeys("Selenium");
So I start a Selenium server standalone version on the localhost machine and I register a test node (also on localhost) to the Selenium hub. Then I start the test. I then get the following exception: org.openqa.selenium.WebDriverException: Could not start Selenium session: org%2Eopenqa%2Egrid%2Ecommon%2Eexception%2EGridException%3A+Error+forwarding+the+new+session+The+server+returned+an+error+%3A+
I don't know what error. There is no server output on the console. Does anyone have ideas? I used the newest version (2.17.0) of Selenium.
EDIT: I just tried "firefox" instead of safari and it outputs the same exception. So actually it's not the fault of safari. Maybe there is something wrong with executing Selenium 1 code via the grid?
Try This:
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setBrowserName("safari");
capabilities.setJavascriptEnabled(true);
CommandExecutor executor = new SeleneseCommandExecutor(new URL("http://localhost:5555/"), new URL("http://www.google.com/"), capabilities);
WebDriver driver = new RemoteWebDriver(executor, capabilities);
driver.get("http://google.com");
Don't create DefaultSelenium object. The above code works well for me with Safari browser.