0

Here is the HTML code :

<div class="ijd-card" ng-click="selectThisJD()" style="cursor: pointer">

                                                <div class="item-counter clearfix ng-binding" style="text-align: left; padding-left: 40px; padding-right: 40px;">#2
                                                    <!-- ngIf: eachRecommendedJD.like_count -->
                                                    <!-- ngIf: eachRecommendedJD.dislike_count -->
                                                </div><!--<p >{{eachRecommendedJD[1]}}</p>-->
                                                <p ng-bind-html="get_jd(eachRecommendedJD.job_desc)" class="ng-binding"><p class="padding-top-10">Proficiency in AngularJS, Javascript, Grunt, Protractor<br>Knowledge in Python, Ming Database ORM, MongoDB will be a pulse<br>Proficiency in Object Oriented design.<br>Experience in REST API.<br>Experience with Amazon web services.<br>Exposure to GIT software<br>Basic Qualifications<br>Bachelor degree in Computer Science or Computer Engineering (B. Tech / B. E. / B. Sc. Comp Science)<br>Experience: 7+ years <br> </p><p class="padding-top-10 padding-xs-15" itemprop="skills">
 <span class="pull-left padding-bottom-10">
  <a class="label label-info margin-right-5">
   AngularJS
  </a>
 </span>
 <span class="pull-left padding-bottom-10">
  <a class="label label-info margin-right-5">
   Javascript
  </a>
 </span>
 <span class="pull-left padding-bottom-10">
  <a class="label label-info margin-right-5">
   Grunt
  </a>
 </span>
 <span class="pull-left padding-bottom-10">
  <a class="label label-info margin-right-5">
   Protractor
  </a>
 </span>
</p><p class="padding-top-10 padding-xs-15"> </p></p>
                                            </div>

In the above paragraph 7+ years experience is the number.

Problem: I am giving the experience range from 1 to 10 years and i am getting the above result(HTML code). Now i want to verify weather the experience range is displaying as per the range or not.

How to verify the range?

nrs
  • 937
  • 3
  • 17
  • 42

2 Answers2

1

Extract the experience value first, then you can apply the toBeWithinRange matcher from jasmine-matchers:

var elm = $(".padding-top-10");  // TODO: bad locator - have not enough information to provide a better one
elm.getText().then(function (text) {
    var pattern = /Experience: (\d+)\+ years/gi;
    var match = pattern.exec(text);

    var value = parseInt(match[1]);

    expect(value).toBeWithinRange(1, 10);  // borders included
});

Also see: Checking two boundaries with Jasmine (between matcher), which shows that you can also do the simple boolean check:

expect(value >= 1 && value <= 10).toBeTruthy();
Community
  • 1
  • 1
alecxe
  • 462,703
  • 120
  • 1,088
  • 1,195
  • It's not working...Returning null value..I had updated HTML code please have a look.. – nrs Aug 23 '16 at 07:37
  • @raghavendrat I hope you still get the main idea. I'd first see if `text` is what you expect to get and contains the `Experience: ...` part. Then, check/tweak the regular expression to extract the digits. Hope you can make it work, thanks. – alecxe Aug 23 '16 at 19:08
0

You can use expect(experience).toBeGreaterThan(0) and expect(experience).toBeLessThan(11) to validate the range.

Sudharsan Selvaraj
  • 4,792
  • 3
  • 14
  • 22
  • how can i get the experience value from the page..(i.e: I have to search entire page to get the experience value) – nrs Aug 23 '16 at 09:37