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 6664257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:35:26+00:00 2026-05-26T02:35:26+00:00

I need to create a few tests for the user roles in a web

  • 0

I need to create a few tests for the user roles in a web application. To minimize the description, one of the tests involves checking if a menu entry is displayed or not for an user.

For this test, I use a table called UserRoles, that looks like this:

sUserName    bDoesntHaveMenuX
User1        1
User2        0
User3        1

bDoesntHaveMenuX is of type bit.

I have a class derived from ValidationRule that checks if a certain text is present in a page, based on a XPath expression to locate the node where to look for the text.
The public properties of this class are:

string XPathExpression
string Text
bool FailIfFound

The last one dictates if the rule should fail if the text is found or not found.

In the test I added a datasource for the table mentioned in the beginning, called DS.
For the request I’m interested in I added a new instance of my validation rule class, with the following values:

Text=MenuX
XPathExpression=//div[@id='menu']//td
FailIfFound={{DS.UserRoles.bDoesntHaveMenuX}}

Unfortunately, this doesn’t work.
The reason seems to be that the data binding process creates a context variable
DS.UserRoles.bDoesntHaveMenuX has the value “False” or “True”. The value is a string, so the binding results in a casting error.

My options, as far as I can think of, are:

  1. Change the validation rule to accept strings for FailIfFound. Not a valid
    option, for 2 reasons: it’s a hack and the same rule is used in
    other places.
  2. Make a new validation rule that will use the above mentioned one,
    and implement the FailIfFound as string. I also don’t like this, for
    the same reason as above. It’s a hack.
  3. Make the test coded and do the proper cast before passing the data
    to the validation rule. I don’t like this one because I prefer to
    have the test as coded only if there is no other way.

Which brings me to the question. Is there another way?

Thank you.

  • 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-05-26T02:35:26+00:00Added an answer on May 26, 2026 at 2:35 am

    So the fundamental issue is that you have no control over how the data-binding treats the ‘bit’ data type, and it’s getting converted to string instead of bool.

    The only solution I can think of (which is sadly still a bit of a hack, but not so egregious as changing FailIfFound to string) is to create a WebTestPlugin, and in the PreRequestDataBinding or PreRequest event, convert the value from string to bool. Don’t forget to add the plugin to your test(s) (easy mistake I have made).

    Then when the validation rule is created it should pick up the nice new bool value and work correctly.

    e.g.

      string val = e.WebTest.Context["DS.UserRoles.bDoesntHaveMenuX"].ToString();
      e.WebTest.Context["DS.UserRoles.bDoesntHaveMenuX"] = (val == "True");
    

    I didn’t actually try this… hope it works.

    EDIT: round two… a better solution

    1. Change the FailIfFound property to string (in a subclass as you mentioned), so it can work properly with data-binding.
    2. Implement a TypeConverter that provides a dropdown list of valid values for the property in the rule’s PropertyGrid (True, False), so in the GUI it looks identical to the rule having FailIfFound as a bool. You can still type your own value into the box when necessary (e.g. for data-binding).
    3. Add the path of the .dll containing the TypeConverter code to your test project’s References section.

    This is what I have started doing and it is much more satisfying than having to type ‘True’ or ‘False’ in the property’s edit box.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create an excel file via C#. I have read a few
I do some examples and i need help with one or few errors. I
I need create custom dialog and put JPanel into it. Is it possible?
i need create an email list sending to many emails. what is best solution
Need to create a custom DNS name server using C which will check against
I need to create a historical timeline starting from 1600's to the present day.
I need to create an XML schema that looks something like this: <xs:element name=wrapperElement>
I need to create a linked server to a DB2 database on a mainframe.
I need to create an ASP page (classic, not ASP.NET) which runs remote shell
I need to create a backup of a SQL Server 2005 Database that's only

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.