How to use addCommandLineOptions method of org.openqa.selenium.firefox.FirefoxBinary class

Best Selenium code snippet using org.openqa.selenium.firefox.FirefoxBinary.addCommandLineOptions

Run Selenium automation tests on LambdaTest cloud grid

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

copy
1package com.edureka;
2
3import java.io.IOException;
4import org.openqa.selenium.By;
5import org.openqa.selenium.WebElement;
6import org.openqa.selenium.firefox.FirefoxBinary;
7import org.openqa.selenium.firefox.FirefoxDriver;
8import org.openqa.selenium.firefox.FirefoxOptions;
9
10public class Main {
11
12    public static void main(String[] args) throws IOException, InterruptedException{
13
14        FirefoxBinary firefoxBinary = new FirefoxBinary();
15        firefoxBinary.addCommandLineOptions("--headless");
16        firefoxBinary.addCommandLineOptions("--no-sandbox");
17        System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
18        FirefoxOptions firefoxOptions = new FirefoxOptions();
19        firefoxOptions.setBinary(firefoxBinary);
20        FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
21        driver.get("http://127.0.0.1:1998/index.php");
22        WebElement button = driver.findElement(By.id("Contact"));
23        assert(button.isDisplayed());
24        System.out.println("Contact element is there: " + button.isDisplayed());
25	System.out.println("Executed");
26        button.click();
27        assert(button.getText().equals("Contact"));
28        driver.close();
29    }
30}
Full Screen
copy
1import java.io.IOException;
2 
3import org.openqa.selenium.By;
4import org.openqa.selenium.WebElement;
5import org.openqa.selenium.firefox.FirefoxBinary;
6import org.openqa.selenium.firefox.FirefoxDriver;
7import org.openqa.selenium.firefox.FirefoxOptions;
8import org.testng.annotations.Test;
9 
10public class StaticsiteSeleniumTest {
11 
12 public static void main(String[] args) throws IOException, InterruptedException {
13 
14 FirefoxBinary firefoxBinary = new FirefoxBinary();
15 firefoxBinary.addCommandLineOptions("--headless");
16 firefoxBinary.addCommandLineOptions("--no-sandbox");
17 System.setProperty("webdriver.gecko.driver", "/usr/bin/geckodriver");
18 FirefoxOptions firefoxOptions = new FirefoxOptions();
19 firefoxOptions.setBinary(firefoxBinary);
20 FirefoxDriver driver = new FirefoxDriver(firefoxOptions);
21 driver.get("http://localhost:90/");
22 
23 Thread.sleep(1000);
24 
25 if (driver.getPageSource().contains("some random key")) {
26 System.out.println("Pass");
27 } else {
28 System.out.println("Fail");
29 }
30 driver.quit();
31 }
32}
33
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Trigger addCommandLineOptions code on LambdaTest Cloud Grid

Execute automation tests with addCommandLineOptions on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie