我正在编写(Selenium)单元测试并遇到NULL问题。此代码以前正在运行并正在运行,但现在失败并且未在所需字段中输入值。谁能给我一些关于可能出错的建议?
单元测试目标:导航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();
}
}
}
运行单元测试后的错误
调试时的错误
运行Debug时,以下行会中断:
L41 this.valuenum = valuenum;
L47 inputValue.SendKeys(valuenum);
答案 0 :(得分:0)
您忘记在string valuenum
类的构造函数中传入ValueCommand
:
DMPage
级:
public static ValueCommand EnterValue(string valuenum)
{
return new ValueCommand(valuenum);
}
ValueCommand
级:
public ValueCommand(string valuenum)
{
this.valuenum = valuenum;
}