0

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'

timbre timbre
  • 12,648
  • 10
  • 46
  • 77
m. botts
  • 11
  • 1
  • 2
    In your BeforeAllTests function shouldn't it be: this.objectContainer = container? – gunnerone May 25 '18 at 16:32
  • Please don't post images of code, copy the code into your question and quote the error. – Ron Beyer May 25 '18 at 16:33
  • @gunnerone the code I used is found here https://stackoverflow.com/questions/26392380/nunit-specflow-how-to-share-a-class-instance-for-all-tests/26402692#comment50937280_26402692 that is not how they did it I'm afraid – m. botts May 25 '18 at 17:27
  • Try removing the static from your RunBeforeScenario() function. Their's isn't static – gunnerone May 25 '18 at 19:03

0 Answers0