其他信息:找不到路径的一部分' C:\ Users \ Admin \ Desktop \ sf.log'。
sf.log不包含在解决方案中,如果我必须得到一个,老实说也不知道在日志中有什么。拜托,我将不胜感激。谢谢!
capability.SetCapability("browserstack.user", username);
capability.SetCapability("browserstack.key", accesskey);
File.AppendAllText("C:\\Users\\Admin\\Desktop\\sf.log", "Starting local");
if (capability.GetCapability("browserstack.local") != null && capability.GetCapability("browserstack.local").ToString() == "true")
{
browserStackLocal = new Local();
List<KeyValuePair<string, string>> bsLocalArgs = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("key", accesskey)
};
browserStackLocal.start(bsLocalArgs);
}
File.AppendAllText("C:\\Users\\Admin\\Desktop\\sf.log", "Starting driver");
driver = new RemoteWebDriver(new Uri("http://" + ConfigurationManager.AppSettings.Get("server") + "/wd/hub/"), capability);
return driver;
}
答案 0 :(得分:0)
如果您尝试写信给用户的桌面,可以使用Environment
课程来获取所需内容:
// Determine the folder name using the desktop path and our .exe name
var rootDir = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var thisExeName = Path.GetFileNameWithoutExtension(Assembly.GetEntryAssembly().Location);
var fileDir = Path.Combine(rootDir, thisExeName);
// Create the folder if it doesn't exist
if (!Directory.Exists(fileDir)) Directory.CreateDirectory(fileDir);
// Now create a variable to store the path to our log file
var fileName = "sf.log";
var filePath = Path.Combine(fileDir, fileName);
但是,如果您只是记录信息,则可以使用AppData
文件夹,这更常见:
// Determine the folder name using the AppData path and our .exe name
var rootDir = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
在任何一种情况下,您现在都有一个有效的路径来创建文件,您应该可以执行以下操作:
File.AppendAllText(filePath, "Starting local");