简体   繁体   中英

Passing values to other methods

I need to pass a value from one Method to the other so I can compare two numbers. But I can't get the number from the first method to the second one. To be more exact, I would like to get the value of rowsBeforeFilterApplied from method CheckReports() to the second method VerifyFilterFunctionality() so I could use the Assert and compare both values.

In the current setup, the problem is that

rowsBeforeFilterApplied does not exist in the current context.

Any help would be appreciated.

在此处输入图像描述

public void CheckReports()
{
    int rowsBeforeFilterApplied = SeleniumDriver.ChromeDriver.FindElements(By.XPath("//*[@id='root']/div/div[2]/div[3]/div/table/tbody/tr")).Count;
}

      

public void VerifyFilterFunctionality()
{
    int rowsWhenFilterApplied = SeleniumDriver.ChromeDriver.FindElements(By.XPath("//*[@id='root']/div/div[2]/div[3]/div/table/tbody/tr")).Count;
    System.Threading.Thread.Sleep(200);//SLEEP

           
    Assert.Greater(rowsBeforeFilterApplied, rowsWhenFilterApplied);
}
public int CheckReports()
    { 
        
        int rowsBeforeFilterApplied = SeleniumDriver.ChromeDriver.FindElements(By.XPath("//*[@id='root']/div/div[2]/div[3]/div/table/tbody/tr")).Count;

return rowsBeforeFilterApplied 
    }

public void VerifyFilterFunctionality()
    {    
         int rowsBeforeFilterApplied = CheckReports();
         System.Threading.Thread.Sleep(200);//SLEEP
         int rowsWhenFilterApplied = SeleniumDriver.ChromeDriver.FindElements(By.XPath("//*[@id='root']/div/div[2]/div[3]/div/table/tbody/tr")).Count;
         System.Threading.Thread.Sleep(200);//SLEEP

       
         Assert.Greater(rowsBeforeFilterApplied, rowsWhenFilterApplied);
    }

You also can declare both variable globally

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM