1. How is the desired capability useful in terms of Selenium?
- A series of key-value pairs can be used to store information like the name and version of the browser, paths of browser drivers in the system, etc, to determine the browser’s behaviour at run-time.
- This feature is called the desired capability. It is highly useful during cross-browser testing or testing across different OS.
- DesiredCapabilities(String browser, String version, Platform platform)
- Handling SSL certs issues setAcceptInsecureCerts(boolean acceptInsecureCerts)
2. Explain the Desired Capabilities class
desired capabilities are a set of key-value pairs encoded in JSON objects. It defines basic requirements for testing such as operating systems, browser versions, browser information etc… DesiredCapabilities class has multiple methods to define properties based on the test requirements.
- getCapability();
- setCapability();
- getBrowserName();
- setBrowserName();
- getBrowserVersion();
- setBrowserVersion();
- getPlatform();
- setPlatform();
3. How to handle the HTTPS website in Selenium or how to accept the SSL untrusted connection?
- Some websites display warning messages like, the content is not trusted, there is a security threat in this page kind of message appears
- Some websites display a certificate warning
- Normally each browser has a set of Certified Authority certificates
- In that case, the web server needs to send a copy of the SSL certificate to our web browser. So our browser verifies the certificate then we can continue testing
- ChromeOptions class come into this place when handling SSL certificates.
- it provides methods like
setCapability(CapabilityType.ACCEPT_SSL_CERTS,true)
- Here we are ignoring the certificate errors, but need to be cautious when dealing with the production environment
- The below code is handling SSL certificate issues in the Chrome browser
- This code will help to accept all the certificates in Chrome and the user will not receive any SSL cert issues.
DesiredCapabilities handlSSLErr = DesiredCapabilities.chrome ()
handlSSLErr.setCapability (CapabilityType.ACCEPT_SSL_CERTS, true)
WebDriver driver = new ChromeDriver (handlSSLErr);
4. What is the usage of ChromeOptions()?
- It is a class in selenium
- We can configure various settings using ChromeOptions class
- setting browser window size
- disabling extensions
- run with headless mode
- Ignoring SSL certificate issues
- setting proxy
5.Write codes for the usage of methods in the ChromeOptions class
ChromeOptions options = new ChromeOptions();
options.addArguments("--window-size=1200,800");
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-extensions");
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
ChromeOptions options = new ChromeOptions();
options.addArguments("--ignore-certificate-errors");
ChromeOptions options = new ChromeOptions();
Proxy proxy = new Proxy();
proxy.setHttpProxy("proxy.example.com:8080");
options.setCapability("proxy", proxy);
getBrowserName()
getBrowserVersion()
getPlatformName()
ptions.addArguments(
"load-extension=/path/to/unpacked_extension",
"allow-outdated-plugins");
addExtensions(List<File> paths)
Adds a new Chrome extension to install on browser startup. Each path should specify a packed Chrome extension (CRX file).
6. Handle SSL certificate issues in Firefox
- Create new firefox profile FirefoxProfile profile = new FirefoxProfile();
- setAcceptUntrustedCeritifcates() method true
- setAssumeUntrustedCeritifcateIssuer() method false
- We can use FirefoxOptions class as well.
- It has inherited methods from Capabilities interface like getBrowserName(), getBrowserVersion(), getPlatformName()
- It has addArguments()method as well
ProfilesIni prof = new ProfilesIni()
FirefoxProfile ffProfile= prof.getProfile ("myProfile")
ffProfile.setAcceptUntrustedCertificates(true)
ffProfile.setAssumeUntrustedCertificateIssuer(false)
WebDriver driver = new FirefoxDriver (ffProfile)
7. What is Firefoxprofile class?
- It extends the Object class
8. Explain setAcceptUntrustedCertificate(Boolean boolean) method
Sets whether Firefox should accept SSL certificates which have expired, signed by an unknown authority or are generally untrusted.
9. Explain setAssumeUntrustedCertificateIssuer(Boolean boolean) method
By default, when accepting untrusted SSL certificates, assume that these certificates will come from an untrusted issuer or will be self-signed
10. Which common class can be used to handle SSL certificate issues and why?
- DesiredCapabilities
- ChromeOptions
- FireFoxOptions
- Since above all classes implement the Capabilities interface
No comments:
Post a Comment