BDD user interface components with WatiN and SpecFlow

My question focuses on if my installation currently matches the best practices for BDD with UI acceptance testing. I use WatiN with SpecFlow to create tests for receiving the user interface, and I deploy my application to AppHarbor (cloud platform as a service for .Net applications). AppHarbor runs your unit / integration tests during deployment and only pushes your site live if your tests pass. So I started by first writing a basic test with an error like this:

Scenario: Navigation to homepage When I navigate to / Then I should be on the application homepage 

The steps associated with this test open a browser using WatiN and confirm that the title attribute for the presentation is set to "Welcome." I am checking the environment to decide which URL to test using the WatiN browser. For example, if in development, go to "http: // localhost: 49641 /" for home. Otherwise, go to "http://myappharborapp.com/".

My problem is that if you are deploying this application for the first time, the page or presentation doesn’t actually exist, so the test doesn’t work (because the site is not yet live. It will also fail if, for example, I add the “About” program later and I’ll write a failure first.When I click on updates, the test will fail because page “O” does not exist yet.

My question is: I am not following best practices regarding how you should customize your user interface tests? How should these tests be configured to pass in any environment?

Any insight is greatly appreciated!

+4
source share
1 answer

In the "traditional" watin tests, I use custom attributes to indicate which version of the application and which environment it is running, and then the test is skipped if there is no criticism.

(The open source code is located at http://testingstax.codeplex.com in the environment monitor parkcalc> observer>

  internal static void CheckSetEnvironment() { Object[] attributes = Utility.GetCallerAttributes(typeof(ExecutionEnvironment), 3); CheckEnvironment(attributes); } private static void CheckEnvironment(Object[] attributes) { TestEnvironment = GetCurrentEnvironment(); if (attributes.Length > 0 && !attributes.Contains(new ExecutionEnvironment(TestEnvironment))) { Assert.Inconclusive("This test is not designed to be executed in the '" + TestEnvironment.ToString() + "' environment."); } } private static EnvironmentType GetCurrentEnvironment() { string currentEnvironment = ConfigurationManager.AppSettings["Environment"].ToLower(CultureInfo.CurrentCulture); EnvironmentType Environment = new EnvironmentType(); try { Environment = (EnvironmentType)Enum.Parse(typeof(EnvironmentType), currentEnvironment, true); } catch (System.ArgumentException) { Assert.Fail(" The current environment setting in 'Environment' in the app.config is invalid."); } return Environment; } 

Then the trick was to display the counter action in order to ignore the test

"Given that the test does not work in production" or something like that

+3
source

Source: https://habr.com/ru/post/1338122/


All Articles