예제 #1
0
        public void Can_Evaluate_False_If_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript("if (\"same\" == \"notsame\") { Wait(10); }");

            Assert.AreNotEqual("Wait", lastOperation.OperationType);
            Assert.IsNull(lastOperation.Arguments);
        }
예제 #2
0
        public void Can_Evaluate_If_AND_False_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript("if (\"same\" == \"same\" && \"other\" == \"notother\") { Log(\"Log output!\"); }");

            Assert.AreNotEqual("Log", lastOperation.OperationType);
            Assert.IsNull(lastOperation.Arguments);
        }
예제 #3
0
        public void Can_Evaluate_False_If_Else_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript("if (\"same\" == \"notsame\") { Wait(10); } else { NavigateTo(\"Url\"); }");

            Assert.AreEqual("NavigateTo", lastOperation.OperationType);
            Assert.AreEqual("Url", lastOperation.Arguments[0]);
        }
예제 #4
0
        public void Can_Evaluate_True_If_AND_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript("if (\"same\" == \"same\" && \"other\" == \"other\") { Wait(10); }");

            Assert.AreEqual("Wait", lastOperation.OperationType);
            Assert.AreEqual("10", lastOperation.Arguments[0]);
        }
예제 #5
0
        public void Can_Evaluate_True_If_Integer_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript("if (3 == 3) { Wait(10); }");

            Assert.AreEqual("Wait", lastOperation.OperationType);
            Assert.AreEqual("10", lastOperation.Arguments[0]);
        }
예제 #6
0
        public void Can_Evaluate_True_Variable_If_LGT_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript("int a = 5; int b = 4; if (a > b) { Wait(10); }");

            Assert.AreEqual("Wait", lastOperation.OperationType);
            Assert.AreEqual("10", lastOperation.Arguments[0]);
        }
예제 #7
0
        public void Can_Evaluate_True_ElseIf_If_Condition()
        {
            lastOperation = new WebDriverOperationLog();
            var visitor = VisitScript(
                @"
if (""same"" == ""notsame"") 
{ 
  Wait(10); 
} 
else if (""same"" == ""same"") 
{ 
  string elementText = GetUrl(); 
} 
");

            Assert.AreEqual("GetUrl", lastOperation.OperationType);
        }
예제 #8
0
        public void Initialize()
        {
            webDriver.Setup(x => x.Click(It.IsAny <string>(), It.IsAny <string>()))
            .Callback((string xPath, string elementDescription) => lastOperation = new WebDriverOperationLog()
            {
                Arguments     = new string[] { xPath, elementDescription },
                OperationType = "Click"
            });

            webDriver.Setup(x => x.SendKeys(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>()))
            .Callback((string xPath, string data, string elementDescription) => lastOperation = new WebDriverOperationLog()
            {
                Arguments     = new string[] { xPath, data, elementDescription },
                OperationType = "SendKeys"
            });

            webDriver.Setup(x => x.WaitForSeconds(It.IsAny <int>()))
            .Callback((int numberOfSeconds) => lastOperation = new WebDriverOperationLog()
            {
                Arguments     = new string[] { numberOfSeconds.ToString() },
                OperationType = "Wait"
            });

            webDriver.Setup(x => x.NavigateTo(It.IsAny <string>()))
            .Callback((string url) => lastOperation = new WebDriverOperationLog()
            {
                Arguments     = new string[] { url },
                OperationType = "NavigateTo"
            });

            webDriver.Setup(x => x.GetElementText(It.IsAny <string>(), It.IsAny <string>()))
            .Returns("Test data")
            .Callback((string xPath, string elementDescription) => lastOperation = new WebDriverOperationLog()
            {
                OperationType = "GetElementText",
                Arguments     = new string[] { xPath, elementDescription }
            });

            webDriver.Setup(x => x.GetUrl())
            .Returns("Test URL")
            .Callback(() => lastOperation = new WebDriverOperationLog()
            {
                OperationType = "GetUrl",
                Arguments     = new string[] { }
            });
        }
예제 #9
0
        public void Can_Evaluate_False_If_ElseIf_Condition()
        {
            var visitor = VisitScript(
                @"
if (""same"" == ""notsame"") 
{ 
  Wait(10); 
} 
else if (""notsame"" == ""same"") 
{ 
  string elementText = GetUrl(); 
} 
");

            lastOperation = new WebDriverOperationLog();
            Assert.AreNotEqual("Wait", lastOperation.OperationType);
            Assert.IsNull(lastOperation.Arguments);
        }
예제 #10
0
        private SeleniumScriptInterpreter VisitScript(string script)
        {
            SeleniumScriptLexer  seleniumScriptLexer  = new SeleniumScriptLexer(new AntlrInputStream(script));
            SeleniumScriptParser seleniumScriptParser = new SeleniumScriptParser(new CommonTokenStream(seleniumScriptLexer));
            var seleniumScriptLogger = new SeleniumScriptLogger();

            seleniumScriptLogger.OnLogEntryWritten += (log) =>
            {
                if (
                    log.LogLevel == Enums.SeleniumScriptLogLevel.RuntimeError ||
                    log.LogLevel == Enums.SeleniumScriptLogLevel.WebDriverError ||
                    log.LogLevel == Enums.SeleniumScriptLogLevel.SyntaxError ||
                    log.LogLevel == Enums.SeleniumScriptLogLevel.VisitorError
                    )
                {
                    throw new Exception(log.Message);
                }
                else if (log.LogLevel == Enums.SeleniumScriptLogLevel.Script)
                {
                    lastOperation = new WebDriverOperationLog()
                    {
                        Arguments     = new string[] { log.Message },
                        OperationType = "Log"
                    };

                    scriptLogOutput.Add(log.Message);
                }
                else
                {
                    Debug.WriteLine($"{log.TimeStamp} [{log.LogLevel}] - {log.Message}");
                }
            };
            seleniumScriptParser.AddErrorListener(new SeleniumScriptSyntaxErrorListener());
            callStack = new CallStack(new StackFrameHandlerFactory(), seleniumScriptLogger);
            var visitor = new SeleniumScriptInterpreter(webDriver.Object, callStack, seleniumScriptLogger);

            visitor.Visit(seleniumScriptParser.executionUnit());
            return(visitor);
        }