Running safari from webdriver - safari

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!!!

Related

Which is the compatible version of IEDriverServer for IE11 and Selenium 3.13?

I am automating tests with IE11 and Selenium 3.13 and I was testing different version of IEDriverServer but every version has a bug. I want a stable version to combine IEDriverServer with IE11 and Selenium 3.13
I'm using this code to launch the application:
private static WebDriver setRemoteDriver(Map<String, Object> selConfig) {
String browser = System.getProperty("browser", selConfig.get("browser").toString());
capabilities = new DesiredCapabilities();
capabilities.setJavascriptEnabled(true);
if (browser.equalsIgnoreCase("firefox")) {
capabilities = DesiredCapabilities.firefox();
capabilities.setCapability(FirefoxDriver.PROFILE, getFirefoxProfile());
capabilities.setCapability("pageLoadStrategy", "normal");
} else if (browser.equalsIgnoreCase("chrome")) {
capabilities = DesiredCapabilities.chrome();
} else if (browser.equalsIgnoreCase("Safari")) {
capabilities = DesiredCapabilities.safari();
} else if ((browser.equalsIgnoreCase("ie")) || (browser.equalsIgnoreCase("internetexplorer"))
|| (browser.equalsIgnoreCase("internet explorer"))) {
capabilities = DesiredCapabilities.internetExplorer();
} else {
System.out.println("Please correct Browser specify in YAML file : " + browser);
capabilities = DesiredCapabilities.firefox();
}
try {
url = new URL(System.getProperty("ipaddress", getYamlValue("selenium.remote.host")));
} catch (MalformedURLException e) {
e.printStackTrace();
}
return new RemoteWebDriver(url, capabilities);
}
IEDriverServer for IE11 and Selenium should always be identical.
As per best practices you should always use the recent GA version while some organizations tends to prefer the major GA releases only.
As an example:
For Selenium v3.14.0 you should always use IEDriverServer v3.14.0
In some exceptional cases there may be minor Selenium releases where you need to use the IEDriverServer from the major release. As an example:
For Selenium v3.141.0, Selenium v3.141.5 and Selenium v3.141.59 you should always use IEDriverServer v3.141.0 only.
This Usecase
For Selenium v3.13.0 you should always use IEDriverServer v3.13.0

Not able to open Chrome headless from Selenium

I am using maven here.Here is my Selenium code:
DesiredCapabilities capb = DesiredCapabilities.chrome();
capb.setCapability("chrome.binary","/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless","--disable-gpu", "--no-sandbox","--remote-debugging-port=9222");
capb.setCapability(ChromeOptions.CAPABILITY, options);
System.setProperty("webdriver.chrome.driver","/Users/nitinkumar/TEST/chromedriver");
try{
ChromeDriver driver = new ChromeDriver(capb);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://qa.cmnetwork.co");
driver.quit();
}
catch(Exception e)
{
e.printStackTrace();
}
when I run "mvn test" it starts the chrome in GUI mode. but It should open in Headless mode. I have chrome vesrion 59.0, OS X yosemite(10.10.5), chromedriver 2.30 and Selenium 3.4.0.
It won't open in GUI mode. Just the chrome launcher icon will be opened. And it is an expected behaviour.
You have to remove the argument --remote-debugging-port. That will block the launched headless Chrome. So the script will never move forward.And you will get a chrome not reachable error
So change the arguments like
options.addArguments("--headless","--disable-gpu", "--no-sandbox");
Also, there is no need for --no-sandbox. As per Official doc only --headless and --disable-gpu flags are enough
Unless you have multiple versions of chrome installed, there is no need for DesiredCapabilities as well.
So the simple code for headless-chrome
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless","--disable-gpu");
System.setProperty("webdriver.chrome.driver","/Users/nitinkumar/TEST/chromedriver");
ChromeDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.get("https://qa.cmnetwork.co");
driver.quit();

Selenium test on VM with Geckodriver

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?

getting error with chromedriver using RemoteWebdriver

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.

Using Selenium to test Safari gives GridException

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.