I'm currently trying to implement a scroll feature for my SpecFlow tests I'm running through Selenium to test a website. I need to be able to scroll down so the driver can see certain elements and test them. Basically, I've coded a scroll feature (using webdriver as IJavaSriptExecutor) but when I implemented that step to my tests it would try and open a separate webdriver. I need this scroll feature to execute on the driver that is currently open testing other features. Basically I need everything to be in unison if that makes sense. Anyway here is my code with the error at the bottom. I have no idea what the issue is.
namespace (mynamespace)
{
[Binding]
public class SeleniumContext
{
public SeleniumContext()
{
//create the selenium context
WebDriver = new ChromeDriver();
}
public IWebDriver WebDriver { get; private set; }
}
public class BeforeAllTests
{
private readonly IWebDriver objectContainer;
private static SeleniumContext seleniumContext;
public BeforeAllTests(IWebDriver container)
{
this.objectContainer = objectContainer;
}
[BeforeTestRun]
public static void RunBeforeAllTests()
{
seleniumContext = new SeleniumContext();
}
[BeforeScenario]
public static void RunBeforeScenario()
{
objectContainer.RegisterInstanceAs<SeleniumContext>(seleniumContext);
}
[Then(@"I scroll down")]
public void ThenIScrollDown()
{
ScenarioContext.Current.Pending();
}
}
}
Severity Code Description Project File Line Suppression State Error CS0120 An object reference is required for the non-static field, method, or property 'BeforeAllTests.objectContainer'