I just started a selenium project, but things didn't got right, so after searching a bit I found this solution. It works but i can't understand what these red statements want me to do, or how to get rid of them.
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxBinary;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
import org.openqa.selenium.remote.DesiredCapabilities;
import java.io.*;
public class SelTest1
{
public static void main(String [] args)
{
System.setProperty("webdriver.gecko.driver","X:\\Gecko\\geckodriver-v0.24.0-win64\\geckodriver.exe");
File pathBinary = new File("X:\\FireFoxx\\firefox.exe");
FirefoxBinary firefoxBinary = new FirefoxBinary(pathBinary);
DesiredCapabilities desired = DesiredCapabilities.firefox();
FirefoxOptions options = new FirefoxOptions();
desired.setCapability(FirefoxOptions.FIREFOX_OPTIONS, options.setBinary(firefoxBinary));
WebDriver obj = new FirefoxDriver(options);
obj.get("http://www.google.com/");
}
}
I got the result i wanted, but I don't understand the warning{ red statements}
I am putting those red lines { warnings here too for ease }
Jul 12, 2019 7:07:28 PM org.openqa.selenium.remote.DesiredCapabilities firefox
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
1562938650997 mozrunner::runner INFO Running command: "X:\\FireFoxx\\firefox.exe" "-marionette" "-foreground" "-no-remote" "-profile" "C:\\Users\\adars\\AppData\\Local\\Temp\\rust_mozprofile.uTUmeENutxin"
1562938652637 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: mozillaAddons
1562938652638 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: resource://pdf.js/
1562938652638 [email protected] WARN Loading extension '[email protected]': Reading manifest: Invalid extension permission: about:reader*
1562938655909 Marionette INFO Listening on port 50040
1562938655964 Marionette WARN TLS certificate errors will be ignored for this session
Jul 12, 2019 7:07:36 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
To declare Desired Capabilities in Selenium automation testing using Grid, we can use the setCapability method from the DesiredCapabilities class to set the different types of capabilities of the browser (Ex. Chrome, IE, Firefox, Edge) platform name (Ex. Windows, macOS, etc.).
FirefoxOptions options = new FirefoxOptions(); FirefoxProfile profile = new FirefoxProfile();
What Are DesiredCapabilities in Selenium? DesiredCapabilities are a set of key-value pairs encoded as a JSON object. It helps QAs define basic test requirements such as operating systems, browser combinations, browser versions, etc. within Selenium test scripts.
Marionette is an automation driver for Mozilla's Gecko engine. It can remotely control either the UI or the internal JavaScript of a Gecko platform, such as Firefox.
This INFO log message:
INFO: Using `new FirefoxOptions()` is preferred to `DesiredCapabilities.firefox()`
is the result of the changes incorporated in:
Selenium v3.0.0-beta4
Added ability to use FirefoxOptions when starting firefox.
Selenium v3.5.0
* Start making *Option classes instances of Capabilities. This allows
the user to do:
`WebDriver driver = new RemoteWebDriver(new InternetExplorerOptions());`
If your usecase is to explicitly mention the absolute location of the FirefoxBinary
you can use the following solution:
Using FirefoxOptions
:
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxOptions;
public class A_Firefox_binary
{
public static void main(String[] args)
{
System.setProperty("webdriver.gecko.driver", "C:/Utility/BrowserDrivers/geckodriver.exe");
FirefoxOptions options = new FirefoxOptions();
options.setBinary("C:\\Program Files\\Mozilla Firefox\\firefox.exe");
WebDriver driver = new FirefoxDriver(options);
driver.get("https://stackoverflow.com");
System.out.println("Page Title is : "+driver.getTitle());
driver.quit();
}
}
Console Output:
Page Title is : Stack Overflow - Where Developers Learn, Share, & Build Careers
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With