Automation, Automation Framework, Design patterns, Java, Maven, Safari, Selenium

Running selenium scripts on browser Safari and Mac Operating System

Safari Logs

SafariDriver Launcher
 [ 0.007s] [safaridriver.client] Connecting to SafariDriver browser extension...
 [ 0.019s] [safaridriver.client] This will fail if you have not installed the latest SafariDriver extension from
 http://selenium-release.storage.googleapis.com/index.html
 [ 0.020s] [safaridriver.client] Extension logs may be viewed by clicking the Selenium [✓] button on the Safari toolbar
 [ 0.071s] [safaridriver.client] Connected to extension
 [ 0.072s] [safaridriver.client] Requesting extension connect to client at ws://localhost:10975

Eclipse Console logs

[TestNG] Running:
/private/var/folders/0z/13848h057r56wcwp808shyhr3w4d0j/T/testng-eclipse-2105191378/testng-customsuite.xml
Jul 24, 2017 11:29:39 AM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 10975
Jul 24, 2017 11:29:39 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Launching Safari
Jul 24, 2017 11:29:39 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Waiting for SafariDriver to connect
Jul 24, 2017 11:29:41 AM org.openqa.selenium.safari.SafariDriverChannelHandler$1 operationComplete
INFO: Connection opened
Jul 24, 2017 11:29:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Driver connected in 1714 ms
Jul 24, 2017 11:29:41 AM org.openqa.selenium.safari.SafariDriverServer start
INFO: Server started on port 17885
Jul 24, 2017 11:29:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Launching Safari
Jul 24, 2017 11:29:41 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Waiting for SafariDriver to connect
Jul 24, 2017 11:29:43 AM org.openqa.selenium.safari.SafariDriverChannelHandler$1 operationComplete
INFO: Connection opened
Jul 24, 2017 11:29:43 AM org.openqa.selenium.safari.SafariDriverCommandExecutor start
INFO: Driver connected in 1665 ms
FAILED CONFIGURATION: @BeforeMethod testMethodStart
java.lang.NoSuchMethodError: com.google.common.util.concurrent.MoreExecutors.directExecutor()Ljava/util/concurrent/Executor;
at org.openqa.selenium.safari.WebSocketConnection.send(WebSocketConnection.java:139)
at org.openqa.selenium.safari.SafariDriverCommandExecutor.execute(SafariDriverCommandExecutor.java:188)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:644)
at org.openqa.selenium.remote.RemoteWebDriver.startSession(RemoteWebDriver.java:249)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:131)
at org.openqa.selenium.remote.RemoteWebDriver.(RemoteWebDriver.java:144)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:62)
at org.openqa.selenium.safari.SafariDriver.(SafariDriver.java:42)
at com.sod.utility.DriverInit.getDriver(DriverInit.java:90)
at com.sod.utility.MainClass.testMethodStart(MainClass.java:162)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Solution

I have seen many blogs around the internet and the below code is the simple solution of the above issue.
public static ThreadLocal ThreadDriver = new ThreadLocal();
protected static WebDriverWait wait;
protected static AppiumDriver adriver;
public static String browserType;
public static String OS;

public static WebDriver getDriver() throws InterruptedException, IOException {
OS = System.getProperty(“os.name”).toLowerCase();
WebDriver driver = ThreadDriver.get();
String workingDir = System.getProperty(“user.dir”);
if (driver == null) {
if (browserType.equals(“firefox”)) {
driver = new EventFiringWebDriver(new FirefoxDriver());
FirefoxProfile profile = new FirefoxProfile();
profile.setAssumeUntrustedCertificateIssuer(false);
profile.setAcceptUntrustedCertificates(false);
profile.setPreference(“dom.disable_beforeunload”, true);
ThreadDriver.set(driver);
getDriver().manage().timeouts().implicitlyWait(30000, TimeUnit.MILLISECONDS);
wait = new WebDriverWait(driver, 30);
}
if (browserType.equals(“chrome”)) {
if (isWindows()) {
System.setProperty(“webdriver.chrome.driver”, workingDir + “//driver//chromedriver.exe”);
} else if (isMac()) {
System.setProperty(“webdriver.chrome.driver”, workingDir + “//driver//chromedriver”);
} else if (isLinux()) {
System.setProperty(“webdriver.chrome.driver”, “/usr/bin/chromedriver”);
}
DesiredCapabilities capabilities = DesiredCapabilities.chrome();
ChromeOptions options = new ChromeOptions();
options.addArguments(“test-type”);
options.addArguments(“–start-maximized”);
options.addArguments(“–disable-web-security”);
options.addArguments(“–allow-running-insecure-content”);
capabilities.setCapability(“chrome.binary”, “./src//lib//chromedriver”);
capabilities.setCapability(ChromeOptions.CAPABILITY, options);
driver = new ChromeDriver(capabilities);
driver = new EventFiringWebDriver(new ChromeDriver());
ThreadDriver.set(driver);
if (isMac()) {
maximizeScreen();
}
getDriver().manage().timeouts().implicitlyWait(30000, TimeUnit.MILLISECONDS);
wait = new WebDriverWait(driver, 30);
}
if (browserType.equals(“ie”)) {
System.setProperty(“webdriver.ie.driver”, workingDir + “//driver//IEDriverServer.exe”);
driver = new EventFiringWebDriver(new InternetExplorerDriver());
ThreadDriver.set(driver);
getDriver().manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
wait = new WebDriverWait(driver, 30);
}

if (browserType.equals(“safari”)) {

// System.setProperty(“webdriver.safari.driver”, workingDir +

// “//driver//SafariDriverServer.exe”);

System.setProperty(“webdriver.safari.driver”,

        “/driver/SafariDriver.safariextz”);

System.setProperty(“webdriver.safari.noinstall”, “true”);

DesiredCapabilities desiredCapabilities = DesiredCapabilities

        .safari();

SafariOptions safariOptions = new SafariOptions();

safariOptions.setUseCleanSession(true);

safariOptions.getUseCleanSession();

safariOptions.setUseCleanSession(true);

desiredCapabilities.setCapability(SafariOptions.CAPABILITY,

        safariOptions);

// deleteCookies();

driver = new EventFiringWebDriver(new SafariDriver());

ThreadDriver.set(driver);

// driver.manage().window().setSize(new Dimension(1024, 850));

getDriver().manage().timeouts().implicitlyWait(3,

        TimeUnit.SECONDS);

wait = new WebDriverWait(driver, 30);

}

}
return driver;
}

More Information

Operating System – Mac Seirra 10.12

Safari version – 10.1.2 (12603.3.8)

Download SafariDriver.safariextz – https://selenium-release.storage.googleapis.com/2.48/SafariDriver.safariextz

  • Technologies used in framework:-
  1. Java 8
  2. Selenium Webdriver
  3. Can support Appium 1.4.13.1
  4. TestNG
  5. Page Object Model, Page Factory
  • Maven dependencies used in framework:-
  1. Selenium webdriver 2.53.1
  2. TestNG 6.8
  3. Log4J 1.2.17
  4. Apache POI 3.14
  5. Can support Appium 4.1.1
  • Browsers/Emulator on which the framework has been tested as of now:
  1. Chrome  53.0
  2. Safari 10
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s