Click here to Skip to main content
15,883,705 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Brilliants,

I don't know is this the right place to ask the question. I have developed a Selenium Hybrid Framework in C#. I have two TestCases which are individually running fine. I am reading data from external spread sheet. But if I want to run in parallel by using
[Parallelizable]
attribute, one Testcase shows failed right away and the other Testcase runs perfectly fine. Testcase has been taken randomly. I have used SeleniumWebDriver version from 2.53.0 to 3.12.0. I am trying to resolve the issue last 7 days but din't get any clue. Codes and Exception are given below:

First Testcase:
namespace FA2HybridFramework.TestCases
{
    [TestFixture]
    [Parallelizable]
    public class LoginTest : BaseTest
    {
        //static ExcelReaderFile xls = new ExcelReaderFile(Constants.FA_Xls);
        string testCaseName = "LoginTest";

        [Test, TestCaseSource("getData")]
        public void loginTest(Dictionary<string, string> data)
        {
            //rep = ExtentManager.getInstance();
            ExtentTest test = rep.CreateTest("LoginTest", "This test will describe my Login Test!");

            if (DataUtil.isSkip(xls, testCaseName) || data["Runmode"].Equals("N"))
            {
                test.Log(Status.Skip, "Skipping the Test as Runmode is No");
                Assert.Ignore("Skipping the Test as Runmode is No");
            }
            app = new Keywords(test);

            test.Log(Status.Info, "Starting my FAOnline Login Test");
            test.Log(Status.Info, "Executing Keywords");
            app.executeKeywords(testCaseName, xls, data);
            app.getGenericKeywords().takeScreenshot();
            
        }        
        // Data Source
        public static object[] getData()
        {
            ExcelReaderFile xls = new ExcelReaderFile(Constants.FA_Xls);
            return DataUtil.getData(xls, "LoginTest");
        }        
    }
}

Second TestCase:
namespace FA2HybridFramework.TestCases
{
    [TestFixture]
    [Parallelizable]
    public class CreateDHSAccount : BaseTest
    {
        //static ExcelReaderFile xls = new ExcelReaderFile(Constants.FA_Xls);        
        string testCaseName = "CreateDHSAccount";

        [Test, TestCaseSource("getData")]
        public void createDHSAccount(Dictionary<string, string> data)
        {
           
            //rep = ExtentManager.getInstance();
            ExtentTest test = rep.CreateTest("CreateDHSAccount", "This test will Create DHS Account Test!");
            if (DataUtil.isSkip(xls, testCaseName) || data["Runmode"].Equals("N"))
            {
                test.Log(Status.Skip, "Skipping the Test as Runmode is No");
                Assert.Ignore("Skipping the Test as Runmode is No");
            }
            app = new Keywords(test);

            test.Log(Status.Info, "Starting my Create DHS Account Test");
            test.Log(Status.Info, "Executing Keywords");
            app.executeKeywords(testCaseName, xls, data);
            app.getGenericKeywords().takeScreenshot();
            
        }
        // Data Source
        public static object[] getData()
        {
            ExcelReaderFile xls = new ExcelReaderFile(Constants.FA_Xls);
            return DataUtil.getData(xls, "CreateDHSAccount");
        }
    }
}


Base Test:
namespace FA2HybridFramework.Base
{
    public class BaseTest
    {
        //public ExtentReports rep;
        public ExcelReaderFile xls = new ExcelReaderFile(Constants.FA_Xls);
        public ExtentReports rep = ExtentManager.getInstance();
        public Keywords app = null;
        
        [TearDown]
        public void quit()
        {
            if (rep != null)
                rep.Flush();
            if (app != null)
                app.getGenericKeywords().closeBrowser();

        }
    }
}


openBrowser function:
{
                string filePath = Path.GetDirectoryName(System.AppDomain.CurrentDomain.BaseDirectory);
                filePath = Directory.GetParent(Directory.GetParent(filePath).FullName).FullName;

                if (browserType.Equals("Mozilla"))
                    
                    //driver = new FirefoxDriver(filePath + "\\Drivers");
                    driver = new FirefoxDriver();
                else if (browserType.Equals("Chrome"))
                    driver = new ChromeDriver(filePath + "\\Drivers");
                    //driver = new ChromeDriver();
                else if (browserType.Equals("IE"))
                    driver = new InternetExplorerDriver(filePath + "\\Drivers");
                    //driver = new InternetExplorerDriver();
            }


Exception:

Test Name:	createDHSAccount(System.Collections.Generic.Dictionary`2[System.String,System.String])
Test FullName:	FA2HybridFramework.TestCases.CreateDHSAccount.createDHSAccount(System.Collections.Generic.Dictionary`2[System.String,System.String])
Test Source:	C:\SeleniumFrameworkNew\FA2HybridFramework\FA2HybridFramework\TestCases\CreateDHSAccount.cs : line 21
Test Outcome:	Failed
Test Duration:	0:00:00.0000003

Result1 Name:	createDHSAccount(System.Collections.Generic.Dictionary`2[System.String,System.String])
Result1 Outcome:	Failed
Result1 Duration:	0:00:00.0000001
Result1 StackTrace:
Result1 Message:	
OneTimeSetUp: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
Result1 StandardOutput:
Result1 StandardError:

Result2 Name:	createDHSAccount(System.Collections.Generic.Dictionary`2[System.String,System.String])
Result2 Outcome:	Failed
Result2 Duration:	0:00:00.0000001
Result2 StackTrace:
Result2 Message:	
OneTimeSetUp: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
Result2 StandardOutput:
Result2 StandardError:

Result3 Name:	createDHSAccount(System.Collections.Generic.Dictionary`2[System.String,System.String])
Result3 Outcome:	Failed
Result3 Duration:	0:00:00.0000001
Result3 StackTrace:
Result3 Message:	
OneTimeSetUp: System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation.
  ----> System.InvalidOperationException : Collection was modified; enumeration operation may not execute.
Result3 StandardOutput:
Result3 StandardError:


Please help me. I am in very bad situation.

What I have tried:

If I "Debug Selected Tests" both are working fine.
Posted
Comments
Vibhav Ramcharan 3-Jan-20 9:56am    
Shafikul, I am looking at the date this was posted. Have you found a solution to this?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900