我有这个代码:
public void Contacts(string domainToBeTested, string[] browserList, string timeOut, int numberOfBrowsers)
{
verificationErrors = new StringBuilder();
for (int i = 0; i < numberOfBrowsers; i++)
{
ISelenium selenium = new DefaultSelenium("LMTS10", 4444, browserList[i], domainToBeTested);
try
{
selenium.Start();
selenium.Open(domainToBeTested);
selenium.Click("link=Email");
Assert.IsTrue(selenium.IsElementPresent("//div[@id='tabs-2']/p/a/strong"));
selenium.Click("link=Address");
Assert.IsTrue(selenium.IsElementPresent("//div[@id='tabs-3']/p/strong"));
selenium.Click("link=Telephone");
Assert.IsTrue(selenium.IsElementPresent("//div[@id='tabs-1']/ul/li/strong"));
}
catch (AssertionException e)
{
verificationErrors.AppendLine(browserList[i] + " :: " + e.Message);
}
finally
{
selenium.Stop();
}
}
Assert.AreEqual("", verificationErrors.ToString(), verificationErrors.ToString());
}
Run Code Online (Sandbox Code Playgroud)
我的问题是我想这样做,以便我可以在其余代码中多次使用'try'周围的代码.我认为它与包装器有关,但我无法从网上得到一个简单的答案.
所以简单来说,这段代码中唯一改变的是try {}之间的位,其余的是标准代码,我目前使用了100多次,结果是难以维护.
希望这很清楚,非常感谢.
c# ×1