Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Selenium PageObjects变量处理_C#_Selenium_Selenium Webdriver_Pageobjects - Fatal编程技术网

C# Selenium PageObjects变量处理

C# Selenium PageObjects变量处理,c#,selenium,selenium-webdriver,pageobjects,C#,Selenium,Selenium Webdriver,Pageobjects,我相当肯定这是一个简单的问题,但我没有找到答案 我有一个使用PageObjects编写的脚本。这一切都由主“运行测试”类控制,并运行到几个页面对象类 现在我遇到的问题是,我需要在脚本的第3步中提取一个系统生成的变量,然后在第5步中使用它,但是这个变量并没有传递给那个类 我做错了什么 主类 class RunTest { static IWebDriver driver; string PlanID; <- Tried setting here?

我相当肯定这是一个简单的问题,但我没有找到答案

我有一个使用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
        }
加入
public void AddNewContract(字符串testName,字符串PlanID)


StartCheck类中的第一行是一个
控制台。计划ID的Writeline
,但在执行
PlanID=PlanReference.Substring(StringLength-7,7)时,它始终不返回任何内容设置传递给此方法的局部变量的值。它对
RunTest
中的
PlanID
变量没有影响。您需要返回新值并分配它

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

执行
PlanID=PlanReference.Substring时(StringLength-7,7)设置传递给此方法的局部变量的值。它对
RunTest
中的
PlanID
变量没有影响。您需要返回新值并分配它

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

我尝试过这个解决方案,但我在返回行中遇到了这个错误,因为“NewContracts.AddNewContract(string)”返回void,返回关键字后面不能跟对象表达式“@Smithy7876”,所以将
void
更改为
string
啊,我不知道我可以这样做。打开了一个充满可能性的全新世界!谢谢我尝试过这个解决方案,但我在返回行中遇到了这个错误,因为“NewContracts.AddNewContract(string)”返回void,返回关键字后面不能跟对象表达式“@Smithy7876”,所以将
void
更改为
string
啊,我不知道我可以这样做。打开了一个充满可能性的全新世界!谢谢