Site icon TestingDocs.com

Run test using RemoteWebDriver with Marionette

Introduction

In this post, we will run a sample test using RemoteWebDriver with Marionette. Earlier we have seen how to use Selenium Grid and setup Hub and Nodes Configuration.

Selenium Grid

https://www.testingdocs.com/what-is-selenium-grid/

Grid Configuration

https://www.testingdocs.com/selenium-grid-hub-and-nodes-configuration/

Another, pre-requisite for running the program is the grid setup. Hence, I assume hub and nodes are registered properly on the environment. Let’s start writing a sample program to launch Bing website using Selenium Grid with Marionette.

 

DesiredCapabilities

In addition, we will run a sample test case in one of the browser instances that is registered to the remote node. (  Also, we need to use RemoteWebDriver to invoke the browser instance. Furthermore, we need to configure correct DesiredCapabilities to set the browser and platform where the test to be executed.

To use Firefox with Selenium 3 we need to set system property and capability set to “marionette” true as shown below:

Setting DesiredCapabilities

DesiredCapabilities capabilities=DesiredCapabilities.firefox();
capabilities.setBrowserName("firefox");
capabilities.setCapability("marionette", true);
capabilities.setPlatform(Platform.WIN10);

 

RemoteWebDriver

Instantiating a remote driver with the desired capabilities as shown below:

driver = new RemoteWebDriver(new URL(“http://localhost:5555/wd/hub”), capabilities);

Sample Code Example:

public class MarionetteExample 
{
 WebDriver driver;
    
 @BeforeTest
  public void setConfig() throws MalformedURLException
  {
  System.setProperty("webdriver.gecko.driver", "C:\\testingdocs\\geckodriver.exe");
  DesiredCapabilities capabilities=DesiredCapabilities.firefox();
  capabilities.setBrowserName("firefox");
  capabilities.setCapability("marionette", true);
  capabilities.setPlatform(Platform.WIN10); 
  driver = new RemoteWebDriver(new URL("http://localhost:5555/wd/hub"),
 capabilities); 
  }
    
@Test
public void sampleTest()
    { 
  driver.get("https://www.bing.com");
  WebElement searchElement = driver.findElement(By.id("sb_form_q"));
  searchElement.sendKeys("hello");
  searchElement.submit();
  WebDriverWait wait = new WebDriverWait(driver, 60);
        wait.until(ExpectedConditions.titleContains("hello"));
   Assert.assertTrue(driver.getTitle().toLowerCase().
startsWith("hello".toLowerCase()));
    } 
    
@AfterTest 
public void closeBrowser()
{
  if(driver!=null)
  driver.quit(); 
  } 
}

 

Run the sample test and we should be seeing a rolling log on the node command prompt with the test running as shown below:

 

Test Outcome

The run output of the program as shown in the picture:

 

Not that we have always use the latest executable that is prepared to run Firefox tests via Marionette. Also, running with the latest exe would make us less prone to errors and exceptions. Furthermore, if we use Firefox 46 or later version we have to switch to use Marionette for our Firefox tests locally or with RemoteWebDriver.

Selenium WebDriver Tutorials on this website can be found at:

https://www.testingdocs.com/selenium-webdriver-tutorial

For more details on the Selenium, visit the official website at:

https://www.selenium.dev/

Exit mobile version