有 Silenium 服务器、NUnit、WebDriver。
我有带有以下代码的 C# dll:
private IWebDriver driver;
// ...
driver = new InternetExplorerDriver();
// ...
[Test]
public void test()
{
string testURL = "file:/C:/Tests/test.html";
driver.Navigate().GoToUrl(testURL);
IJavaScriptExecutor js = driver as IJavaScriptExecutor;
object resFunc = js.ExecuteScript("open_form");
object res = js.ExecuteAsyncScript("alert('hello')");
}
文件test.html
看起来像:
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<script type="text/javascript" src="./test.js"></script>
</head>
<body unselectable="on">
</body>
</html>
和test.js
function open_form () {
document.body.style.backgroundColor = "green";
}
我用控制台 NUnit 运行测试,当出现“hello”时,背景颜色没有改变。如何运行 html 中的函数并执行某些操作?