Search This Blog

September 20, 2018

DesiredCapabilities is obsolete in Selenium Web Driver v.3.14, How to write the code for Selenium Grid in C#?

I upgraded Selenium Web Driver and Support to v3.14.  Noticed that the following code showed the error.  

DesiredCapabilities capabilities; --deprecated  
capabilities = DesiredCapabilities.Chrome();  --has the error 
capabilities.SetCapability(CapabilityType.Platformnew Platform(PlatformType.Windows));  
Uri uri = new Uri(hub url);  
_driver = new RemoteWebDriver(uri, capabilities, TimeSpan.FromSeconds(120));  

From the class RemoteWebDriver in OpenQA.Selenium.Remote, it still has the ICapabilities parameter.  
public RemoteWebDriver(Uri remoteAddressICapabilities desiredCapabilitiesTimeSpan commandTimeout) 

After posting the question in stackflowone nice guy replied. I created a new branch , updated the following code , set up the private branch in bamboo and ran BVTs in the Selenium Grid. The tests passed.  

ChromeOptions options = new ChromeOptions(); 
options.PlatformName = PlatformType.Windows.ToString(); 
Uri uri = new Uri(hub url); 
_driver = new RemoteWebDriver(urioptions.ToCapabilities(), TimeSpan.FromSeconds(120)); 

September 5, 2018

Many Selenium tests fail using Chrome headless

I need to run 9 BVTs and 74 core tests every day in my machine.  Last week, I ran them in parallel using Chrome or Chrome headless. Here was the test result:



If I run 519 parallel tests in Selenium using Chrome headless , can you imagine how many tests will fail?  I would say running a lot of tests in Chrome headless is not  a good idea even if the duration is so short. 

August 21, 2018

How to get the value from the textbox in Selenium?

Today one colleague asked me one question. If he entered the value in the textbox, how to get that value from textbox in C# and Selenium ?  

It is simple. You can use GetAttribute("value") to achieve your goal.  

        public string GetTextBoxValue(IWebElement textBoxElement) 
        { 
            return textBoxElement.GetAttribute("value");    
        } 

July 27, 2018

Fixed the Firefox issue in Selenium : out of bounds of viewport width (1600) and height (786)

Today I used Firefox 61 to run some tests and 2 tests failed due to the following error. 

System.InvalidOperationException : (345.816650390625, 789.8833312988281) is out of bounds of viewport width (1600) and height (786) (MoveTargetOutOfBounds) 

2 tests are running fine in Chrome and Microsoft Edge.  

After looking into this issue, it looks like there is the bug in Gecko Driver about the viewpoint width and height of Firefox. In order to let the tests pass, I need to add the code to handle this issue. 

Since the Firefox has the issue related to out of bounds of viewpoint width and height, the quickest way to handle it is to add ScrollDown() method. 

After adding it and running the tests, 2 tests pass without any issue.  

       public void ScrollDown() 
        { 
            ((IJavaScriptExecutor)_driver).ExecuteScript("scroll(0,450);"); 
        }