public async Task ExceptionTest() { using (Chrome c = new Chrome()) { var s = await c.CreateNewSession(); bool failed = false; string reason = ""; string stack = ""; //this should cause an error because foo is not defined try { var result = await s.EvalValue <int>("foo"); } catch (ChromeRemoteException ex) { failed = true; reason = ex.Message; stack = ex.RemoteStackTrace; } catch (Exception) { throw; } Assert.IsTrue(failed, "There was supposed to be an exception!"); Assert.IsTrue(reason.Contains("foo is not defined"), "The error does not contain the correct description"); } }
public async Task DoubleEvalTest() { using (Chrome c = new Chrome()) { var s = await c.CreateNewSession(); double result = await s.EvalValue <double>("7.3543"); Assert.AreEqual(7.3543, result, "The received result did not match the expected result"); } }
public async Task BoolEvalTest() { using (Chrome c = new Chrome()) { var s = await c.CreateNewSession(); bool result = await s.EvalValue <bool>("true"); Assert.AreEqual(true, result, "The received result did not match the expected result"); } }
public async Task IntEvalTest() { using (Chrome c = new Chrome()) { var s = await c.CreateNewSession(); int result = await s.EvalValue <int>("7"); Assert.AreEqual(7, result, "The received result did not match the expected result"); } }
public async Task DynamicArrayEvalTest() { using (Chrome c = new Chrome()) { object[] expected = new object[] { 1, true, "asd" }; var s = await c.CreateNewSession(); IEnumerable <object> result = await s.EvalEnumerable <object>("[1, true, 'asd']"); Assert.IsTrue(expected.SequenceEqual(result), "The received result did not match the expected result"); } }
public async Task ArrayEvalTest() { using (Chrome c = new Chrome()) { int[] expected = new int[] { 1, 2, 3, 4, 5 }; var s = await c.CreateNewSession(); IEnumerable <int> result = await s.EvalEnumerable <int>("[1, 2, 3, 4, 5]"); Assert.IsTrue(expected.SequenceEqual(result), "The received result did not match the expected result"); } }
public async Task SessionCreationTest() { Chrome c = new Chrome(remoteDebuggingPort: 9992, headless: false); var currentSessions = await c.GetActiveSessions(); var s = await c.CreateNewSession(); var newSessions = await c.GetActiveSessions(); Assert.IsTrue(currentSessions.Count() + 1 == newSessions.Count(), "The number of sessions before creation + 1 was not equal to the sessions found later"); c.Dispose(); }
public async Task ObjectLiteralEvalTest() { using (Chrome c = new Chrome(headless: false)) { Point expected = new Point(10, 3); var s = await c.CreateNewSession(); var result = await s.EvalObject("var a ={ 'X' : 10, 'Y' : 3}; a;"); Assert.AreEqual(expected.X, result.X, "The received result did not match the expected result"); Assert.AreEqual(expected.Y, result.Y, "The received result did not match the expected result"); } }
public async Task SessionDisposeTest() { using (Chrome c = new Chrome(remoteDebuggingPort: 9994, headless: false)) { var currentSessions = await c.GetActiveSessions(); var s = await c.CreateNewSession(); s.Dispose(); var currentSessions2 = await c.GetActiveSessions(); Assert.AreEqual(currentSessions.Count(), currentSessions2.Count(), 0, "The session created was not destroyed when disposed"); } }
public async Task NavigateTest() { using (Chrome c = new Chrome(remoteDebuggingPort: 9994, headless: false)) { bool reached = false; var session = await c.CreateNewSession(); session.PageLoaded += (s, e) => { reached = true; }; await session.Navigate("http://www.google.com"); await Task.Delay(5000); //if by now i do not have the result, something went wrong Assert.IsTrue(reached, "The webpage was not reached during the time waited"); } }
public static async Task<List<ChromeSession>> CreateHiveSessions(this Chrome c, int amount) { List<ChromeSession> result = new List<ChromeSession>(); int finished = 0; for (int i = 0; i < amount; i++) { var s = await c.CreateNewSession(); result.Add(s); s.PageLoaded += (cs, e) => { finished++; }; await s.Navigate("http://hiveproject.github.io/Firebase/"); } while (finished < amount) await Task.Delay(10); await Task.Delay(100); return result; }