Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support local safaridriver from Safari 10.0 #345

Open
OndraM opened this issue Oct 16, 2016 · 7 comments
Open

Support local safaridriver from Safari 10.0 #345

OndraM opened this issue Oct 16, 2016 · 7 comments
Labels
enhancement New feature help wanted We'd appreciate help on this issue
Milestone

Comments

@OndraM
Copy link
Collaborator

OndraM commented Oct 16, 2016

Safari could be started through Selenium Server as remote WebDriver.

Since Safari 10.0 (see blogpost), however, it could also be started also locally, using binary "safaridriver" (as chrome, opera and geckodriver - see also #344, #342). This is already supported by other selenium language bindings, so we could support it as well.

It would require creating new classes SafariDriver, SafariDriverService and SafariOptions - see java bindings as an example.

@rajabhaskar
Copy link

rajabhaskar commented Dec 21, 2016

@OndraM Can you please let me know how I can run acceptance suite in safari browser in Windows 8.1. Below is my acceptance.yml file configuration. I tried --env safari and --env firefox by mentioning the env in acceptance suite. yml also but no luck. it's giving me error

**_[Codeception\Exception\ConnectionException]
Curl error thrown for http POST to /session with params: {"desiredCapabilit
ies":{"unexpectedAlertBehaviour":"accept","handlesAlerts":true,"browserName
":"firefox"}}
Could not resolve host: selenium-hub

Please make sure that Selenium Server or PhantomJS is running._**

But I do have selenium jar or phantom running aside already with below command
phantomjs --webdriver=4444 [OR] java -jar vendor/selenium/selenium-server/selenium-server-standalone-2.53.0.jar

Acceprance.suite.yml
modules:
enabled:

  • WebDriver
  • \Helper\Acceptance
  • \Helper\Locator
  • \Helper\User
  • \Helper\TestData
    config:
    WebDriver:
    url: 'https://www.abc.com'
    browser: safari
    wait: 2
    window_size: maximize
    clear_cookies: false
    capabilities:
    unexpectedAlertBehaviour: 'accept'
    handlesAlerts: true

but it is not working. If I replace the browser name with Chrome (and run executable) or firefox then I was able to run my suite. Please advise. (By the way, I do have safari installed manually in my machine - V5.1.7)
Thanks

@Anton-Rosen
Copy link

Hi @OndraM,
I'm working with php via linux command line and trying to run a few tests. I've read all of your posts related to this and the links you provided, but I can't find anything that helps with my problem (or maybe I just didn't understand the solution when I saw it)

I write out my code in a php file and run it with php myfilename.php and BrowserStack shows me my results. However, safari is killing me.

I have the following line (from browser stack):
$caps = array("browser" => "Safari", "browser_version" => "10.1", "os" => "OS X", "os_version" => "Sierra", "resolution" => "1024x768");

Later in the code I have: $web_driver->findElement(WebDriverBy::id("book-now-btn"))->click();

Safari is the only browser giving me this error: Facebook\WebDriver\Exception\ElementNotVisibleException: An element command could not be completed because the element is not visible on the page.

Any help or ideas would be amazing. The test connects and shows a successful load of the page I'm testing, but that first find element just kills it (and I double checked on a mac, that is the right id).

Thanks in advance!

@OndraM
Copy link
Collaborator Author

OndraM commented Jul 12, 2017

@ComradeAnton Hi, could you please provide URL of the page? Also try waiting for the element, as it may not yet be rendered in the moment you try to access it, see https://github.com/facebook/php-webdriver/wiki/HowTo-Wait .

@Anton-Rosen
Copy link

Anton-Rosen commented Jul 12, 2017

Hi @OndraM, I know you do volunteer support here so ty for getting back so quickly.
I'm new to selenium and facebook/webdriver so I apologize in advance for any rookie questions.

I am trying to automate the selection of the "Check rates" dates picker on the top right of the 1hotels.com page. I am trying to make the code click on July 15th, then on July 19th. This works in all browsers except for Safari (I have only tried El Capitan and Sierra).
In safari I get either the "Element is no longer attached to the DOM" error or "Element not found" after the first date has been selected.
I tried using xpath to to get the element, and then tried cssSelector with no luck.

Here is my test code:

<?php
require_once('vendor/autoload.php');
use Facebook\WebDriver\Remote\RemoteWebDriver;
use Facebook\WebDriver\WebDriverBy;
use Facebook\WebDriver\WebDriverExpectedCondition;
use Facebook\WebDriver\WebDriverDimension;
use Facebook\WebDriver\WebDriverWindow;
use Facebook\WebDriver\Remote\DesiredCapabilities;
use Facebook\WebDriver\Remote\RemoteWebElement;

 $caps = array("browser" => "Safari", "browser_version" => "9.1", "os" => "OS X", "os_version" => "El Capitan", "resolution" => "1024x768");
 //$caps = array("browser" => "Chrome", "browser_version" => "59.0", "os" => "Windows", "os_version" => "10", "resolution" => "1024x768");
 $web_driver = RemoteWebDriver::create("https://verbinteractive1:LER3fHmdqDwX7hn7Ep3U@hub-cloud.browserstack.com/wd/hub", $caps);

 $web_driver->get("http://1hotels.com/");
 $web_driver->manage()->window()->setSize(new WebDriverDimension(1225, 996));
 $web_driver->findElement(WebDriverBy::id("book-now-btn"))->click();

  $web_driver->findElement(WebDriverBy::xpath(".//td[@data-month='6']/a[contains(text(),'15')]"))->click();
  $web_driver->findElement(WebDriverBy::xpath(".//td[@data-month='6']/a[contains(text(),'19')]"))->click();
 //$web_driver->findElement(WebDriverBy::cssSelector("td[data-month='6']"))->findElement(WebDriverBy::linkText("15"))->click();
 //$web_driver->findElement(WebDriverBy::cssSelector("td[data-month='6']"))->findElement(WebDriverBy::linkText("19"))->click();

 $web_driver->findElement(WebDriverBy::id("check-availability"))->click();

 $web_driver->quit();

What I don't understand is that while I was typing this up, it started working. I'm honestly not sure what was causing the issue. Could it somehow be based on how quickly the click command gets sent to the server vs how long it takes the date picker to open?

Thanks!

UPDATE: I just tested Sierra and El Capitan again and it seems that Sierra is the cause of issues. El Capitan recognizes all the commands I send it, while Sierra doesn't recognize $web_driver->manage()->window()->maximize(); sometimes. As of my last test Sierra breaks on the click event after the "book-now-btn" with the following error: An element command could not be completed because the element is not visible on the page

UPDATE 2: Sierra Safari 10.1 is now giving a "A request to use a window could not be satisfied because the window could not be found" error on the $web_driver->manage()->window()->setSize(new WebDriverDimension(1225, 996)); line

@Anton-Rosen
Copy link

UPDATE 3: After a lot of googling and talking to BrowserStack support it seems that Safari 10.1 simply doesn't support certain actions at the moment. BroweserStack support told me the following:
As a workaround for this, we recently added Safari 10 Technology preview release v30 on Sierra for Automate. The commands change window size will certainly work on Safari 10 Technology preview. You can test on this release by adding the following capabilities in your test scripts.
caps['safari.options'] = {

'technologyPreview' => true

}​
For example in Ruby this would look like:

caps = Selenium::WebDriver::Remote::Capabilities.new
caps["browser"] = "Safari"
caps["browser_version"] = "10.1"
caps["os"] = "OS X"
caps["os_version"] = "Sierra"
caps['safari.options'] = {

  'technologyPreview' => true

}​

Hopefully this helps anyone else looking for a similar fix. I haven't made the above fix work yet, but when I do, I will update with my findings.

@Anton-Rosen
Copy link

Anton-Rosen commented Jul 13, 2017

Update 4:
Sorry for spamming this thread up, but I have some useful findings.

  1. The PHP syntax to use the safari tech preview is as follows:
 $caps = array("browser" => "Safari", "browser_version" => "10.1", "os" => "OS X", "os_version" => "Sierra");
 $caps['safari.options'] =  array('technologyPreview' => true);

As for the issue with Safari being difficult, @OndraM was correct in setting a wait on the elements that are causing problems. However, Browserstack seems to randomly have issues with finding elements Im working with. I've had all my tests succeed for one build, and then fail in various spots via timeout in another.
My code is exactly the same in both cases with absolutely nothing changing.

Anyway, hope this helps!

@OndraM
Copy link
Collaborator Author

OndraM commented Jul 17, 2017

@ComradeAnton Nice findings, thanks, it sure may help others!

@OndraM OndraM added this to the 2.0 milestone Nov 11, 2019
@OndraM OndraM added the enhancement New feature label Apr 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature help wanted We'd appreciate help on this issue
Projects
None yet
Development

No branches or pull requests

3 participants