18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

How to ignore Upper or Lower case in assertion?

tsivatsiva Members
edited August 2013 in Sahi - Open Source
I was doing assert for a content and the content is sometimes changing only lowercase letters to uppercase letters and vice versa. Script is failing just because of the change in case. I don't want to fail it for the small things. I was wondering whether there is any ignoreCase API in Sahi. I have searched through the forums but couldn't find it. I would really appreciate if someone can guide me through this issue. Thanks in advance.

Best Answer

  • edited August 2013 Answer ✓
    Hi tsiva,
    I can try and provide you with a workaround.
    Use the following code with the modifications as per your requirement.
    var $contents = _getValue(_textbox("your_content_getter");
    var $contents_in_lowercase = _getValue(_textbox("your_content_getter").toLowerCase();
    _assertEqual("your_content_in_lowercase", $contents_in_lowercase);
    
    This would make the assertions not fail based on case.
    Regards.

Answers

  • tsivatsiva Members
    Thanks for your help. but i have modified the code as per my requirement below:

    var $contents = _getValue(_paragraph("welcome_info"));
    var $contents_in_lowercase = _getValue(_paragraph("welcome_info").toLowerCase());
    _assertEqual("Welcome to Vehicle Acquisition The VA application is xyz proprietary tool designed to increase productivity and ensure the highest standard of excellence for the VA department.". $contents_in_lowercase);

    I got the beow error after replaying the script:

    _sahi.setServerVar('___lastValue___1377275854592', _getValue(_paragraph("welcome_info").toLowerCase()));
    TypeError: _sahi._paragraph(...).toLowerCase is not a function
    http://lpusamqapp01:9080/_s_/spr/concat.js:3480
    Sahi.prototype.ex@http://lpusamqapp01:9080/_s_/spr/concat.js:3480
    http://lpusamqapp01:9080/_s_/spr/concat.js:3267
  • Hi tsiva,
    What version of Sahi OS are you using?

    Regards.
  • tsivatsiva Members
    sahi-v44
    2013-04-29
  • Hi,
    It says _sahi._paragraph(...).toLowerCase() is not a function. This is because i made a small mistake in the above script.

    Please replace the following line:
    var $contents_in_lowercase = _getValue(_paragraph("welcome_info").toLowerCase());
    

    with this line:
    var $contents_in_lowercase = _getValue(_paragraph("welcome_info")).toLowerCase();
    

    Now it should work for you.

    Regards.
  • tsivatsiva Members
    After using the corrected code it was converting everything into lowercase. But my requirement is, if there are any upper or lower cases are changed then it shouldn't fail the assertion.
    Its failing because of mismatch. The code is not really ignoring the changed case in a word. Please check the below error message. Failed the assertion because of the lower case conversion. My only the requirement is ignoring case from a sentense..not converting to lower case. Could you research for a workaround for me? Thanks for your help

    Expected:"Welcome To VA The VA application is xxx USAs proprietary tool designed to increase productivity and ensure the highest standard of excellence for the VA department."
    Actual:"welcome to va the va application is xxx usas proprietary tool designed to increase productivity and ensure the highest standard of excellence for the va department."
  • Hi tsiva,
    If you want the the test case should pass despite difference in case, you can change both the expected and actual text to lowercase/uppercase WHILE ASSERTING.ie.

    Let $expected be your expected text and $actual be the actual text you're getting.

    If you put your _assertEqual statement in the following manner:
    _assertEqual($expected.toLowerCase(), $actual.toLowerCase());
    

    it is basically ignoring the case and passing the test as you need. I mean to say that you shouldn't change the value of $expected or $actual but simply assert on their lowercase values.

    Regards.
  • tsivatsiva Members
    Hi Pratyush,
    Thanks for your quick response and workaround solution but that's not my requirement was. Don't worry for now.
Sign In or Register to comment.