我相当确定这是一个简单的答案,但我没有找到答案。
我有一个使用PageObjects编写的脚本。这全部由主“运行测试”类控制,并运行到多个页面对象类。
现在出现的问题是,我需要在脚本的第3步中拾取系统生成的变量,然后在第5步中使用它,但是此变量未传递给该类。
我在做什么错?
主类
class RunTest
{
static IWebDriver driver;
string PlanID; <- Tried setting here?
//Opens Chrome, Navigates to CTSuite, Logs in and Selects desired environment.
[TestFixtureSetUp]
public void Login()
{
... Login Code
}
[Test]
public void Test5()
{
//Set back to home page
driver.FindElement(By.XPath("//*[@id='ajaxLoader']")).Click();
var NetChange = new SwapNetwork(driver);
NetChange.ChangeTheNetwork("LEBC");
var SearchForClient = new GoTo(driver);
SearchForClient.GoToClient("810797");
var NewContract = new NewContracts(driver);
NewContract.AddNewContract("Test5", PlanID); //PlanID is set in this class
var NewFee = new NewFee(driver);
NewFee.AddNewFee("Test5");
var StartChecks = new NewFee(driver);
StartChecks.ExpectationChecks("Test5", PlanID); //Then needs to be used here
}
变量由设置
//Collect plan reference number
string PlanReference = driver.FindElement(By.XPath("//*[@id='ctl00_MainBody_Tabpanel1_lblRecord']")).Text;
Console.WriteLine("Plan Details: " + PlanReference);
var StringLength = PlanReference.Length;
PlanID = PlanReference.Substring(StringLength - 7, 7);
在public void AddNewContract(string testName, string PlanID)
StartCheck类的第一行是计划ID的Console.Writeline
,但始终不返回任何内容
PlanID = PlanReference.Substring(StringLength - 7, 7);
时,您设置传递给此方法的局部变量的值。它对PlanID
中的RunTest
变量没有影响。您需要返回新值并分配它
string planID = PlanReference.Substring(StringLength - 7, 7);
return planID;
// or if you don't need it in the method just
return PlanReference.Substring(StringLength - 7, 7);
并且在RunTest
中>
PlanID = NewContract.AddNewContract("Test5"); // no need to send PlanID