Hello! This is my new article on Selenium. Earlier, I already spoke in detail about the organization of a scalable Selenium cluster ( Part I , Part II ). Then we considered the issue of using Selenium as a tool for debugging autotests ( one , two ). Finally, we managed to create order out of chaos on Windows ( link ). Today we will deal with apples, more precisely with one big Apple (i.e. with Apple).
Although Selenium is a relatively simple tool, life becomes more complicated when we try to run automated tests in browsers from Cupertino: Safari under MacOS and mobile Safari under iOS. To fully understand the browsers for desktop operating systems, let's talk today about Safari under MacOS. Today, the latest versions of Safari are developed only for MacOS. Historically, work with Safari was implemented in Selenium using a browser extension that translated Selenium commands into internal browser commands. Initially, the extension was loaded into Safari automatically. Later, due to a change in security rules in Safari, you had to install the extension once manually. Finally, with the release of Safari X, everything has changed significantly. Safari now uses a stand-alone web driver process - safaridriver
, similar to chromedriver
in Chrome and geckodriver
in Firefox. To run tests in Safari:
Run safaridriver
(usually installed with Safari and located in /usr/bin/safaridriver
) on a free port, for example, 4444. The command to run will be this:
$ /usr/bin/safaridriver --port 4444
Run tests using the following Selenium URL:
http://localhost:4444/
It sounds easy, is not it? And so it is! Nevertheless, there is a problem - safaridriver
can work with only one copy of Safari in parallel. How to overcome this limitation? - Run the driver several times on different ports and run tests on different URLs with these ports. Simple, but requires a lot of manual work. Let's automate this process! How could this work? That's how:
safaridriver
is located.safaridriver
process on this port and proxies all subsequent requests to the same place.safaridriver
process also stops.The described algorithm is very simple, so it should not require the development of a complex server, is it? If you take as a server the current standard - the Selenium server, then you will use an overly complex tool for such a simple task. Why is this so:
In short, let me show you a more suitable tool - Selenoid . Selenoid is a lightweight daemon, created to completely replace the fat Selenium server. Getting Selenoid with Safari is easy:
Copy the slice of JSON below to a file (for example, in ~/browsers.json
):
{ "safari": { "default": "latest", "versions": { "latest": { "image": ["/usr/bin/safaridriver"] } } } }
Launch and download the Selenoid executable:
$ curl -Lo ~/selenoid \ https://github.com/aerokube/selenoid/releases/download/1.3.3/selenoid_darwin_amd64 $ chmod +x ~/selenoid $ ~/selenoid -conf ~/browsers.json -disable-docker
http://localhost:4444/wd/hub
No longer need to install Java and company! But if you, like me, do not want to do this with your hands, you can get a similar result using a single-line script:
$ curl -Lo ~/cm https://github.com/aerokube/cm/releases/download/1.2.1/cm_darwin_amd64 && \ chmod +x ~/cm && \ ~/cm selenoid start --browsers safari
If you wish, you can also download and run the lightweight UI for Selenoid. Read more about this in the documentation .
Simple Selenium testing in Safari has never been this close. Have a nice day!
Source: https://habr.com/ru/post/334048/
All Articles