0

I have a test using selenium C# webdriver chorme on windows 10. When i am running this test one at a time it is working fine. I am using the same test for loadtest in visual studio 2017. There I am am trying to run multiple instance of the same test. The first instance is always getting executed perfectly , but all the rest are not recognizing the web element and throwing the error mentioned below.

Test method LoadWebTestPOC.WebTestM.LoginWithCredentials threw exception: OpenQA.Selenium.WebDriverException: Unexpected error. System.Net.WebException: Unable to connect to the remote server ---> System.Net.Sockets.SocketException: No connection could be made because the target machine actively refused it 127.0.0.1:54049 at System.Net.Sockets.Socket.DoConnect(EndPoint endPointSnapshot, SocketAddress socketAddress) at System.Net.ServicePoint.ConnectSocketInternal(Boolean connectFailure, Socket s4, Socket s6, Socket& socket, IPAddress& address, ConnectSocketState state, IAsyncResult asyncResult, Exception& exception) --- End of inner exception stack trace --- at System.Net.HttpWebRequest.GetRequestStream(TransportContext& context) at System.Net.HttpWebRequest.GetRequestStream() at

Could someone help me please. Thanks in advance.

I have seen similar issue here Selenium web driver fails after the first test run and TestFixtureTearDown happens

Here is the code how i am initializing the test

namespace LoadWebTestPOC
{
    [TestClass]
    public class WebTestM
    { 



    public string user = "Administrator";
    public string password = "*******";


    [TestInitialize]
    public void SetupTest()
    {
        Installer.SetUpEnv();
    }

    [TestCleanup]

    public void TeardownTest()
    {
        Base.QuitDriver();
    }

    [TestMethod]
    public void LoginWithCredentials()
    {
        LoginModule.NavigateTo();
        LoginModule.LoginWithCredentials(user,password);
        NUnit.Framework.Assert.AreEqual(user, CoreOperation.GetAttributeValue(LoginModuleLocators.iconLogedUser, "title")); 
    }
}
}


public static void SetUpEnv()
    {

     string _driver = CHROME;
     public static void SetupLocal(_driver)
    {
        switch (_driver)
                {
                    case "CHROME":
                        Base.Driver = Base.StartDriver(AvDriver.Chrome);
                        Base.ChosenDriverName = "chrome";
                        break;
                    case "FIREFOX":
                        Base.Driver = Base.StartDriver(AvDriver.Firefox);
                        Base.ChosenDriverName = "firefox";
                        break;
                    case "EDGE":
                        Base.Driver = Base.StartDriver(AvDriver.Edge);
                        Base.ChosenDriverName = "edge";
                        break;
                    case "SAFARI":
                        Base.Driver = Base.StartDriver(AvDriver.Safari);
                        Base.ChosenDriverName = "safari";
                        break;
                    default:
                        Base.Driver = Base.StartDriver(AvDriver.Chrome);
                        Base.ChosenDriverName = "chrome";
                        break;
                }
        }
    }


 public static IWebDriver StartDriver(AvDriver chosenDriver)
    {
        switch (chosenDriver)
        {
            case AvDriver.Chrome:
                Driver = new ChromeDriver(_driversPath);
                break;
            case AvDriver.Firefox:
                Driver = new FirefoxDriver(FirefoxDriverService.CreateDefaultService(_driversPath));
                break;
            case AvDriver.Edge:
                Driver = new EdgeDriver(_driversPath);
                break;
            case AvDriver.Safari:
                Driver = new SafariDriver();
                break;
        }

        Driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(10);
        Driver.Manage().Window.Maximize();
        return Driver;
    }

1 Answer 1

0

You can use the RepeatAttribute to run the test multiple times if you use nunit, however, if you want to do it at the same time you should really look into running a Selenium-Grid to distribute the tests over multiple instances of your chosen browser.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.