using System; using System.Text; using System.Text.RegularExpressions; using System.Threading; using NUnit.Framework; using Selenium; namespace SeleniumTests { [TestFixture] public class NewTest { private ISelenium selenium; private StringBuilder verificationErrors; [SetUp] public void SetupTest() { selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://change-this-to-the-site-you-are-testing/"); selenium.Start(); verificationErrors = new StringBuilder(); } [TearDown] public void TeardownTest() { try { selenium.Stop(); } catch (Exception) { // Ignore errors if unable to close the browser } Assert.AreEqual("", verificationErrors.ToString()); } [Test] public void TheNewTest() { selenium.Open("/"); selenium.Type("kw", "hyddd"); selenium.Click("sb"); selenium.WaitForPageToLoad("30000"); try { Assert.IsTrue(selenium.IsTextPresent("hyddd - 博客園")); } catch (AssertionException e) { verificationErrors.Append(e.Message); } selenium.Click("//table[@id='1']/tbody/tr/td/a/font"); } } } ```
using System; using System.Text; using System.Collections.Generic; using Microsoft.VisualStudio.TestTools.UnitTesting; using Selenium; namespace SeleniumTest { [TestClass] public class UnitTest1 { [TestMethod] public void Test() { //127.0.0.1為Selenium測試服務器位置。 //4444為Selenium測試服務器監聽端口。 //*iexplore為啟動瀏覽器類型,我把它改為了IE瀏覽器。 //http://www.baidu.com為源地址。 ISelenium selenium = new DefaultSelenium("127.0.0.1", 4444, "*iexplore", "http://www.baidu.com"); selenium.Start(); selenium.Open("/"); selenium.Type("kw", "hyddd"); selenium.Click("sb"); selenium.WaitForPageToLoad("30000"); Assert.IsTrue(selenium.IsTextPresent("hyddd - 博客園")); selenium.Click("//table[@id='1']/tbody/tr/td/a/font"); selenium.Close(); selenium.Stop(); } } } ```
進階搜尋
64人線上 (6人在瀏覽線上書籍)
會員: 0
訪客: 64