Verify a variable text

Hello, I got this scenario, when a user access to a specific content, the app automatically adds a view count on the text, I want to verify that text, what I can use, here is the piece of the html:

Training & Pre-Sales

Test test Test

115 views
Training & Pre-Sales

Test1JMNR

65 views
Content & Resources

content new

42 views
Playbook

new playbook for you

37 views
Content & Resources

A third content for Test0

35 views
Training & Pre-Sales

09/20training

34 views
Content & Resources

Frodo Auto Content

21 views
Training & Pre-Sales

test learning track

21 views

The problem is that the box had multiple child objects and I tried to use the xpath or css selector on the first object and the result of the xpath is this one:

//div[contains(text(),‘115 views’)]

it had the 115 vies text on it and its impossible to detect because everytime i execute the test the view increment, what I can use to verify that part?

Thx in advance

hello,
it seems you will not be able to check number since you really dont know what should be there.
but it seems to me that this is unique :

<p><a href="/learn/test-test-test">Test test Test</a></p>

you can use xpath to query sibling of

it text contains ‘views’ string

Andrej Podhajský said:

hello,
it seems you will not be able to check number since you really dont know what should be there.
but it seems to me that this is unique :

<p><a href="/learn/test-test-test">Test test Test</a></p>

you can use xpath to query sibling of

it text contains ‘views’ string

so if I create an xpath to that link I can verify the views if the other object?

to get element i used following xpath:

//a[contains(text(),'Test test Test')]/following::div[1]

so first div after
next, get text of this element and compare if contains ‘views’ text

assert WebUI.getText(findTestObject('Object Repository/__Sandbox/HelloFile/searchforViewText')).indexOf("views") > 0

log from TC:

10-31-2018 08:18:05 AM - [END]    - End action : openBrowser10-31-2018 08:18:05 AM - [START]  - Start action : Statement - assert com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(com.kms.katalon.core.testobject.ObjectRepository.findTestObject(Object Repository/__Sandbox/HelloFile/searchforViewText)).indexOf("views") > 010-31-2018 08:18:05 AM - [INFO]   - Finding Test Object with id 'Object Repository/__Sandbox/HelloFile/searchforViewText'10-31-2018 08:18:05 AM - [INFO]   - Checking object10-31-2018 08:18:05 AM - [INFO]   - Checking timeout10-31-2018 08:18:05 AM - [INFO]   - Finding web element with id: 'Object Repository/__Sandbox/HelloFile/searchforViewText' located by 'By.xpath: //a[contains(text(),'Test test Test')]/following::div[1]' in '30' second(s)10-31-2018 08:18:05 AM - [INFO]   - Found 1 web elements with id: 'Object Repository/__Sandbox/HelloFile/searchforViewText' located by 'By.xpath: //a[contains(text(),'Test test Test')]/following::div[1]' in '30' second(s)10-31-2018 08:18:05 AM - [INFO]   - Getting text of object 'Object Repository/__Sandbox/HelloFile/searchforViewText'10-31-2018 08:18:05 AM - [PASSED] - Text of object 'Object Repository/__Sandbox/HelloFile/searchforViewText' is: '115 views'10-31-2018 08:18:05 AM - [END]    - End action : Statement - assert com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords.getText(com.kms.katalon.core.testobject.ObjectRepository.findTestObject(Object Repository/__Sandbox/HelloFile/searchforViewText)).indexOf("views") > 010-31-2018 08:18:05 AM - [PASSED] - Test Cases/__Sandbox/Check For View10-31-2018 08:18:05 AM - [END]    - End Test Case : Test Cases/__Sandbox/Check For View
1 Like