无法在Nunit硒中执行第二种测试方法 [英] Not able to execute Second Test Method in Nunit selinium

查看:54
本文介绍了无法在Nunit硒中执行第二种测试方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selinium Webdriver,Nunit框架并正在使用IE浏览器.我有下面的代码. Tt没有执行第二种方法(增加危害).我正在粘贴代码和堆栈跟踪.有人可以告诉我哪里出了问题吗? 预先感谢.

I am using Selinium webdriver, Nunit framework and working with IE browser. I have the below code. Tt is not executing second method(add hazard). I am pasting code and stack trace. Could some one let me know where it went wrong. Thanks in advance.

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");
        }
    }
}

Stacktrace

Stacktrace

est名称:AddHazard 测试全名:Nunit2.SeleniumTest.AddHazard 测试源:C:\ Users \ Anuradh Vanguri \ Documents \ Visual Studio 2015 \ Projects \ Nunit2 \ Nunit2 \ Class1.cs:第72行 测试结果:失败 测试时间:0:00:38.151

est Name: AddHazard Test FullName: Nunit2.SeleniumTest.AddHazard Test Source: C:\Users\Anuradh Vanguri\Documents\Visual Studio 2015\Projects\Nunit2\Nunit2\Class1.cs : line 72 Test Outcome: Failed Test Duration: 0:00:38.151

结果StackTrace:
在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求)中位于c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs:line 154 在OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs:line 114中 在OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ DriverServiceCommandExecutor.cs:line 78 在OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2 parameters)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:line 910中 在OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(字符串机制,字符串值)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:line 954 在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:line 700中的OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath) 在OpenQA.Selenium.By.<> c__DisplayClasse.b__c(ISearchContext上下文)中的c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ By.cs:line 167中 在OpenQA.Selenium.By.FindElement(ISearchContext上下文)中的c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ By.cs:line 309 在OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(按作者)在c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ RemoteWebDriver.cs:line 330 在C:\ Users \ Anuradh Vanguri \ Documents \ Visual Studio 2015 \ Projects \ Nunit2 \ Nunit2 \ Class1.cs:line 74中的Nunit2.SeleniumTest.AddHazard()中 --WebException 在System.Net.HttpWebRequest.GetResponse() 在OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest请求)中位于c:\ Projects \ webdriver \ dotnet \ src \ webdriver \ Remote \ HttpCommandExecutor.cs:line 141 --IOException 在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) 在System.Net.PooledStream.Read处(字节[]缓冲区,Int32偏移量,Int32大小) 在System.Net.Connection.SyncRead(HttpWebRequest请求,布尔userRetrievedStream,布尔probeRead) --SocketException 在System.Net.Sockets.Socket.Receive(Byte []缓冲区,Int32偏移量,Int32大小,SocketFlags socketFlags) 在System.Net.Sockets.NetworkStream.Read(Byte []缓冲区,Int32偏移量,Int32大小) 结果消息: OpenQA.Selenium.WebDriverException:引发了具有空响应的异常,该异常将HTTP请求发送到URL http://localhost:61917/session/a992c864-0c93-45dc-bec8-0d74e68ecceb/element .异常的状态为ReceiveFailure,并且消息为:基础连接已关闭:接收时发生意外错误. ----> System.Net.WebException:基础连接已关闭:接收时发生意外错误. ----> System.IO.IOException:无法从传输连接读取数据:远程主机强行关闭了现有连接. ----> System.Net.Sockets.SocketException:现有连接被远程主机强行关闭

Result StackTrace:
at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:line 154 at OpenQA.Selenium.Remote.HttpCommandExecutor.Execute(Command commandToExecute) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:line 114 at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\DriverServiceCommandExecutor.cs:line 78 at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 910 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 954 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByXPath(String xpath) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 700 at OpenQA.Selenium.By.<>c__DisplayClasse.b__c(ISearchContext context) in c:\Projects\webdriver\dotnet\src\webdriver\By.cs:line 167 at OpenQA.Selenium.By.FindElement(ISearchContext context) in c:\Projects\webdriver\dotnet\src\webdriver\By.cs:line 309 at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\RemoteWebDriver.cs:line 330 at Nunit2.SeleniumTest.AddHazard() in C:\Users\Anuradh Vanguri\Documents\Visual Studio 2015\Projects\Nunit2\Nunit2\Class1.cs:line 74 --WebException at System.Net.HttpWebRequest.GetResponse() at OpenQA.Selenium.Remote.HttpCommandExecutor.CreateResponse(WebRequest request) in c:\Projects\webdriver\dotnet\src\webdriver\Remote\HttpCommandExecutor.cs:line 141 --IOException at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) --SocketException at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) Result Message: OpenQA.Selenium.WebDriverException : A exception with a null response was thrown sending an HTTP request to the remote WebDriver server for URL http://localhost:61917/session/a992c864-0c93-45dc-bec8-0d74e68ecceb/element. The status of the exception was ReceiveFailure, and the message was: The underlying connection was closed: An unexpected error occurred on a receive. ----> System.Net.WebException : The underlying connection was closed: An unexpected error occurred on a receive. ----> System.IO.IOException : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ----> System.Net.Sockets.SocketException : An existing connection was forcibly closed by the remote host

推荐答案

尝试在与IE驱动程序进行交互之间添加超时.

Try to add a timeout between interactions with IE driver.

查看此主题,讨论了一些IE问题: Selenium错误:服务器对URL http:/没有响应/localhost:7055

Look at this topic, some IE problems are discussed: Selenium error: No response from server for url http://localhost:7055

这篇关于无法在Nunit硒中执行第二种测试方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆