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 set partial assertion.

AkhilsAkhils Members
edited November -1 in Sahi - Open Source
Hi All,

I am using "Build: 2009-02-10". I am getting a Successful Completion message after submitting a form.
I am able to assert that message successfully by using following syntax:

_assertExists(_spandiv("---message---"));
_assertContainsText("---message---", _spandiv("---message---"));


But I failed when it comes for partial assertion. Sahi is taking complete message as a string.

Ex. message displays as " Successfully submitted form#123"

I want to put check only on "Successfully submitted" because the numeric value is dynamic it changes in each iteration.

Any buddy plz help me out.

Comments

  • Hi,

    Use regular expression like:

    _assertContainsText(/Successfully submitted/, _spandiv("SpandivName"));

    Regards,
    Pankaj.
  • narayannarayan Administrators
    _assertExists(_spandiv(/Successfully submitted/));
    
    should be enough.
  • AkhilsAkhils Members
    Thanks for quick and easy code.
  • sumeetsumeet Members
    I was trying to use the regEx but it did not worked for me, do you see I did something wrong in below statements.

    _assertContainsText(/button (floatright|floatleft) disabled/, _byId("widget.activitiesList_viewbutton").className);

    OR

    _assertEqual(_byId("widget.activitiesList_viewbutton").className, /button (floatright|floatleft) disabled/);
  • AkhilsAkhils Members
    Try this


    _assertExists(_spandiv(/button (floatright|floatleft) disabled/));
  • sumeetsumeet Members
    This will not work for me as there are be multiple buttons on the web page so i need to test a particular button is disabled. isDisabled is somehow now supported by the button we have, so I need to get the class name to see if its enabled or disabled.
  • AkhilsAkhils Members
    Sumeet ur requirment is not very claer what exactly u want to test. Are u checking that, a particular button is disable or enable?........
  • narayannarayan Administrators
    Sumeet,

    The signature of _assertContainsText is _assertContainsText(expectedText, element, failureMessage). Here the element is a DOM element from the page.

    What you want to check is that the className matches a regex.

    You should do:
    _log(_byId("widget.activitiesList_viewbutton").className);
    _assertNotNull(_byId("widget.activitiesList_viewbutton").className.match(/button (floatright|floatleft) disabled/));
    
    Regards,
    Narayan
  • sumeetsumeet Members
    Thanks Narayan it worked for me.

    But will it work if i specify the failure message with _assertContainsText??? OR is there way to use it with _assertTrue?
Sign In or Register to comment.