0

I have a problem with my selenium test, here it is error, that meaning I don't know, may be someone can help me with structure of code?

As I think the structure of statement is correct, but why it is error there?

picture of error

System.NullReferenceException: 'Object reference not set to an instance of an object.'

That is my code:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.Remote;
using System.IO;

namespace DVSTesti.Common
{
    public class CustomRemoteWebDriver : RemoteWebDriver
    {
        public static bool useExistingSession = false;

        public static string sessiodIdPath = String.Format(@"{0}\..\..\sessionID.txt", AppDomain.CurrentDomain.BaseDirectory);

        public CustomRemoteWebDriver(Uri remoteAddress, DesiredCapabilities dd) : base(remoteAddress, dd)                
        {
        }

        protected override Response Execute(string driverCommandToExecute, System.Collections.Generic.Dictionary<string,object> parameters)

        {
            if (driverCommandToExecute == DriverCommand.NewSession)
                return ProcessNewSessionAction(parameters);
            else
                return base.Execute(driverCommandToExecute, parameters);
        }

        private Response ProcessNewSessionAction(Dictionary<string, object> parameters)
        {
            useExistingSession = false;

            if (useExistingSession)
            {

                var sidText = File.ReadAllText(sessiodIdPath);
                return new Response
                {
                    SessionId = sidText,
                };
            }
            else
            {
                var response = base.Execute(DriverCommand.NewSession, parameters);
                File.WriteAllText(sessiodIdPath, response.SessionId);
                return response;
            }

        }
    }
}

Thanks!

Alex
  • 1
  • 3
  • 3
    Does this answer your question? [What is a NullReferenceException, and how do I fix it?](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – JamesS Feb 18 '20 at 11:44
  • This is the most frequently asked question on StackOverflow. You need to read [this](https://stackoverflow.com/help/searching) – vasily.sib Feb 18 '20 at 11:47

0 Answers0