I would like to built an nunit project for selenium ui automation. I would like to sign in to the site before running all tests (all of them) and to close the browser after running all tests (all of them).
I can't use the SetUp since it related to fixtures and I want to do it before and after everything.
Do you know who to execute it?
I'm familiar with the SetUp and TearDown attribute. Let me explain it again.
I need some logic to be executed before all tests from all fixtures starts (AKA - First test in the entire assembly) and also some logic to be executed after all tests from all fixtures ended (AKA - Last test in the entire assembly).
This attribute is to identify methods that are called once prior to executing any of the tests in a fixture.
This is the attribute that marks a class that contains the one-time setup or teardown methods for all the test fixtures under a given namespace. The class may contain at most one method marked with the OneTimeSetUpAttribute and one method marked with the OneTimeTearDownAttribute.
Whereas the TestFixtureSetUp is where the test fixture, the required initial state of the system before tests are run, is initialized. Follow this answer to receive notifications.
The Test attribute is one way of marking a method inside a TestFixture class as a test. It is normally used for simple (non-parameterized) tests but may also be applied to parameterized tests without causing any extra test cases to be generated.
If all your test fixtures are within the same namespace then you can use the [SetUpFixture]
attribute to mark a class as the global setup and teardown. You can then put all your login/logout functionality in there.
NUNIT 2.x
namespace MyNamespace.Tests { using System; using NUnit.Framework; [SetUpFixture] public class TestsSetupClass { [SetUp] public void GlobalSetup() { // Do login here. } [TearDown] public void GlobalTeardown() { // Do logout here } } }
See: http://www.nunit.org/index.php?p=setupFixture&r=2.4
NUNIT 3.x
namespace MyNamespace.Tests { using System; using NUnit.Framework; [SetUpFixture] public class TestsSetupClass { [OneTimeSetUp] public void GlobalSetup() { // Do login here. } [OneTimeTearDown] public void GlobalTeardown() { // Do logout here } } }
See: https://github.com/nunit/docs/wiki/SetUpFixture-Attribute
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With