我目前正在使用Specflow和Selenium来自动化我的质量检查。每次测试后,它都会生成一个“范围报告”,并且在测试过程中发生一些错误时,它会截取屏幕截图并将其链接放在消息的正下方,但是当我单击该链接时,它不会执行任何操作。因此,我必须右键单击它,然后在新选项卡上将其打开。该图像使用base64格式在C#上编码。谁能告诉我如何使用常规的左键单击以在新标签页中打开屏幕截图?
这是我的代码:
else if (ScenarioContext.Current.TestError != null)
{
if (stepType == "Given")
{
var gDriverHook = AssertDriverHook(DriverHook);
CapturaTela.ErrorScreenshot(AssertDriverHook(gDriverHook));
_scenario.CreateNode<Given>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
_scenario.CreateNode<Given>("Detalhes:").Fail("<a href =" + "data:image/jpeg;base64," + CapturaTela.ErrorScreenshot(gDriverHook) + ">" + "Clique Aqui para ver a Imagem" + "</a>");
}
else if (stepType == "When")
{
var gDriverHook = AssertDriverHook(DriverHook);
CapturaTela.ErrorScreenshot(AssertDriverHook(gDriverHook));
_scenario.CreateNode<When>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message + " \n \n <a href =" + "data:image/jpeg;base64," + CapturaTela.ErrorScreenshot(gDriverHook) + ">" + "Clique Aqui para ver a Imagem" + "</a>");
}
else if (stepType == "Then")
{
var gDriverHook = AssertDriverHook(DriverHook);
CapturaTela.ErrorScreenshot(AssertDriverHook(gDriverHook));
_scenario.CreateNode<Then>(ScenarioStepContext.Current.StepInfo.Text).Fail(ScenarioContext.Current.TestError.Message);
_scenario.CreateNode<Then>("Detalhes:").Fail("<a href =" + "data:image/jpeg;base64," + CapturaTela.ErrorScreenshot(gDriverHook) + ">" + "Clique Aqui para ver a Imagem" + "</a>");
}
}
这是我的Screenshot方法的所在地:
public static string ErrorScreenshot(IWebDriver pDriver)
{
ITakesScreenshot screenshotDriver = pDriver as ITakesScreenshot;
Screenshot screenshot = screenshotDriver.GetScreenshot();
string base64 = screenshot.AsBase64EncodedString.Replace("\"\"", "");
string ErrDirectory = "C:/Screenshot/err/";
Directory.CreateDirectory(ErrDirectory);
ErrDirectory = ErrDirectory + "Err_" + DateTime.Now.ToString("dd-MM-yyyy_HH-mm-ss");
screenshot.SaveAsFile(ErrDirectory, ScreenshotImageFormat.Jpeg);
return base64;
}
这是我要单击的链接: