public class TestClass<T>
{
public void GetIDForPassedInObject(T obj)
{
PropertyInfo[] properties =
obj.GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance);
PropertyInfo IdProperty = (from PropertyInfo property in properties
where property.GetCustomAttributes(typeof(Identifier), true).Length > 0
select property).First();
if(null == IdProperty)
throw new ArgumentException("obj does not have Identifier.");
Object propValue = IdProperty.GetValue(entity, null)
}
}
Тип driver.manage().logs().get(LogType.BROWSER)
- LogEntries
, а не String
.
String
, сделайте следующее: public String getConsoleLogs(WebDriver driver) {
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
String consoleLog = "";
for (LogEntry logEntry : logEntries.getAll()) {
consoleLog += logEntry.toString() + "\n";
}
return consoleLog;
}
File
, сделайте это: public static File writeLogEntriesInATextFile(WebDriver driver, String name) throws IOException {
LogEntries logEntries = driver.manage().logs().get(LogType.BROWSER);
File consoleLog = File.createTempFile(name, "txt");
FileWriter output = new FileWriter(consoleLog);
for (LogEntry logEntry : logEntries.getAll()) {
output.write(logEntry.toString() + "\n");
}
output.close();
return consoleLog;
}
Имейте в виду, что это не работает в FireFox < 65
.
Возвращает записи журнала, а не строки. Используйте следующее, чтобы решить вашу проблему
for (LogEntry entry : driver.manage().logs().get(LogType.BROWSER)) {
String msg = entry.getMessage();
System.err.println("Message: " + msg);
}