VS Selenium - System.ArgumentNullException:文本不能为空参数名称:文本
VS Selenium - System.ArgumentNullException: text cannot be null Parameter name: text
我正在编写 (Selenium) 单元测试并且 运行 遇到了 NULL 问题。此代码之前 运行 并且可以正常工作,但现在失败了并且没有在所需的字段中输入值。谁能给我一些建议,告诉我哪里出了问题?
单元测试 Objective:导航 Web 服务 UI 并输入应显示结果的值。
DMPage.cs
using System;
using OpenQA.Selenium;
namespace Framework.WebServicePages
{
public class DMPage
{
public static void GoTo()
{
WebServiceDriver.Instance.Navigate().GoToUrl("URL");
}
public static void Wait()
{
WebServiceDriver.Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
}
public static string IsAt
{
get
{
var title = WebServiceDriver.Instance.FindElement(By.XPath(""));
if (title != null)
return title.GetAttribute("Title");
return string.Empty;
}
}
public static ValueCommand EnterValue(string valuenum)
{
return new ValueCommand();
}
}
public class ValueCommand
{
private readonly string valuenum;
public ValueCommand()
{
this.valuenum = valuenum;
}
public void SearchValue()
{
var inputValue = WebServiceDriver.Instance.FindElement(By.XPath(""));
inputValue.SendKeys(valuenum);
var submitValue = WebServiceDriver.Instance.FindElement(By.XPath(""));
submitValue.Click();
}
}
}
DMTests.cs
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ValueMedAutomation.WebServicePages;
namespace Tests.WebServiceTestScripts
{
[TestClass]
public class DMTests
{
[TestInitialize]
public void Init()
{
WebServiceDriver.Initialize();
}
[TestMethod]
public void DM_Meds()
{
DMPage.GoTo();
DMPage.Wait();
DMPage.EnterValue("123456789").SearchValue();
DMPage.Wait();
Assert.AreEqual(DMPage.IsAt, "TEST", "Value failed.");
}
[TestCleanup]
public void Cleanup()
{
WebServiceDriver.Close();
}
}
}
运行 单元测试后出现错误
- 消息:测试方法 Tests.WebServiceTestScripts.DMTests.DM_Med 抛出异常:
System.ArgumentNullException: 文本不能为空
参数名称:text
- 堆栈跟踪:
RemoteWebElement.SendKeys(字符串文本)
ValueCommand.SearchValue()
DMTests.DM_Med()
- CS1717 对同一变量进行赋值;您是要分配其他内容吗?
调试时出错
当 运行 调试时以下行中断:
L41 this.valuenum = valuenum;
L47 inputValue.SendKeys(valuenum);
您忘记在 ValueCommand
的构造函数中传入 string valuenum
class:
在DMPage
内class:
public static ValueCommand EnterValue(string valuenum)
{
return new ValueCommand(valuenum);
}
在ValueCommand
内class:
public ValueCommand(string valuenum)
{
this.valuenum = valuenum;
}
我正在编写 (Selenium) 单元测试并且 运行 遇到了 NULL 问题。此代码之前 运行 并且可以正常工作,但现在失败了并且没有在所需的字段中输入值。谁能给我一些建议,告诉我哪里出了问题?
单元测试 Objective:导航 Web 服务 UI 并输入应显示结果的值。
DMPage.cs
using System;
using OpenQA.Selenium;
namespace Framework.WebServicePages
{
public class DMPage
{
public static void GoTo()
{
WebServiceDriver.Instance.Navigate().GoToUrl("URL");
}
public static void Wait()
{
WebServiceDriver.Instance.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(20);
}
public static string IsAt
{
get
{
var title = WebServiceDriver.Instance.FindElement(By.XPath(""));
if (title != null)
return title.GetAttribute("Title");
return string.Empty;
}
}
public static ValueCommand EnterValue(string valuenum)
{
return new ValueCommand();
}
}
public class ValueCommand
{
private readonly string valuenum;
public ValueCommand()
{
this.valuenum = valuenum;
}
public void SearchValue()
{
var inputValue = WebServiceDriver.Instance.FindElement(By.XPath(""));
inputValue.SendKeys(valuenum);
var submitValue = WebServiceDriver.Instance.FindElement(By.XPath(""));
submitValue.Click();
}
}
}
DMTests.cs
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using ValueMedAutomation.WebServicePages;
namespace Tests.WebServiceTestScripts
{
[TestClass]
public class DMTests
{
[TestInitialize]
public void Init()
{
WebServiceDriver.Initialize();
}
[TestMethod]
public void DM_Meds()
{
DMPage.GoTo();
DMPage.Wait();
DMPage.EnterValue("123456789").SearchValue();
DMPage.Wait();
Assert.AreEqual(DMPage.IsAt, "TEST", "Value failed.");
}
[TestCleanup]
public void Cleanup()
{
WebServiceDriver.Close();
}
}
}
运行 单元测试后出现错误
- 消息:测试方法 Tests.WebServiceTestScripts.DMTests.DM_Med 抛出异常:
System.ArgumentNullException: 文本不能为空 参数名称:text - 堆栈跟踪:
RemoteWebElement.SendKeys(字符串文本)
ValueCommand.SearchValue()
DMTests.DM_Med() - CS1717 对同一变量进行赋值;您是要分配其他内容吗?
调试时出错
当 运行 调试时以下行中断:
L41 this.valuenum = valuenum;
L47 inputValue.SendKeys(valuenum);
您忘记在 ValueCommand
的构造函数中传入 string valuenum
class:
在DMPage
内class:
public static ValueCommand EnterValue(string valuenum)
{
return new ValueCommand(valuenum);
}
在ValueCommand
内class:
public ValueCommand(string valuenum)
{
this.valuenum = valuenum;
}