Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7813145
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T04:45:05+00:00 2026-06-02T04:45:05+00:00

I was working in a selenium project in the cs codebehind for an aspx

  • 0

I was working in a selenium project in the cs codebehind for an aspx page but have been trying to transfer my code to an nunit testfixture class. in a class library project. The code below ran without issues in my original cs page, but now I get errors like: ‘LibraryTests.Tests.Driver is a field but is used as a type’, ‘a field initializer cannot reference a non-static field, method, or property ‘LibraryTests.Tests.Driver” and that methods such as GoToURL must have a return type.

IWebDriver driver = new FirefoxDriver();
driver.Navigate().GoToUrl(urlString);
IWebElement name = driver.FindElement(By.Id("UserName"));
IWebElement button = driver.FindElement(By.ClassName("sign in"));

I want to be able to execute the code above before running any tests for efficiency reasons. How do I make this code work in a testfixture class?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T04:45:06+00:00Added an answer on June 2, 2026 at 4:45 am

    I think you want to put the code into a TestFixtureSetup method:

    [TestFixture]
    class MyTestFixture
    {
        protected IWebDriver driver;
        protected IWebElement name;
        protected IWebElement button;
    
        [TestFixtureSetUp]
        public void Init()
        {
            driver = new FirefoxDriver();
            driver.Navigate().GoToUrl(urlString);
            name = driver.FindElement(By.Id("UserName"));
            button = driver.FindElement(By.ClassName("sign in"));
        }
    
        [Test]
        public void MyTest
        {
         // ...
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We have Capybara working with the selenium driver but when I try to use
Background I have been working towards automating my Selenium test suite that I developed
I'm working on a project using Scala running Selenium tests as part of a
I'm working on a project which is using Selenium and I'd like to try
I am working with a tester who is using Selenium in my latest project.
I'm working with selenium. while trying to click a button it creates a pop
I've been working for 2 months and a half in a project and it
I'm working with Selenium 2 WebDriver in Eclipse and everything works fine. But when
I have Selenium server working with PHPUnit on a MAMP local server. When an
I have a project with several features in cucumber both plain and selenium are

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.