-
-
Notifications
You must be signed in to change notification settings - Fork 8.7k
Boolean returns exception instead of false using Any() on Safari Webdriver with Selenium Server 3.3.1 if object not present #4265
Description
Hi,
When I try to run my Selenium tests (I am using Sauce Labs environment) on Safari pointing to seleniumVersion 3.3.1, booleans returns exception instead of "false" if I use "Any()" in C# when the object is not available. The desired capabilities are as follows:
SetCapability("seleniumVersion", "3.3.1");
SetCapability("platform", "macOS 10.12");
For simplicity, I have created a simple google test as I can reproduce it with that as well, just copy paste in Visual Studio and run it (provided you have Selenium and webdriver/s from nuget):
Please note that in my test I am using inheritance from "Helper Page" which has got my Sauce Labs config, You can try running this on local Safari webdriver setup if you have or on sauce labs.
This throws exception ONLY on Safari with seleniumVersion 3.3.1
Works fine on Chrome - both default seleniumVersion (2.48.0) and 3.3.1
Works fine on Safari - default seleniumVersion (2.48.0)
PS: The expected result and failure step provided in code comments for simplicity
Please let me know if you need any other detail.
Thanks!
Regards
Manish
===========================================================
using FredNxtOfficeWebAutomation.Pages;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Safari;
using OpenQA.Selenium.Support.UI;
using System;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading;
namespace FredNxtOfficeWebAutomation.Tests
{
[TestClass]
public class SafariBoolTest : HelperPage //My sauce lab config is in helper page, you can try your own config with SetCapability("seleniumVersion", "3.3.1")
{
[TestMethod]
public void SafariTest()
{
//driver = new SafariDriver(); //you can try locally, not aware of the outcome though as I don't have local mac setup
//driver = new ChromeDriver();
driver.Manage().Window.Maximize();
Uri BaseUrl = new Uri("http://www.google.com/");
//The below statement throws exception on Safari with seleniumVersion 3.3.1
//Works fine on Chrome - both default and 3.3.1 - Sauce Labs
//Works fine on Safari - default - Sauce Labs
if (!googleIsOpen) //exception here
driver.Navigate().GoToUrl(BaseUrl);
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(60));
//wait.Until(ExpectedConditions.ElementToBeClickable(By.Id("lst-ib"))); //This also fails on Safari for Selenium 3.3.1
Thread.Sleep(2000);
searchElement[0].SendKeys("selenium");
}
public ReadOnlyCollection<IWebElement> searchElement => driver.FindElements(By.Id("lst-ib"));
public bool googleIsOpen
{
get
{
return searchElement.Any(); //throws exception
}
}
}
}