How to use setBrowserName method of org.openqa.selenium.remote.DesiredCapabilities class

Best Selenium code snippet using org.openqa.selenium.remote.DesiredCapabilities.setBrowserName

Source:BrowserControl.java Github

copy

Full Screen

...75 return new RemoteWebDriver(grid.hub, get_grid_capabilities(browser));76 }77 private DesiredCapabilities get_grid_capabilities(TestConfig.Browser browser) {78 DesiredCapabilities desiredCapabilities = new DesiredCapabilities();79 desiredCapabilities.setBrowserName("marionette");80 switch (browser) {81 case CHROME:82 desiredCapabilities.setBrowserName("chrome");83 case FIREFOX:84 desiredCapabilities.setCapability("marionette", false);85 desiredCapabilities.setBrowserName("firefox");86 case IE:87 desiredCapabilities.setBrowserName("internet explore");88 case SAFARI:89 desiredCapabilities.setBrowserName("safari");90 case EDGE:91 desiredCapabilities.setBrowserName("edge");92 default:93 desiredCapabilities.setBrowserName("chrome");94 }95 return desiredCapabilities;96 }97 Capabilities createCapabilities() {98 DesiredCapabilities capabilities = new DesiredCapabilities();99 // capabilities.setCapability("javascriptEnabled", "true");100 capabilities.setBrowserName("marionette");101 return capabilities;102 }103 private DesiredCapabilities get_bs_capabilities(String testName) {104 DesiredCapabilities capabilities = new DesiredCapabilities();105 capabilities.setCapability("project", System.getProperty("bsProject"));106 capabilities.setCapability("build", System.getProperty("bsBuild") + " Git branch: " + System.getProperty("bsName"));107 capabilities.setCapability("name", testName);108 capabilities.setCapability("browser", System.getProperty("bsBrowser"));109 capabilities.setCapability("browser_version", System.getProperty("bsBrowserVersion"));110 capabilities.setCapability("os", System.getProperty("bsOs"));111 capabilities.setCapability("os_version", System.getProperty("bsOsVersion"));112 capabilities.setCapability("resolution", System.getProperty("bsResolution"));113 capabilities.setCapability("acceptSslCerts", "true");114 capabilities.setCapability("browserstack.debug", "true");...

Full Screen

Full Screen

Source:RemoteWebDriverProvider.java Github

copy

Full Screen

...30 return driver;31 }32 private RemoteWebDriver createFirefoxDriver() {33 DesiredCapabilities capabilities = createCommonCapabilities();34 capabilities.setBrowserName(Configuration.browser);35 if (!StringUtils.isEmpty(Configuration.firefoxVersion)) {36 capabilities.setVersion(Configuration.firefoxVersion);37 log.info("Configuration.browser.version=" + Configuration.firefoxVersion);38 }39 if (Configuration.marionette) {40 capabilities.setCapability("marionette", true);41 }42 else {43 capabilities.setCapability("marionette", false);44 }45 return new RemoteWebDriver(Configuration.gridUrl, capabilities);46 }47 private RemoteWebDriver createChromeDriver() {48 DesiredCapabilities capabilities = createCommonCapabilities();49 ChromeOptions options = new ChromeOptions();50 if (!StringUtils.isEmpty(Configuration.chromeVersion)) {51 capabilities.setVersion(Configuration.chromeVersion);52 log.info("Configuration.browser.version=" + Configuration.chromeVersion);53 }54 options.addArguments("--ignore-certificate-errors");55 if (Configuration.browserStartMaximized) {56 options.addArguments("--start-maximized");57 }58 capabilities.setBrowserName(Configuration.browser);59 capabilities.setCapability(ChromeOptions.CAPABILITY, options);60 return new RemoteWebDriver(Configuration.gridUrl, capabilities);61 }62 private RemoteWebDriver createInternetExplorerDriver() {63 DesiredCapabilities capabilities = createCommonCapabilities();64 capabilities.setBrowserName(Configuration.browser);65 capabilities.setBrowserName("internet explorer");66 capabilities.setCapability("ie.forceCreateProcessApi", true);67 capabilities.setCapability("ie.browserCommandLineSwitches", "-private");68 capabilities.setCapability("ie.ensureCleanSession", true);69 return new RemoteWebDriver(Configuration.gridUrl, capabilities);70 }71 private RemoteWebDriver createEdgeDriver() {72 DesiredCapabilities capabilities = createCommonCapabilities();73 capabilities.setBrowserName("MicrosoftEdge");74 return new RemoteWebDriver(Configuration.gridUrl, capabilities);75 }76 private DesiredCapabilities createCommonCapabilities() {77 DesiredCapabilities capabilities = new DesiredCapabilities();78 if (!StringUtils.isEmpty(Configuration.proxyUrl)){79 capabilities.setCapability(PROXY, createProxy());80 log.info("Configuration.proxyUrl=" + Configuration.proxyUrl);81 }82 if (Configuration.browserPlatform != null) {83 capabilities.setPlatform(Configuration.browserPlatform);84 log.info("Configuration.browser.platform=" + Configuration.browserPlatform);85 }86 if (Configuration.video && !Configuration.INTERNET_EXPLORER.equalsIgnoreCase(Configuration.browser)){87 capabilities.setCapability("nodeType", "video");...

Full Screen

Full Screen

Source:DriverFactoryTest.java Github

copy

Full Screen

...30 assertTrue(factory.hasMappingFor(capabilities));31 }32 public void testShouldReturnMatchIfOneFieldMatchesAndOnlyOneDriverIsRegistered() {33 DesiredCapabilities template = new DesiredCapabilities();34 template.setBrowserName("foo");35 template.setVersion("1.0");36 template.setPlatform(Platform.getCurrent());37 factory.registerDriver(template, DriverOne.class);38 DesiredCapabilities example = new DesiredCapabilities();39 example.setBrowserName(template.getBrowserName());40 Class<? extends WebDriver> result = factory.getBestMatchFor(example);41 assertEquals(DriverOne.class, result);42 }43 public void testShouldReturnDriverWhereTheMostCapabilitiesMatch() {44 DesiredCapabilities first = new DesiredCapabilities();45 first.setBrowserName("foo");46 first.setVersion("1.0");47 DesiredCapabilities second = new DesiredCapabilities();48 second.setBrowserName("bar"); // Different name49 second.setVersion("1.0");50 factory.registerDriver(first, DriverOne.class);51 factory.registerDriver(second, DriverTwo.class);52 DesiredCapabilities example = new DesiredCapabilities();53 example.setBrowserName("foo");54 Class<? extends WebDriver> result = factory.getBestMatchFor(example);55 assertEquals(DriverOne.class, result);56 example.setBrowserName("bar");57 result = factory.getBestMatchFor(example);58 assertEquals(DriverTwo.class, result);59 }60 61 public void testShouldReturnMostRecentlyAddedDriverWhenAllCapabilitiesAreEqual() {62 Capabilities capabilities = DesiredCapabilities.firefox();63 factory.registerDriver(capabilities, DriverOne.class);64 factory.registerDriver(capabilities, DriverTwo.class);65 Class<? extends WebDriver> result = factory.getBestMatchFor(capabilities);66 assertEquals(DriverTwo.class, result);67 }68 public void testShouldConsiderJavascriptCapabilities() {69 DesiredCapabilities nojavascript = new DesiredCapabilities("browser", "v1", Platform.LINUX);70 DesiredCapabilities javascript = new DesiredCapabilities("browser", "v1", Platform.LINUX);...

Full Screen

Full Screen

Source:DockerExample.java Github

copy

Full Screen

...19// System.out.println(DesiredCapabilities.chrome().getBrowserName());20// System.out.println(DesiredCapabilities.firefox().getBrowserName());21 22 //This is how you can set browser. The parameter is the output of above commands.23 //capabilities.setBrowserName("chrome");24 //capabilities.setBrowserName("internet explorer");25 26 27 /* Remote Web Driver is used to28 * - execute tests on a different machine29 * - execute tests on a different browser (using user input)30 * - execute tests in parallel (on multiple machines)31 */ 32 33 /*We first need to start the Remote Server on the execution machine by executing this command - 34 * From command line: 35 *36 * java -jar selenium-server-standalone-2.41.0.jar37 *38 *39 * We need to pass the location of the remote Web Driver HUB to the driver instance. 40 * If your Hub is on the same machine, then you can use localhost. Otherwise, the machine IP41 * Then You need to start the node by using the following command42 * 43 * 44 * java -jar selenium-server-standalone-2.41.0.jar -role node -hub http://localhost:4444/grid/register45 * 46 * 47 * Please use the correct jar file name and make sure that the command is being executed from the 48 * command prompt and inside the directory where your selenium standalone jar is present.49 */50 51 //capabilities.setBrowserName("chrome");52 //capabilities.setBrowserName(BrowserType.CHROME);53 //capabilities.setBrowserName(BrowserType.IEXPLORE);54 capabilities.setBrowserName(BrowserType.FIREFOX);55 56 WebDriver driver = new RemoteWebDriver(57 new URL("http://c14735bc9c10.ngrok.io/wd/hub"), 58 capabilities59 );60 //And now use it61 62 driver.get("http://www.flipkart.com");63 System.out.println(driver.getTitle());64 // Query the driver to find out more information65 Capabilities actualCapabilities = ((RemoteWebDriver) driver).getCapabilities();66 System.out.println(actualCapabilities.getBrowserName());67 System.out.println(actualCapabilities.getVersion());68 System.out.println(actualCapabilities.isJavascriptEnabled());69 System.out.println(actualCapabilities.getPlatform()); 70 71 driver.quit();72 }73 }74 //Another way of Setting browser75 //capabilities.setBrowserName(BrowserType.CHROME);76 //capabilities.setBrowserName(BrowserType.IEXPLORE);77 //capabilities.setBrowserName(BrowserType.FIREFOX);78 //If I set platform to Windows or XP or VISTA, without specifying the browser, IE opens. Otherwise Firefox opens79 //capabilities.setPlatform(Platform.XP);80 //capabilities.setPlatform(Platform.VISTA);81 //capabilities.setPlatform(Platform.WINDOWS);82 //capabilities.setPlatform(Platform.extractFromSysProperty("XP"));83 //System.out.println(capabilities.getCapability(CapabilityType.PLATFORM));...

Full Screen

Full Screen

Source:RunTestInDockerViaSelenium.java Github

copy

Full Screen

...13 @Test14 public void openGoogle() throws MalformedURLException, InterruptedException {15 WebDriverManager.chromedriver().setup();16 DesiredCapabilities cap = new DesiredCapabilities();17 cap.setBrowserName(BrowserType.CHROME);18 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4446/wd/hub"),cap);19 String baseurl ="https://www.google.com/";20 driver.get(baseurl);21 driver.manage().window().maximize();22 System.out.println("Test1");23 Thread.sleep(10000);24 driver.quit();25 }26 @Test27 public void openGoogleSecond() throws MalformedURLException, InterruptedException {28 WebDriverManager.chromedriver().setup();29 DesiredCapabilities cap = new DesiredCapabilities();30 cap.setBrowserName(BrowserType.FIREFOX);31 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4449/wd/hub"),cap);32 String baseurl ="https://www.google.com/";33 driver.get(baseurl);34 driver.manage().window().maximize();35 System.out.println("Test2");36 Thread.sleep(10000);37 driver.quit();38 }39 @Test(dataProvider = "getData")40 public void DataProviderUsed(String browser) throws MalformedURLException, InterruptedException {41 WebDriverManager.chromedriver().setup();42 DesiredCapabilities cap = new DesiredCapabilities();43 cap.setBrowserName(browser);44 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4448/wd/hub"),cap);45 String baseurl ="https://www.google.com/";46 driver.get(baseurl);47 driver.manage().window().maximize();48 System.out.println("Test2");49 Thread.sleep(10000);50 driver.quit();51 }52 @DataProvider(parallel=true)53 public Object[][] getData()54 {55 return new Object[][]56 {{"chrome"},{"chrome"},{"firefox"},{"firefox"}};57 }58 @Test(dataProvider = "getData2")59 public void DataProviderUsedWithVersion(String browser,String version) throws MalformedURLException, InterruptedException {60 WebDriverManager.chromedriver().setup();61 DesiredCapabilities cap = new DesiredCapabilities();62 cap.setBrowserName(browser);63 cap.setVersion(version);64 WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4445/wd/hub"),cap);65 String baseurl ="https://www.google.com/";66 driver.get(baseurl);67 driver.manage().window().maximize();68 System.out.println("Test2");69 Thread.sleep(10000);70 driver.quit();71 }72 @DataProvider(parallel=true)73 public Object[][] getData2()74 {75 return new Object[][]76 {{"chrome","92.0.4515.107"},{"chrome","79.0.3945.117"},{"firefox","90.0.2"},{"firefox","90.0.2"}};...

Full Screen

Full Screen

Source:WebDriver.java Github

copy

Full Screen

...14 public WebDriver(){}15 @Deprecated16 protected DesiredCapabilities createChromeDesiredCapabilities() {17 DesiredCapabilities desiredCapabilities = DesiredCapabilities.chrome();18 desiredCapabilities.setBrowserName("chrome");19 return desiredCapabilities;20 }21 protected ChromeOptions createChromeOptionsCapabilities() {22 ChromeOptions cap = new ChromeOptions();23 cap.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);24 return cap;25 }26 @Deprecated27 protected DesiredCapabilities createFirefoxDesiredCapabilities() {28 DesiredCapabilities desiredCapabilities = DesiredCapabilities.firefox();29 desiredCapabilities.setBrowserName("firefox");30 return desiredCapabilities;31 }32 protected FirefoxOptions createFirefoxOptionsCapabilities() {33 FirefoxOptions cap = new FirefoxOptions();34 cap.setCapability(CapabilityType.BROWSER_NAME, BrowserType.FIREFOX);35 return cap;36 }37 public void tearDown(){38 if(driver != null){39 System.out.println("closing the driver...");40 driver.quit();41 System.out.println("driver closed");42 driver= null;43 }...

Full Screen

Full Screen

Source:BaseTest.java Github

copy

Full Screen

...15 public void openBrowser(String browser) {16 DesiredCapabilities cap = null;17 if(browser.equals("Mozilla")) {18 cap = new DesiredCapabilities();19 cap.setBrowserName("firefox");20 cap.setPlatform(Platform.WINDOWS);21 }else if(browser.equals("Chrome")) {22 cap = new DesiredCapabilities();23 cap.setBrowserName("chrome");24 cap.setPlatform(Platform.WINDOWS);25 }else if(browser.equals("IE")) {26 cap = new DesiredCapabilities();27 cap.setBrowserName("iexplore");28 cap.setPlatform(Platform.WINDOWS);29 }30 31 try {32 driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), cap);33 } catch (MalformedURLException e) {34 // TODO Auto-generated catch block35 e.printStackTrace();36 }37 }38 39 @AfterTest40 public void quit() {41 if(driver!=null)...

Full Screen

Full Screen

Source:GridConnection.java Github

copy

Full Screen

...22 e.printStackTrace();23 }24 if(browser.equals("chrome")) {25 capability = DesiredCapabilities.chrome();26 capability.setBrowserName(browser);27 }28 else if(browser.equals("firefox")) {29 capability = DesiredCapabilities.firefox();30 capability.setBrowserName(browser);31 }32 else if(browser.equals("internet explorer")) {33 capability = DesiredCapabilities.internetExplorer();34 capability.setBrowserName(browser);35 }36 capability.setPlatform(Platform.WINDOWS);37 driver = new RemoteWebDriver(url, capability);38 return driver;39 40 }41} ...

Full Screen

Full Screen

setBrowserName

Using AI Code Generation

copy

Full Screen

1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setBrowserName("chrome");3DesiredCapabilities capabilities = new DesiredCapabilities();4capabilities.setCapability("browserName", "chrome");5DesiredCapabilities capabilities = new DesiredCapabilities();6capabilities.setCapability(CapabilityType.BROWSER_NAME, "chrome");7DesiredCapabilities capabilities = new DesiredCapabilities();8capabilities.setCapability(ChromeOptions.CAPABILITY, "chrome");9DesiredCapabilities capabilities = new DesiredCapabilities();10capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);11DesiredCapabilities capabilities = new DesiredCapabilities();12capabilities.setCapability(CapabilityType.BROWSER_NAME, BrowserType.CHROME);13DesiredCapabilities capabilities = new DesiredCapabilities();14capabilities.setCapability("browserName", BrowserType.CHROME);15DesiredCapabilities capabilities = new DesiredCapabilities();16capabilities.setCapability("browserName", BrowserType.CHROME);17DesiredCapabilities capabilities = new DesiredCapabilities();18capabilities.setCapability("browserName", BrowserType.CHROME);19DesiredCapabilities capabilities = new DesiredCapabilities();20capabilities.setCapability("browserName", BrowserType.CHROME);21DesiredCapabilities capabilities = new DesiredCapabilities();22capabilities.setCapability("browserName", BrowserType.CHROME);23DesiredCapabilities capabilities = new DesiredCapabilities();24capabilities.setCapability("browserName",

Full Screen

Full Screen

setBrowserName

Using AI Code Generation

copy

Full Screen

1DesiredCapabilities capabilities = new DesiredCapabilities();2capabilities.setBrowserName("firefox");3DesiredCapabilities capabilities = new DesiredCapabilities();4capabilities.setBrowserName("firefox");5DesiredCapabilities capabilities = new DesiredCapabilities();6capabilities.setBrowserName("firefox");7DesiredCapabilities capabilities = new DesiredCapabilities();8capabilities.setBrowserName("firefox");9DesiredCapabilities capabilities = new DesiredCapabilities();10capabilities.setBrowserName("firefox");11DesiredCapabilities capabilities = new DesiredCapabilities();12capabilities.setBrowserName("firefox");13DesiredCapabilities capabilities = new DesiredCapabilities();14capabilities.setBrowserName("firefox");15DesiredCapabilities capabilities = new DesiredCapabilities();16capabilities.setBrowserName("firefox");17DesiredCapabilities capabilities = new DesiredCapabilities();18capabilities.setBrowserName("firefox");19DesiredCapabilities capabilities = new DesiredCapabilities();20capabilities.setBrowserName("firefox");

Full Screen

Full Screen

setBrowserName

Using AI Code Generation

copy

Full Screen

1DesiredCapabilities cap = DesiredCapabilities.firefox();2cap.setBrowserName("firefox");3cap.setVersion("3.6.8");4cap.setPlatform(Platform.WINDOWS);5DesiredCapabilities cap = DesiredCapabilities.firefox();6cap.setCapability("browserName", "firefox");7cap.setCapability("version", "3.6.8");8cap.setCapability("platform", Platform.WINDOWS);9DesiredCapabilities cap = DesiredCapabilities.firefox();10cap.setCapability(CapabilityType.BROWSER_NAME, "firefox");11cap.setCapability(CapabilityType.VERSION, "3.6.8");12cap.setCapability(CapabilityType.PLATFORM, Platform.WINDOWS);13DesiredCapabilities cap = DesiredCapabilities.firefox();14cap.setCapability("browserName", "firefox");15cap.setCapability("version", "3.6.8");16cap.setCapability("platform", Platform.WINDOWS);17DesiredCapabilities cap = DesiredCapabilities.firefox();18cap.setCapability(CapabilityType.BROWSER_NAME, "firefox");19cap.setCapability(CapabilityType.VERSION, "3.6.8");20cap.setCapability(CapabilityType.PLATFORM, Platform.WINDOWS);21DesiredCapabilities cap = DesiredCapabilities.firefox();22cap.setCapability("browserName", "firefox");23cap.setCapability("version", "3.6.8");24cap.setCapability("platform", Platform.WINDOWS);25DesiredCapabilities cap = DesiredCapabilities.firefox();26cap.setCapability(CapabilityType.BROWSER_NAME, "firefox");27cap.setCapability(CapabilityType.VERSION, "3.6.8");28cap.setCapability(CapabilityType.PLATFORM, Platform.WINDOWS);29DesiredCapabilities cap = DesiredCapabilities.firefox();30cap.setCapability("browserName", "firefox");31cap.setCapability("version", "3.6.8");32cap.setCapability("platform", Platform.WINDOWS);

Full Screen

Full Screen

setBrowserName

Using AI Code Generation

copy

Full Screen

1package com.testautomation;2import org.openqa.selenium.WebDriver;3import org.openqa.selenium.chrome.ChromeDriver;4import org.openqa.selenium.remote.DesiredCapabilities;5public class DesiredCapabilitiesDemo {6public static void main(String[] args) {7 DesiredCapabilities capabilities = new DesiredCapabilities();8 capabilities.setBrowserName("chrome");9 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Nishant\\Desktop\\chromedriver.exe");10 WebDriver driver = new ChromeDriver(capabilities);11 driver.quit();12}13}142. Using setCapability() method of DesiredCapabilities class15public void setCapability(String capabilityName, Object value)16package com.testautomation;17import org.openqa.selenium.WebDriver;18import org.openqa.selenium.chrome.ChromeDriver;19import org.openqa.selenium.remote.DesiredCapabilities;20public class DesiredCapabilitiesDemo {21public static void main(String[] args) {22 DesiredCapabilities capabilities = new DesiredCapabilities();23 capabilities.setCapability("browserName", "chrome");24 System.setProperty("webdriver.chrome.driver", "C:\\Users\\Nishant\\Desktop\\chromedriver.exe");25 WebDriver driver = new ChromeDriver(capabilities);26 driver.quit();27}28}

Full Screen

Full Screen

Selenium 4 Tutorial:

LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.

Chapters:

  1. Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.

  2. What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.

  3. Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.

  4. Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.

  5. How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.

  6. Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.

  7. Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.

Selenium 101 certifications:

LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.

Run Selenium automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful