Avoid invalid certificate warning while testing using self-signed or invalid certificates
Whenever you work with self-signed certificates or some server with a stale or untrusted certificate, most modern browsers display a security warning or invalid certificate errors.
To avoid these warnings and errors while running your automated tests on BrowserStack, use the following capability.
You can use either Selenium 4 or Selenium Legacy JSON to organize your tests.
BrowserStack SDK is a plug-n-play solution that takes care of all the integration steps for you. Using the BrowserStack SDK is the recommended integration method for your project. To know more, visit the SDK core concepts page.
# Accept any valid/invalid certificates
capabilities ={'acceptSslCerts':True}
# Accept any valid or invalid certificates
caps =Selenium::WebDriver::Remote::Capabilities.new
caps["acceptSslCerts"]="true"
While testing on the Safari browser or on iOS devices, if you want to navigate to a page in the middle of the test which has an invalid certificate, you have to additionally use the acceptSsl JavascriptExecutor capability as shown below.
JavascriptExecutor for Safari browser and iOS devices
This section is only required if your are testing on Safari or iOS devices and navigating to a URL with invalid certificate in the middle of the test through navigation commands such as click action, Javascript navigation, etc. Under such scenario you have to use both the capability explained above and the Javascript executor shown below.
This JavascriptExecutor code must be executed after the stale/untrusted certificate webpage is loaded.
Following is the code snippet to use JavascriptExecutor to accept insecure certificates on Safari browser and on iOS devices: