0

I am new to using the SafariDriver() web driver with Selenium. and so in order to gain some experience I thought I would use the example code from:

[https://www.browserstack.com/guide/run-selenium-tests-on-safari-using-safaridriver%5C]

However this has not worked for me... here is the code I am attampting to execute..

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.remote.service.DriverService.*;
import org.openqa.selenium.safari.SafariDriver;
import org.openqa.selenium.safari.SafariDriverService;

import java.io.IOException;
import java.util.concurrent.TimeUnit;


// import org.openqa.selenium.Saf
// I have not imported the following
// import org.openqa.selenium.safari.SafariDriver;
// because this does not provide me with the SafariDriver.
public class Test_SafariDemo
{
    // the purpose of this class is to test the Safari driver
    // Written by Michael John Little
    // Based on a Java program from...
    // https://www.browserstack.com/guide/run-selenium-tests-on-safari-using-safaridriver

    public static void main(String[] args)
    {
        //create an instance of the Safari class
        WebDriver drvr =new SafariDriver();

        // lets Launch the Google website
        drvr.navigate().to("http://www.google.com/");

        // lets click on the search box and send a value
        drvr.findElement(By.id("lst-ib")).sendKeys("BrowserStack");

        // click the search button
        drvr.findElement(By.name("btnK")).click();

        // lets wait and display before we close the browser
        drvr.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

        //close the browser
        drvr.close();

    }// close public static void main(String[] args)


} // public class Test_SafariDemo

When executed this code, I was expecting:

  1. a safari browser instance to occur
  2. Launch the Google web site and for it to perform a search.

This did not occur, and I got the following:


Exception in thread "main" java.lang.AbstractMethodError: 
Receiver class org.openqa.selenium.safari.SafariDriverService$Builder does not define or inherit 
an implementation of the resolved method 'abstract com.google.common.collect.ImmutableList createArgs()' 
of abstract class org.openqa.selenium.remote.service.DriverService$Builder.
    at org.openqa.selenium.remote.service.DriverService$Builder.build(DriverService.java:358)
    at org.openqa.selenium.safari.SafariDriverService.createDefaultService(SafariDriverService.java:75)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:60)
    at org.openqa.selenium.safari.SafariDriver.<init>(SafariDriver.java:49)
    at Test_SafariDemo.main(Test_SafariDemo.java:27)

Process finished with exit code 1

In addition I have also completed the following actions:

1. Enabled the 'Allow Remote Automation' checkbox on the Safari Developer menu.

2. Executed the ' safaridriver --enable' command

The error message, I do not fully understand what is means by...


Receiver class org.openqa.selenium.safari.SafariDriverService$Builder does not define or inherit 
an implementation of the resolved method 'abstract com.google.common.collect.ImmutableList createArgs()' 
of abstract class org.openqa.selenium.remote.service.DriverService$Builder.

at the statement...

WebDriver drvr =new SafariDriver();

Any suggestions as to how I can resolve this issue?

1 Answers1

0

You were almost there. You simply have a couple of unwanted import as:

import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.safari.SafariDriverService;

Remove those unwanted imports to get rid of compilation errors, you will be good to go.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you... I am now importing the following... import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.safari.SafariDriver; import java.util.concurrent.TimeUnit; ...but I am still getting the same error... have you managed to get this code working on your environment? – Flash Jack From Gundagai Feb 23 '23 at 23:56