首页 > 解决方案 > 对象引用未设置为对象的实例(基础结构)

问题描述

我的硒测试有问题,这是错误,这意味着我不知道,可能有人可以帮助我解决代码结构吗?

正如我认为语句的结构是正确的,但为什么它在那里是错误的?

错误图片

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

那是我的代码:

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;
            }

        }
    }
}

谢谢!

标签: c#seleniumtesting

解决方案


推荐阅读