简体   繁体   English

如何使用Selenium Webdriver和C#创建日志文件?

[英]How to create a log file using selenium webdriver and C#?

How to create a log file using selenium webdriver? 如何使用Selenium WebDriver创建日志文件? I had created a log file using selenium RC. 我已经使用Selenium RC创建了一个日志文件。 IN selenium RC I had created an HTML log file with screenshots and error messages. 在selenium RC中,我创建了一个包含屏幕截图和错误消息的HTML日志文件。 I used the following code in selenium RC. 我在硒RC中使用了以下代码。

`selenium.CaptureEntirePageScreenshot(screenShotDirectory + "\\" + "wrong username and password.png",""); `selenium.CaptureEntirePageScreenshot(screenShotDirectory +“ \\” +“用户名和密码错误。png”,“”);

string path = "Screenshot\\wrong username and password.png"; 字符串路径=“屏幕截图\\错误的username和password.png”;

Sw.WriteLine(" Wrong username and password Sw.WriteLine(“ 用户名和密码错误



"); ` “);`

How can I create same HTML log file using selenium Webdriver? 如何使用Selenium Webdriver创建相同的HTML日志文件? What code in C# should i write? 我应该用C#编写什么代码?

Thanks. 谢谢。

In the .NET bindings, you'll want something like the following: 在.NET绑定中,您将需要以下内容:

// Assumes driver is a WebDriver instance that implements ITakesScreenshot
// N.B., to be completely correct, you should check for a successful cast
// by adding a null check for screenshotDriver.
ITakesScreenshot screenshotDriver = driver as ITakesScreenshot;
Screenshot screenCapture = screenshotDriver.GetScreenshot();
screenCapture.SaveAsFile(screenShotDirectory + "\\" + "wrongUserNameAndPassword.png", 
    System.Drawing.Imaging.ImageFormat.Png);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用Selenium WebDriver C#自动创建文本文件并在其中写入异常 - How to create Text file and write exceptions in it automatically using Selenium WebDriver C# 如何使用带有C#的Selenium WebDriver将数据写入Excel文件? - How to write data into an Excel file using Selenium WebDriver with C#? 如何使用 selenium c# webdriver 重命名下载的文件 - How to rename downloaded file using selenium c# webdriver 如何在C#中使用Selenium WebDriver执行本地javascript文件 - How to execute local javascript file using selenium webdriver in C# 如何使用 C# 在 Selenium WebDriver (Selenium 2) 中最大化浏览器窗口? - How to maximize the browser window in Selenium WebDriver (Selenium 2) using C#? 在 C# 中使用 Autoit 在 selenium webdriver 中上传文件 - file upload in selenium webdriver using Autoit in C# 如何使用C#使用Selenium WebDriver知道URL? - How to know a URL is existing using Selenium WebDriver using C#? 如何从Selenium Webdriver C#中的文件中获取输入 - how to take input from file in selenium webdriver c# 在C#中使用Selenium WebDriver下载文件时如何处理保留和丢弃选项按钮 - how to handle keep and discard option button when file is downloaded using selenium webdriver in c# 如何使用Selenium Webdriver在Internet Explorer上获取Cookie-C# - How to get cookies on internet explorer using Selenium webdriver - C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM