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?
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!