PKI Certificate authentication using Selenium webdriver for test automation in python - python-3.x

I have UI application which for which I had build Test Automation Framework using Selenium Python Pytest Framework. When I launch web application, a pop window appears where I have to select valid PKI Test Certificate, after which only the application opens up. As this authentication pop-up is windows based and cannot be authenticated using selenium webdriver, can someone suggest any solution by which I can pass the .p12 certificate and password and the application can be accessed. I tried to use service_args in phantom js, which works very well.
def phantomJsDriver():
headlessDriver = webdriver.PhantomJS(executable_path='../drivers/phantomjs.exe', service_args=['--ignore-ssl-errors=true', '--ssl-client-certificate-file=<path of .pem file>', '--ssl-client-key-file=<path of key file>', '--ssl-client-key-passphrase=<passphrase>'])
headlessDriver.set_window_size(1280, 1024)
return headlessDriver
But same thing is not working in case of chrome or edge chromium. Can someone please provide any solution for this?

Related

UWP on RPi - Trying to Provision to Azure - How to get X.509 certificate

I'm working with a RPi/UWP program (works well) that is signed with out X.509 certificate.
I have no problems connecting to Azure IoT hub if I manually provision the connection, but as we intend to ship these by the 100s, if not thousands, obviously that won't work.
I've looked at the code examples of using the provisioning service, but all of them are in the emulation.
Looking at the code, you have to load your X.509 certificate
certificateCollection.Import(s_certificateFileName, certificatePassword, X509KeyStorageFlags.UserKeySet);
This is where I get lost - Where on the RPi IS the certificate to load?
Basically, I THINK I understand how to do this in a plain Win10 app, but when you get to UWP on the RPi (a 3B, as the 3B+ is not supported - probably have to switch to Core) . Anyone have some sample code, or can point me in the right direction?
This document provides an overview of the cryptography features available to UWP apps.
You can generate the certificate file and then copy or import it to the device. If you copy the certificate file to device, you need to add capabilities for accessing the file to your UWP app. Please refer to this topic in MSDN forum. Following code can be used to import the pfx certificate into your device and then load it from cert store.
Import:
StorageFolder certificatesFolder = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFolderAsync("Certificates");
StorageFile certificateFile = await certificatesFolder.GetFileAsync("ClientCertificate .pfx ");
IBuffer certificateBuffer = await FileIO.ReadBufferAsync(certificateFile);
string encodedCertificate = Windows.Security.Cryptography.CryptographicBuffer.EncodeToBase64String(certificateBuffer);
await CertificateEnrollmentManager.ImportPfxDataAsync(encodedCertificate, "password", ExportOption.NotExportable, KeyProtectionLevel.NoConsent, InstallOptions.None, "certificateOne");
Load:
CertificateQuery certQuery = new CertificateQuery();
certQuery.FriendlyName = "certificateOne";
IReadOnlyList<Certificate> certificates = await CertificateStores.FindAllAsync(certQuery);

How to automate file upload on browserstack using nightwatch node js

I am writing automation using Nightwatch node js. I have a test for uploading a file in my application and testing it locally works perfectly. However, when I test it using BrowserStack, BrowserStack cannot access the file in my local machine.
I have also tried setting FileDetector but it gives error saying setFileDetector is not a function on browser object.
I know this function is available for selenium driver object but I am javascript browser object for writing test scripts.
browser.setFileDetector(new remote.FileDetector());
I see that you want to perform the File Upload Operation for a file available on your local machine. You can review the link: https://www.browserstack.com/automate/node#enhancements-uploads-downloads for more details.

How can I tell Selenium Webdriver on Firefox Quantum to use a proxy with auth and port?

I have tried pretty much every way mentioned on SO and the docs and failed.
Specifically, I'm using WebdriverJS through Node.js.
I'd want a way to programatically make Firefox-Quantum use a proxy, which requires auth and port (i.e http://user:pass#host:port).
I don't mind to use an extension for this, but I don't know which one I could use for programmatic access.
I do not want a solution involving the authentication dialog popping up and asking for the auth.
I used to manage to do it on Firefox 56.0 using an extension called CloseProxy. (As per How to set proxy authentication (user & password) using python selenium)
However, CloseProxy is not supported on Firefox-Quantum.
This is my last attempt at this issue before resorting to going ahead and writing my own Webextension for this so I hope someone somewhere has the answer
Somethig like that should work:
var webdriver = require('selenium-webdriver'),
proxy = require('selenium-webdriver/proxy');
var driver = new webdriver.Builder()
.withCapabilities(webdriver.Capabilities.firefox())
.setProxy(proxy.manual({http: 'host:1234'}))
.build();
Actually there is a lot of info about this https://seleniumhq.github.io/selenium/docs/api/javascript/module/selenium-webdriver/proxy.html

How to access localStorage of a firefox browser via Python?

following case.
I have a python script that opens a firefox browser on windows which has a firefox addon installed that writes logs into the local storage.
Before I close the browser via python I would like to read out the log information out of the local storage of the firefox.
So how can I access the localStorage in the firefox?
Help very appreciated.
You will have to use PyXPCOM and the nsIDOMStorageManager interface.
Have a look at this tutorial to see how to use PyXPCOM.
You may start from this code (untested):
from xpcom import components
principal = (components.classes['#mozilla.org/scriptsecuritymanager;1']
.getService(components.interfaces.nsIScriptSecurityManager)
.getNoAppCodebasePrincipal(YOUR_URL))
dom_storage_manager = (components.classes['#mozilla.org/dom/localStorage-manager;1']
.getService(components.interfaces.nsIDOMStorageManager))
local_storage = dom_storage_manager.getLocalStorageForPrincipal(principal, YOUR_URL)

Setting up profile for invalid SSL Certificates using Cucumber and Capybara

-=UPDATE=-
The problem I was experiencing was a case where the certificate was valid, but the site was invalid for the certificate. Leaving the default settings (either providing a profile with the certificate default settings or using the standard :selenium driver in Capybara) worked for my case. I mistakingly thought I needed to modify my Firefox profile for the driver to work, this wasn't the case.
Removing the certificate settings from my custom profile fixed the issue. Thanks Jarib.
-=Original Question=-
I'm currently trying to setup my test browsers to ignore invalid SSL certificates when using Cucumber and Capybara. I have the following in my env.rb:
Capybara.register_driver :selenium_profile do |app|
profile = Selenium::WebDriver::Firefox::Profile.new
profile.secure_ssl = false
profile.assume_untrusted_certificate_issuer = false
Capybara::Selenium::Driver.new(app, :browser => :firefox, :profile => profile)
end
Capybara.configure do |config|
config.run_server = false
config.default_driver = :selenium_profile
config.default_wait_time = 15
end
The environment seems to be setup properly, and the testcase runs fine until I hit an invalid certificate.
Is there something I'm doing wrong in the code above? Is there another option (using script/code) to create a new profile that ignores certificates? I'm trying to do some black box testing on a qa site, so self signed certificates aren't really an option. Individual Firefox profiles aren't good since the code needs to be portable. Thoughts?
Environment:
OS X.7.3
Firefox 12.0
ruby-1.9.2
capybara (1.1.2 ruby, 0.4.1.2)
capybara-webkit (0.8.0)
cucumber (1.1.9)
selenium-webdriver (2.21.2)
Did you try without profile.assume_untrusted_certificate_issuer = false
and with profile.accept_untrusted_certs = True

Resources