public void Run(string script) { var seleniumScriptLexer = new SeleniumScriptLexer(new AntlrInputStream(script)); var seleniumScriptParser = new SeleniumScriptParser(new CommonTokenStream(seleniumScriptLexer)); seleniumScriptParser.AddErrorListener(new SeleniumScriptSyntaxErrorListener()); try { seleniumScriptVisitor.Run(seleniumScriptParser.executionUnit()); } catch (Exception e) { seleniumScriptLogger.Log(e.Message, exceptionLogLevels.ContainsKey(e.getType().Name) ? exceptionLogLevels[e.GetType().Name] : SeleniumScriptLogLevel.Undefined); Dispose(); throw e; } }
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); }