From f03fc3269982d2084176fcba6e725646f1007823 Mon Sep 17 00:00:00 2001 From: dhbrett Date: Mon, 18 Apr 2016 15:46:35 -0700 Subject: [PATCH 1/3] New way of checking --- TestData.cs | 32 ++++---------------------------- 1 file changed, 4 insertions(+), 28 deletions(-) diff --git a/TestData.cs b/TestData.cs index 316f9c2..f3df48a 100644 --- a/TestData.cs +++ b/TestData.cs @@ -298,20 +298,8 @@ namespace Microsoft.Edge.A11y Func VideoPlaying = () => (bool)driver.ExecuteScript("return !document.getElementById('" + videoId + "').paused", 0); Func VideoVolume = () => { - var volume = driver.ExecuteScript("return document.getElementById('" + videoId + "').volume", 0); - try - { - return (int)volume; - } - catch { } - - try - { - return (double)volume; - } - catch { } - - throw new ArgumentException("Unable to cast to int or double"); + var volume = (string) driver.ExecuteScript("return document.getElementById('" + videoId + "').volume", 0); + return double.Parse(volume); }; Func VideoMuted = () => (bool)driver.ExecuteScript("return document.getElementById('" + videoId + "').muted", 0); Func VideoElapsed = () => (double)driver.ExecuteScript("return document.getElementById('" + videoId + "').currentTime", 0); @@ -429,20 +417,8 @@ namespace Microsoft.Edge.A11y Func AudioPlaying = () => (bool)driver.ExecuteScript("return !document.getElementById('" + audioId + "').paused", 0); Func AudioVolume = () => { - var volume = driver.ExecuteScript("return document.getElementById('" + audioId + "').volume", 0); - try - { - return (int)volume; - } - catch { } - - try - { - return (double)volume; - } - catch { } - - throw new ArgumentException("Unable to cast to int or double"); + var volume = (string)driver.ExecuteScript("return document.getElementById('" + audioId + "').volume", 0); + return double.Parse(volume); }; Func AudioMuted = () => (bool)driver.ExecuteScript("return document.getElementById('" + audioId + "').muted", 0); Func AudioElapsed = () => (double)driver.ExecuteScript("return document.getElementById('" + audioId + "').currentTime", 0); From fcd808e41c08bc517bc63375ca1ae4b22a5dff9d Mon Sep 17 00:00:00 2001 From: dhbrett Date: Mon, 18 Apr 2016 16:11:46 -0700 Subject: [PATCH 2/3] Another way of parsing things --- EdgeA11yTools.cs | 23 +++++++++++++++++++++++ TestData.cs | 16 ++++------------ 2 files changed, 27 insertions(+), 12 deletions(-) diff --git a/EdgeA11yTools.cs b/EdgeA11yTools.cs index ae6e413..fe8f208 100644 --- a/EdgeA11yTools.cs +++ b/EdgeA11yTools.cs @@ -321,5 +321,28 @@ namespace Microsoft.Edge.A11y return toreturn; } + + public static double ParseMystery(this object o) + { + try + { + return (int)o; + } + catch { } + + try + { + return (double)o; + } + catch { } + + try + { + return double.Parse((string)o); + } + catch { } + + throw new InvalidCastException("Cannot parse to int, double, or string"); + } } } \ No newline at end of file diff --git a/TestData.cs b/TestData.cs index f3df48a..651461e 100644 --- a/TestData.cs +++ b/TestData.cs @@ -296,13 +296,9 @@ namespace Microsoft.Edge.A11y { string videoId = "video1"; Func VideoPlaying = () => (bool)driver.ExecuteScript("return !document.getElementById('" + videoId + "').paused", 0); - Func VideoVolume = () => - { - var volume = (string) driver.ExecuteScript("return document.getElementById('" + videoId + "').volume", 0); - return double.Parse(volume); - }; + Func VideoVolume = () => driver.ExecuteScript("return document.getElementById('" + videoId + "').volume", 0).ParseMystery(); Func VideoMuted = () => (bool)driver.ExecuteScript("return document.getElementById('" + videoId + "').muted", 0); - Func VideoElapsed = () => (double)driver.ExecuteScript("return document.getElementById('" + videoId + "').currentTime", 0); + Func VideoElapsed = () => driver.ExecuteScript("return document.getElementById('" + videoId + "').currentTime", 0).ParseMystery(); //Case 1: tab to video element and play/pause driver.SendSpecialKeys(videoId, "Space"); @@ -415,13 +411,9 @@ namespace Microsoft.Edge.A11y { string audioId = "audio1"; Func AudioPlaying = () => (bool)driver.ExecuteScript("return !document.getElementById('" + audioId + "').paused", 0); - Func AudioVolume = () => - { - var volume = (string)driver.ExecuteScript("return document.getElementById('" + audioId + "').volume", 0); - return double.Parse(volume); - }; + Func AudioVolume = () => driver.ExecuteScript("return document.getElementById('" + audioId + "').volume", 0).ParseMystery(); Func AudioMuted = () => (bool)driver.ExecuteScript("return document.getElementById('" + audioId + "').muted", 0); - Func AudioElapsed = () => (double)driver.ExecuteScript("return document.getElementById('" + audioId + "').currentTime", 0); + Func AudioElapsed = () => driver.ExecuteScript("return document.getElementById('" + audioId + "').currentTime", 0).ParseMystery(); //Case 1: Play/Pause driver.SendTabs(audioId, 1); //Tab to play button From 9e697812cf5bc566c94f083b05acac275a7479ba Mon Sep 17 00:00:00 2001 From: Mustapha Jaber Date: Mon, 18 Apr 2016 16:33:44 -0700 Subject: [PATCH 3/3] Handle casting into Int64 --- EdgeA11yTools.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/EdgeA11yTools.cs b/EdgeA11yTools.cs index fe8f208..20b4011 100644 --- a/EdgeA11yTools.cs +++ b/EdgeA11yTools.cs @@ -330,6 +330,12 @@ namespace Microsoft.Edge.A11y } catch { } + try + { + return (Int64)o; + } + catch { } + try { return (double)o; @@ -345,4 +351,4 @@ namespace Microsoft.Edge.A11y throw new InvalidCastException("Cannot parse to int, double, or string"); } } -} \ No newline at end of file +}