public static void CheckJSErrors()
{
//Firefox
if (MainForm.form.cbBrowsers.SelectedItem.ToString() == "FireFox")
{
string JSerrors = "";
IList<object> errors = null;
try
{
errors = ((IJavaScriptExecutor)BitrixFramework.WebDriver).ExecuteScript("return window.JSErrorCollector_errors.pump()") as IList<object>;
}
catch (Exception)
{
return;
}
int JSErrorsCountTMP = errors.Count();
if (JSErrorsCount > 0)
{
for (int i = 0; i >= JSErrorsCount; i++)
{
errors.Remove(i);
}
}
JSErrorsCount = JSErrorsCountTMP;
if (errors.Count > 0)
{
foreach (var er in errors)
{
JSerrors += "\r\n\r\n Ошибка: " + ((System.Collections.Generic.IDictionary<string, object>)er)["errorMessage"].ToString() +
"\r\n Строка: " + ((System.Collections.Generic.IDictionary<string, object>)er)["lineNumber"].ToString() +
"\r\n Урл: " + ((System.Collections.Generic.IDictionary<string, object>)er)["sourceName"].ToString();
}
Log.MesError("Найдены JS ошибки: " + JSerrors + "\r\nНа странице: " + BitrixFramework.WebDriver.Url);
}
}
//Chrome
if (MainForm.form.cbBrowsers.SelectedItem.ToString() == "Chrome")
{
string JSerrors = "";
IList<object> errors = null;
try
{
errors = ((IJavaScriptExecutor)BitrixFramework.WebDriver).ExecuteScript("return window.JSErrorCollector_errors.pump()") as IList<object>;
}
catch (Exception)
{
return;
}
int JSErrorsCountTMP = errors.Count();
if (JSErrorsCount > 0)
{
for (int i = 0; i >= JSErrorsCount; i++)
{
errors.Remove(i);
}
}
JSErrorsCount = JSErrorsCountTMP;
if (errors.Count > 0)
{
try
{
foreach (var er in errors)
{
JSerrors += "\r\n\r\n Ошибка: " + ((System.Collections.Generic.IDictionary<string, object>)er)["errorMessage"].ToString() +
"\r\n Строка: " + ((System.Collections.Generic.IDictionary<string, object>)er)["lineNumber"].ToString() +
"\r\n Урл: " + ((System.Collections.Generic.IDictionary<string, object>)er)["sourceName"].ToString();
}
}
catch (KeyNotFoundException)
{
return;
}
Log.Gap();
Log.MesError("Найдены JS ошибки: " + JSerrors + "\r\nНа странице: " + BitrixFramework.WebDriver.Url);
}
}
}