0

I use SpecFlow + WatiN + nunit.framework to construct BDD tests for .net

I'd like to check the following functionality on HTML Page:

Scenario: Change user role from 'Admin' to 'User'

Given I have logged in
And I am on the 'Add new user' page
Then the 'Homepage' should not be visible
When I select 'Role' as 'User'
Then the 'Homepage' should be visible

This is a scenario where some property depends on user role. Admin doesn't have Homepage but User does. So the page has an apropriate javascript to show/hide this.

Update: I have made the following method:

[Then(@"'(.*)' (should|should not) be visible")]
public void ThenElementShouldBeVisible(string elementName, string should)
{
    var element = WebBrowser.Current.Elements.First(Find.ByLabelText(elementName));
    Assert.That(should == "should"
                    ? element.Style.Display == "none"
                    : element.Style.Display != "none");
}

But it seems to me that the browser object doesn't update the elements style after Javascript has finished work.

I'm not sure how to check if the element is visible or not using SpecFlow.

Jenninha
  • 1,357
  • 2
  • 20
  • 42
Anubis
  • 2,484
  • 2
  • 22
  • 33
  • Adding `.net` tag as I believe it will require some kind of `.net` language to accomplish. – Jared Farrish May 28 '12 at 15:06
  • Your step "Then the 'Homepage' should not be visible" is wrong in this context. There could be a test to check it is not visible. You should then assert that with C# in your test. You could also write it as "And the 'Homepage' is not visible". – Jenninha Jul 10 '14 at 16:30
  • There should be a test to check it’s not visible AND you could also assert it in one of the given steps if you want to make sure you are on the correct page. – Jenninha Jul 10 '14 at 16:36

1 Answers1

1

You could inject some code to wait for any ajax or asynchronous actions to complete, such as explained in this discussion. However, even with such a solution, we still need to use some Thread.Sleep() here and there.

As a side note, your example seems to be dangerously close to a test script. This is an anti-pattern that you should try to avoid. You can find some guidelines here.

Community
  • 1
  • 1
Dennis Doomen
  • 8,368
  • 1
  • 32
  • 44