# Desired Capabilities

Desired capabilities are used in Selenium to configure browser and device-specific options when requesting a session from a remote WebDriver. It falls under the topic of cross-browser testing.

<figure><img src="https://images.unsplash.com/photo-1519114563721-eb52c00b9129?crop=entropy&#x26;cs=srgb&#x26;fm=jpg&#x26;ixid=M3wxOTcwMjR8MHwxfHNlYXJjaHwyfHx4fGVufDB8fHx8MTY5MDc4MDk3OHww&#x26;ixlib=rb-4.0.3&#x26;q=85" alt=""><figcaption></figcaption></figure>

**What is Cross Browser Testing? 💻🌎**

Cross-browser testing is the practice of testing your website or application across different browsers, operating systems, and devices.

**Why is it Important? ✅**

* 👀 Users access your site on different browsers.
* 🤖 Rendering issues can occur on specific browsers.
* 🐛 Browser inconsistencies can cause bugs.
* 🏆 Ensures site works correctly everywhere.

**Common Browsers to Test 💻**

* 🦊 Firefox
* 🍎 Safari
* 💚 Chrome
* 🌏 Internet Explorer / Edge
* 🤖 Headless browsers

**Common Testing Strategies 🧪**

* 🔎 Manual testing on different browsers
* 🤖 Automated testing with multiple browsers
* ☁️ Use cloud based browser testing tools

**Key Benefits ✅**

* 🙅‍♂️ Avoid browser-specific bugs
* 💯 Ensure consistent experience
* 🏅 Improve quality
* 🛡️ Reduce technical debt
* 📈 Optimize conversion rates

Make sure to test across browsers for happy users everywhere! 😊🌎

## Some key points about desired capabilities:

* They are a set of key-value pairs that define configuration options for a browser or device when creating a remote WebDriver session.

### Commonly used methods of achieving desired capabilities

* `setBrowserName(String browserName)`sets the name of the browser to be used for the test.
* `setVersion(String version)`sets the version of the browser to be used for the test.
* `setPlatform(Platform platform)`sets the operating system to be used for the test.
* `setCapability(String key, String value)`sets a specific capability for the test.
* `setAcceptInsecureCerts(boolean acceptInsecureCerts)`sets whether to accept insecure SSL certificates.
* `setHeadless(boolean headless)`sets whether to run the browser in headless mode.
* `setProxy(Proxy proxy)`sets the proxy to be used for the test.
* `setPageLoadStrategy(PageLoadStrategy strategy)`sets the page load strategy for the test.
* `setUnhandledPromptBehaviour(UnhandledPromptBehaviour behaviour)`sets the behavior when an unhandled alert is encountered.
* `setJavascriptEnabled(boolean enable)`: Sets whether to enable JavaScript in the browser

Desired capabilities are passed to the WebDriver when creating a session:

```java
DesiredCapabilities = new DesiredCapabilities();
caps.setCapability(CapabilityType.BROWSER_NAME, "chrome");
caps.setCapability(CapabilityType.VERSION, "latest");

WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/"), caps); 
```

* They enable cross-browser testing by allowing you to switch the browser or device for your tests.
* Different WebDriver implementations require different desired capabilities.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://qatesting.gitbook.io/qa/automation-testing/flow/selenium/selenium-grid/desired-capabilities.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
