How to run selenium tests on Safari using Selenoid? - selenium

I'd like to ask, maybe somebody had experience with running automation tests on Safari (there are some strict limitations for Windows and Linux machines). One approach that I detected - it's Selenoid (but when run it, I get: "
Could not start a new session. Possible causes are invalid address of the remote server or browser start-up failure.
Build info: version: '4.0.0', revision: '......'
System info: host: 'runner-ovqpgybp-project-31983248-concurrent-0', ip: '.....', os.name: 'Linux', os.arch: 'amd64', os.version: '5.15.0-1017-gcp', java.version: '17.0.1'
selenide.remote: http://localhost:4444/wd/hub
Let me know if there exist some solution or workaround, please.

We provide Webkit-based Docker images for that:
$ cat browsers.json
{
"safari": {
"default": "15.0",
"versions": {
"15.0": {
"image": "browsers/safari:15.0",
"port": "4444",
"path": "/"
}
}
}
}
This is not a real Safari, but browser engine is the same and it works in Docker.

Related

Selenium: Using a Chrome Profile for Remote Webdriver: unknown error: cannot create default profile directory

Using ChromeDriver v102 (since there's a current bug open for v103 https://bugs.chromium.org/p/chromedriver/issues/detail?id=4121)
I get the error (full log information listed below):
Response code 500. Message: unknown error: cannot create default profile directory
when I run ChromeDriver remotely on the selenium node grid.
I am able to use a specific chrome profile when running the ChromeDriver locally. The driver for Firefox also works remotely, so I have to conclude that this is a "remote ChromeDriver" issue.
I download the chrome profile from the cloud into my current working directory. The directory is detected/located in my code.
There are no spaces in my path to the profile directory. The chrome profile only contains essential files I want to keep.
save_file_list = ["Bookmarks", "History", "History-journal", "Cookies", "Cookies-Journal", "Favicons", "Favicons-journal"]
When I use the ChromeDriver locally, I download the chrome profile, it loads the essential files and the driver creates the rest on its own. The same code works (and runs in an executable) when I run it on windows and mac machines.
However, this fails to work at all when using the remote driver. The remote driver works perfectly when I do not use a specific user-data-dir. It even works using an authenticated proxy. Therefore there are no issues with my connection. The code fails in both cases: when I use a virtual environment to run the code and when I run a docker image. Therefore I know it's not a docker issue.
This is the code for loading a chrome profile to my chrome options:
def add_profile(self, chrome_options):
if self.download_profile():
arg = f'--user-data-dir={os.getcwd()}/{self.profile_path}'
logging.info(f'Adding arg: {arg}')
chrome_options.add_argument(arg)
logging.info("Successfully added profile to chrome driver.")
return chrome_options
def setup_chrome(self) -> webdriver.Remote:
prefs = {
"credentials_enable_service": False,
"profile.password_manager_enabled": False,
}
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--enable-javascript")
chrome_options.add_argument("--disable-blink-features=AutomationControlled")
chrome_options.add_experimental_option("useAutomationExtension", False)
chrome_options.add_experimental_option("excludeSwitches", ["enable-automation"])
chrome_options.add_experimental_option("prefs", prefs)
chrome_options = self.proxy.add_proxy_plugin(chrome_options, use_proxy=True)
chrome_options = self.chrome_profile.add_profile(chrome_options) #currently not working
capabilities = {
"browserName": "chrome",
"chromeOptions": {
"useAutomationExtension": False,
"forceDevToolsScreenshot": True,
"args": ["--start-maximized", "--disable-infobars"],
},
}
remote_driver_host = os.environ.get("SELENIUM_URL")
logging.info("Setting up remote connection")
try:
selenium_connection = RemoteConnectionV2(
remote_driver_host, keep_alive=False
)
selenium_connection.set_remote_connection_authentication_headers()
driver = webdriver.Remote(
command_executor=selenium_connection, # for prod
# command_executor="http://localhost:4444/wd/hub", # for local development
desired_capabilities=capabilities,
options=chrome_options,
keep_alive=True,
)
logging.info("SUCCESS: created remote chrome using connection")
except Exception as ex:
logging.error(f"Failed to initiate Chrome browser: {ex}")
raise
try:
driver.get("https://www.google.com")
except Exception as e:
logging.error(f"Failed to connect using proxy: {e}")
return driver
This is the log:
27-Jun-22 10:04:53 AM EDT | INFO | SUCCESS: downloaded proxy assignment:
27-Jun-22 10:04:54 AM EDT | INFO | Successfully downloaded & extracted _zGF_23_CHROME_PROFILE.
27-Jun-22 10:04:54 AM EDT | INFO | Adding arg: --user-data-dir=/Users/<myuser>/Repos<my-repo>/_zGF_23_CHROME_PROFILE
27-Jun-22 10:04:54 AM EDT | INFO | Successfully added profile to chrome driver.
27-Jun-22 10:04:54 AM EDT | INFO | Setting up remote connection
[Authentication] No identity token was found in the environment. Requesting a new one.
[Authentication] An identity token found successfully.
27-Jun-22 10:04:55 AM EDT | ERROR | Failed to initiate Chrome browser: Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: cannot create default profile directory
Build info: version: '4.2.2', revision: '683ccb65d6'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '11.0.15'
Driver info: driver.version: unknown
Build info: version: '4.2.2', revision: '683ccb65d6'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '11.0.15'
Driver info: driver.version: unknown
Stacktrace:
at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply (DriverServiceSessionFactory.java:194)
at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply (DriverServiceSessionFactory.java:67)
at org.openqa.selenium.grid.node.local.SessionSlot.apply (SessionSlot.java:145)
at org.openqa.selenium.grid.node.local.LocalNode.newSession (LocalNode.java:362)
at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession (LocalDistributor.java:618)
at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession (LocalDistributor.java:544)
at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest (LocalDistributor.java:791)
at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1 (LocalDistributor.java:752)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
at java.lang.Thread.run (Thread.java:829)
27-Jun-22 10:04:55 AM EDT | ERROR | Message: Could not start a new session. Error while creating session with the driver service. Stopping driver service: Could not start a new session. Response code 500. Message: unknown error: cannot create default profile directory
Build info: version: '4.2.2', revision: '683ccb65d6'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '11.0.15'
Driver info: driver.version: unknown
Build info: version: '4.2.2', revision: '683ccb65d6'
System info: host: 'localhost', ip: '127.0.0.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0', java.version: '11.0.15'
Driver info: driver.version: unknown
Stacktrace:
at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply (DriverServiceSessionFactory.java:194)
at org.openqa.selenium.grid.node.config.DriverServiceSessionFactory.apply (DriverServiceSessionFactory.java:67)
at org.openqa.selenium.grid.node.local.SessionSlot.apply (SessionSlot.java:145)
at org.openqa.selenium.grid.node.local.LocalNode.newSession (LocalNode.java:362)
at org.openqa.selenium.grid.distributor.local.LocalDistributor.startSession (LocalDistributor.java:618)
at org.openqa.selenium.grid.distributor.local.LocalDistributor.newSession (LocalDistributor.java:544)
at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.handleNewSessionRequest (LocalDistributor.java:791)
at org.openqa.selenium.grid.distributor.local.LocalDistributor$NewSessionRunnable.lambda$run$1 (LocalDistributor.java:752)
at java.util.concurrent.ThreadPoolExecutor.runWorker (ThreadPoolExecutor.java:1128)
at java.util.concurrent.ThreadPoolExecutor$Worker.run (ThreadPoolExecutor.java:628)
at java.lang.Thread.run (Thread.java:829)

Always getting a "Failed: sendKeysToActiveElement" error while working on any of the keyboard actions of the actions class in protractor

I am always getting a "Failed: sendKeysToActiveElement" error while working on any of the keyboard actions of the actions class in protractor.
Below is my code -
it(' Tests to handle keyboard actions in Protractor ', async () => {
browser.manage().timeouts().implicitlyWait(15000);
browser.get("https://letcode.in/selectable")
browser.sleep(5000)
let elem_1 = element(by.xpath("(//h3[#id='clour'])[2]"))
let elem_2 = element(by.xpath("(//h3[#id='clour'])[4]"))
let elem_3 = element(by.xpath("(//h3[#id='clour'])[5]"))
let elem_4 = element(by.xpath("(//h3[#id='clour'])[9]"))
await browser.actions()
.click(await elem_1.getWebElement())
.keyDown(protractor.Key.CONTROL)
.click(await elem_2.getWebElement())
.keyUp(protractor.Key.CONTROL)
.perform();
});
My conf.js -
require("babel-register")({
presets: ["es2015"]
});
exports.config = {
framework: 'jasmine',
SELENIUM_PROMISE_MANAGER: true,
specs: ['selectMultiElement.js'],
capabilities: {
'browserName': 'chrome',
'chromeOptions': {
'args': ['show-fps-counter=true', '--window-size=1920x1280']
}
}
};
I am getting the error as -
UnsupportedOperationError: sendKeysToActiveElement
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:53'
System info: host: 'LAPTOP-HGJU6DES', ip: '192.168.1.6', os.name: 'Windows 11', os.arch: 'amd64', os.version: '10.0', java.version: '18.0.1.1'
Driver info: driver.version: unknown
Can anyone suggest what can be the solution of this error please.
I am using chrome 102 version.
I tried adding 'w3c': false in chromeOptions but that also showed some different error. Running the code with this argument it is opening 3 instances of the chromedriver but not being able to proceed with any command in the script thus eventually failing the script.
Changing the framework from jasmine to jasmine2 worked for me.

Selenium GeckoDriver with Protractor: "Failed: Timed out"

My automation test suite uses Selenium WebDriver with Protractor and Jasmine to run against a variety of browsers. When using GeckoDriver to run the tests on Firefox, I am intermittently getting an error message that just says "Failed: Timed out":
. ✓ WHEN I visit the favorites page
. ✓ THEN it should say I havent added anything
F ✗ WHEN I open the inspirations page
- Failed: Timed out
Build info: version: '3.8.1', revision: '6e95a6684b', time: '2017-12-01T19:05:32.194Z'
System info: host: 'admins-MacBook-Pro-3.local', ip: 'fe80:0:0:0:10a7:9b8d:6ff5:f46%en0', os.name: 'Mac OS X', os.arch: 'x86_64', os.version: '10.12.6', java.version: '1.8.0_144'
Driver info: driver.version: unknown
F ✗ AND I click on an inspiration preview pane to open an inspiration
I have tried padding it with hard-coded sleep on either side, and I've searched for other errors, but everything else I can find in regards to Protractor timeouts is for other errors that have some kind of a description about what is actually timing out.
Has anyone seen JUST the message "Failed: Timed out" here who can help determine what might be timing out?
As requested, here is the gulp task that kicks off my protractor:
gulp.task('test-frontend-firefox', 'Run feature tests locally', function() {
gulp.src(['test/feature/**/*.spec.js'])
.pipe(protractor({
configFile: __dirname + '/../test/protractor_local_ff.conf.js',
args: ['--baseUrl', 'http://localhost:9099'],
}));
});
And here is protractor_local_ff.conf.js as referenced by the gulp task:
var private_config = require('./private.conf.js');
var golden_config = require('./golden.conf.js');
exports.config = {
params: {
private: private_config,
golden: golden_config,
localhost: true
},
onPrepare: function(){
var SpecReporter = require('jasmine-spec-reporter').SpecReporter;
jasmine.getEnv().addReporter(new SpecReporter({displayStacktrace: 'all'}));
},
framework: 'jasmine2',
// seleniumAddress: 'http://hub-cloud.browserstack.com/wd/hub',
seleniumAddress: 'http://localhost:4444/wd/hub',
capabilities: {
'browserName': 'firefox'
}
};
As you can see, it's set up to be able to run against the hosted app in either browserstack or on my localhost, but the error gets thrown intermittently in either environment.

Unable to find page elements with Behat / Mink using Selenium 3.5.x

I am working on setting up behavioral tests for our current website. I have used Behat in the past with Selenium standalone server and now have updated to the latest Behat 3 and Selenium 3.5. I am having a multitude of issues though. Using Selenium 3.5 I cannot get xpath selectors to work at all. It is not able to find elements by id, name, class etc. With Selenium 3.4.x it seems to work fine but I cannot get button presses to work. I receive this error:
Then I click button "loginBtn" # FeatureContext::iClickButton()
mouseMoveTo
Build info: version: '3.4.0', revision: 'unknown', time: 'unknown'
System info: host: 'matt-VirtualBox', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-59-generic', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver (WebDriver\Exception\UnknownCommand)
This seems to be something that was fixed in 3.5.x with enablePassThrough set to true. Here is my behat.yml configuration.
default:
suites:
default:
contexts:
- FeatureContext:
screenshots_path: '%paths.base%/screenshots/firefox/'
extensions:
Behat\MinkExtension:
base_url: 'http://localhost:8080/customer_portal/'
default_session: selenium2
browser_name: 'firefox'
selenium2:
browser: 'firefox'
capabilities:
browserName: 'firefox'
browser: 'firefox'
version: ''
wd_host: 'localhost:5555/wd/hub'
And inside of my composer.json file
{
"require": {
"behat/behat": "3.*#stable",
"behat/mink": "1.7.*#stable",
"behat/mink-selenium2-driver": "#stable",
"behat/mink-goutte-driver": "#stable",
"behat/mink-extension": "#stable",
"phpmd/phpmd" : "#stable"
},
"config": {
"bin-dir": "bin/"
}
}
I am using Firefox 55 and geckodriver v18. Has anyone successfully configured selenium to work with Behat 3 and Firefox?
It seems to be an issue from Selenium. I also have the issue when working with FF and could not get the Element clicked.
mouseMoveTo error is well known issue when using selenium3. This error happens only for firefox browser with gecko driver. To fix this issue you can use chrome or update the MinkSelenium2Driver library. Should be master branch of MinkSelenium2Driver which requires behat/mink: ~1.7#dev. Here is the point of the problem MinkSelenium2Driver So if its ok for you to use all the latest behat versions, then composer.json could looks like this:
"require": {
"behat/behat": "v3.3.1",
"behat/mink": "v1.7.1",
"behat/mink-extension": "v2.2",
"behat/mink-selenium2-driver": "dev-master",
}

Runnig selenium Grid

I am trying to run a test using the selenium server which will enable cross browser testing, but I'm getting this error
I have downloaded the standalone server and ran it through comand prompt and got a grid console such as the image file attached and my guess is only webdriver part is enabled and remote control part is not if so PLease guid me on how to solve this [Grid console][1]
this is the error
FAILED: test
org.openqa.selenium.WebDriverException: 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
Command duration or timeout: 256 milliseconds
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'AKHIL-PC', ip: '192.158.0.29', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_131'
Driver info: driver.version: RemoteWebDriver
The error suggests that you are missing chrome driver. did you download the chrome driver form here?
Did you add the chrome driver to your path variable
In Windows, goto System -> Advanced System Settings -> Advanced (Tab) -> Environment Variables
Under System variables, scroll to the Variable named Path -> Edit… (button) -> Variable value ->
Scroll to the end of the field, add a semicolon and append the local path of chromedriver.exe to the
end of the value field. Click OK:
To verify, open the Command Line (Run cmd.exe) -> Type chromedriver ->Hit Enter -> ChromeDriver
Also, restart the selenium standalone hubs and nodes
Let me know if it works
EDIT:
And if you configure your node via a xml file like:
{
"capabilities":
[
{
"browserName": "chrome",
"platform": "WINDOWS",
"maxInstances": 5,
"seleniumProtocol": "WebDriver",
"webdriver.chrome.driver": "C:/Selenium/drivers/chromedriver.exe",
"binary":"C:/Program Files/Google/Chrome/Application/chrome.exe"
}
"proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
"maxSession": 5,
"port": 5555,
"register": true,
"registerCycle": 5000,
"hub": "<address to hub>",
"nodeStatusCheckTimeout": 5000,
"nodePolling": 5000,
"role": "node",
"unregisterIfStillDownAfter": 60000,
"downPollingLimit": 2,
"debug": false,
"servlets" : [],
"withoutServlets": [],
"custom": {}
}
Change the webdriver.chrome.driver and binary to your own path.
and the to your hub url
And start your node via:
java -jar selenium-server-standalone-<version>.jar -role node -nodeConfig nodeConfig.json