我使用webdriver的Selinium,NUnit的框架,並與IE瀏覽器合作,以執行第二個測試方法。我有下面的代碼。 Tt沒有執行第二種方法(增加危險)。我正在粘貼代碼和堆棧跟蹤。有人能讓我知道哪裏出了問題。 在此先感謝。無法在NUnit的selinium
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.IE;
using NUnit.Framework;
using OpenQA.Selenium.Interactions;
using OpenQA.Selenium.Support.UI;
namespace Nunit2
{
[TestFixture]
class SeleniumTest
{
public IWebDriver driver;
[TestFixtureSetUp]
public void SetUp()
{
driver = new InternetExplorerDriver(@"C:\Selenium_App\IE DriverServer_32bit2.48.0");
driver.Navigate().GoToUrl("https://testwebsite");
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(6000));
IWebElement loginbutton = driver.FindElement(By.Id("Image2"));
loginbutton.Click();
System.Console.WriteLine("page title is" + driver.Title);
driver.FindElement(By.Id("Loginlogin")).SendKeys("AutomationUser");
driver.FindElement(By.Id("Loginpassword")).SendKeys("safety35");
IWebElement log = driver.FindElement(By.Id("LoginButton_DoLogin"));
log.Click();
}
[TestFixtureTearDown]
public void TearDown()
{
driver.Quit();
driver.Dispose();
}
[Test]
public void AddAction()
{
// driver.Navigate().GoToUrl("https://test.riskmanager.co.nz/");
// driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(6000));
//IWebElement loginbutton = driver.FindElement(By.Id("Image2"));
//loginbutton.Click();
//System.Console.WriteLine("page title is" + driver.Title);
//driver.FindElement(By.Id("Loginlogin")).SendKeys("AutomationUser");
//driver.FindElement(By.Id("Loginpassword")).SendKeys("safety35");
//IWebElement log = driver.FindElement(By.Id("LoginButton_DoLogin"));
//log.Click();
// driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(1000));
Actions action = new Actions(driver);
IWebElement actionsMenu = driver.FindElement(By.XPath(".//div[2]/ul/li[2]/a/span[1]"));
action.MoveToElement(actionsMenu).Build().Perform();
driver.FindElement(By.XPath(".//div[2]/ul/li[2]/ul/li[1]/a/span")).Click();
IWebElement actiontitle = driver.FindElement(By.Id("actrpnlActionTitleInputtitle"));
actiontitle.SendKeys("Testaction");
driver.FindElement(By.Id("actrpnlDateDueInputdatedue")).SendKeys("16 Nov 16");
IWebElement element = driver.FindElement(By.Id("actrpnlReportingLineInputpnlLineDropdownlineid"));
SelectElement select = new SelectElement(element);
select.SelectByValue("196E");
IWebElement PersonResponsible = driver.FindElement(By.Id("actrpnlPersonResponsibleInputempText"));
PersonResponsible.SendKeys("a");
IWebElement se = driver.FindElement(By.XPath(".//html/body/ul[2]/li/a"));
se.Click();
IWebElement Addaction = driver.FindElement(By.Id("actrButton_Insert"));
Addaction.Click();
}
[Test]
public void AddHazard()
{
Actions hazard = new Actions(driver);
IWebElement hazardmenu = driver.FindElement(By.XPath(".//div[3]/ul/li[3]/a/span[1]"));
hazard.MoveToElement(hazardmenu).Build().Perform();
driver.FindElement(By.XPath(".//div[3]/ul/li[3]/ul/li[1]/a/span")).Click();
System.Console.WriteLine("second test");
}
}
}
堆棧跟蹤
共青名稱:AddHazard 測試真實姓名:Nunit2.SeleniumTest.AddHazard 測試來源:C:\用戶\ Anuradh Vanguri \文檔\ Visual Studio的2015年\項目\ Nunit2 \ Nunit2 \的Class1的.cs:線72 測試結果:失敗 測試持續時間:0:00:38.151
結果堆棧跟蹤:
在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest的請求)在C:\項目\我們bdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs:第154行 位於c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs中的OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(命令commandToExecute) :第114行 位於c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ DriverServiceCommandExecutor.cs中的OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(命令commandToExecute)行:第012行: 第78行:在C執行(字符串driverCommandToExecute,Dictionary`2參數):\項目\的webdriver \ DOTNET \ SRC \的webdriver \遠程\ RemoteWebDriver.cs:線910 在OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(字符串機構,字符串值)在C:\項目\的webdriver \ DOTNET \ SRC \的webdriver \遠程\ RemoteWebDriver.cs:線954 在OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(字符串XPA th)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs中:第700行 位於OpenQA.Selenium.By。 <> c__DisplayClasse.b__c在C(ISearchContext上下文):\項目\的webdriver \ DOTNET \ SRC \的webdriver \ By.cs:線167 在OpenQA.Selenium.By.FindElement(ISearchContext上下文)在C:\項目\的webdriver \ dotnet \ src \ webdriver \ By.cs:第309行 位於c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs中的OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(by by)中:line 330 在C:\ Users \ Anuradh Vanguri \ Documents \ Visual Studio 2015 \ Projects \ Nunit2 \ Nunit2 \ Class1.cs中的Nunit2.SeleniumTest.AddHazard():74行 --WebException at System.Net.HttpWebRequest.GetResponse at c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs中的OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest請求):第141行 --IOException 在System.Net.Sockets.NetworkStream.Read(字節[]緩衝液,的Int32偏移的Int32大小) 在System.Net.PooledStream.Read(字節[]緩衝液,的Int32偏移的Int32大小) 在System.Net。 Connection.SyncRead(HttpWebRequest請求,布爾userRetrievedStream,布爾probeRead) --SocketException 在System.Net.Sockets.Socket.Receive(字節[]緩衝區,Int32偏移量,Int32大小,SocketFlags socketFlags) 在System.Net.Sockets .NetworkStream.Read(Byte []緩衝區,Int32偏移量,Int32大小) 結果消息: OpenQA.Selenium.WebDriverException:拋出了一個空響應異常,向遠程WebDriver服務器發送HTTP請求,URL爲http://localhost:61917/session/a992c864-0c93-45dc-bec8-0d74e68ecceb/element。異常的狀態是ReceiveFailure,消息是:底層連接已關閉:接收時發生意外錯誤。 ----> System.Net.WebException:底層連接已關閉:接收時發生意外錯誤。 ----> System.IO.IOException:無法從傳輸連接讀取數據:現有連接被遠程主機強制關閉。 ----> System.Net。Sockets.SocketException:一個現有的連接被強制由遠程主機