테스트 실패시 스크린 샷을 찍는 동안 문제가 발생합니다. 실패 상태에서 스크린 샷을 찍으려고하면 시간 초과 오류가 발생합니다. try 블록에서는 잘 작동하지만 catch 블록에서는 시간이 초과되었습니다. 어떤 도움을 주시면 감사하겠습니다.
다음은 스크린 샷을 찍는 방법입니다.
public class Logging
{
public static void ErrorScreenshot()
{
//Take the screenshot
Screenshot ssh = ((ITakesScreenshot)Driver.BrowserInstance).GetScreenshot();
//Save the screenshot
ssh.SaveAsFile("C:/Users/", ScreenshotImageFormat.Png);
}
}
이것은 내 테스트 방법입니다.
public static bool FindElement
{
get
{
try
{
var element = Driver.BrowserInstance.FindElement(By.XPath(" "));
if (element != null)
{
return true;
}
}
catch (Exception ex)
{
Logging.ErrorScreenshot();
Logging.Error("Not able to find element" + ex.ToString());
}
return false;
}
}
요소를 찾을 수 없으면 catch 블록으로 이동하고 Logging.ErrorScreenshot 메서드는 시간 초과 예외를 throw합니다.
Error details:
OpenQA.Selenium.WebDriverException
HResult=0x80131500
Message=The HTTP request to the remote WebDriver server for URL http://localhost:55418/session/f3dbde1645dd91e453c5823d72199ea9/screenshot timed out after 60 seconds.
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.HttpCommandExecutor.MakeHttpRequest(HttpRequestInfo requestInfo)
at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.GetScreenshot()
at AvbLinqAutoFramework.Logging.ErrorScreenshot() in C:\Users\Logging.cs:line 66
at DashboardPage.get_Verifylogin() in C:\Users\DasboardPage.cs:line 65
at Tests() in C:\Users\SmokeTests\Tests.cs:line 33
Inner Exception 1:
WebException: The operation has timed out
다른 선택기 (CssSelector) 및 WebDrverWait를 사용하여이 문제를 해결했습니다. 원래 예외는 XPath를 사용하여 요소를 찾을 수없는 동안 시간이 초과되었습니다.
public static bool FindElement
{
get
{
try
{
WebDriverWait wait = new WebDriverWait(Driver.BrowserInstance, TimeSpan.FromSeconds(10));
var inputspcmodel = wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions.ElementToBeClickable(By.CssSelector($"div[id ='modelSearch-container'] div[class='k-widget k-multiselect k-multiselect-clearable'] div input")));
inputspcmodel.Click();
return true;
}
catch (Exception ex)
{
Logging.Error("Not able to find element " + ex.ToString());
Logging.ErrorScreenshot();
}
return false;
}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다