NewUserRegistration.feature

From Logic Wiki
Jump to: navigation, search


Feature: New User Registration
   In order to get access to the member-only features
   As a potential new user
   I want to create an account

Scenario: Password Strength Indicator
   Given I'm on the registration page
   When I enter a password of Pass
   Then the password strength indicator should read Poor


using System;
using TalkTexh.Specflow;
using WatiNCore;
using NUnit.Framework;
namespace DemoExampleSite.specs
{
  [Binding]
  public class NewUserRegistrationSteps
  {
    [Given]
    public void Given_I_m_on_the_registration_page()
    {
      var ie= new IE("http://localhost:62988/Register.aspx")
      ie.BringToFrontForDemo();

      ScenarioContext.Current.Add("browser", ie);    / to store ie in context
    }
    [When]
    public void When_I_enter_a_password_of_Pass()
    {
      var ie = ScenarioContext.Current["browser"] as IE;
      ie.TextField(Find.ByID("Password")).TypeText("Pass");
      // WatiN TypeText - the js keypress event doesn't fire (it's a BUG in WatiN) 
      ie.Eval("$('#Password').keypress()"); // workaround of the bug above
    }
    [Then]
   public void Then_the_password_strength_indicatopr_should_read_Poor()
   {
      var ie = ScenarioContext.Current["browser"] as IE;
      var stregth = ie.Div(Find.ByID("PasswordStrength")).InnerHtml;
      Assert.AreEqual("Poor", stregth);
     ie.AutoClose = false ; // to see what happened
     ie.Dispose
 
   }


include /DemoHelpers/BrowserDemoHelper.cs to project and take name space from this file and include in Step definition file like

using DemoExampleSite.specs.DemoHelpers;

When we use WatiN we go and edit the properties of "References/Interop.SHDocVw"-> EmbedInteropTypes -> false

Change Project.Specs -> Properties -> AssemblyInfo.cs file and add

[assembly:RequiresSTA]


Refactoring

We create a class

WebBrowser Class

and refactor the code

Refactoring