Not able to execute Second Test Method in Nunit selinium

余生长醉 提交于 2019-12-12 03:15:20

问题


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

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

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


回答1:


[TestFixture] requires a public class

 [TestFixture]
 public class SeleniumTest

From Nunit's documentation




回答2:


Try to add a timeout between interactions with IE driver.

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



来源:https://stackoverflow.com/questions/34191047/not-able-to-execute-second-test-method-in-nunit-selinium

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!