Confirm that the time and date match the current time and date

import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testng.keyword.TestNGBuiltinKeywords as TestNGKW
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import com.kms.katalon.core.windows.keyword.WindowsBuiltinKeywords as Windows
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import static com.kms.katalon.core.testobject.ObjectRepository.findWindowsObject
import io.appium.java_client.AppiumDriver as AppiumDriver
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.MobileElement as MobileElement
import java.text.SimpleDateFormat as SimpleDateFormat
import java.util.Calendar as Calendar
import io.appium.java_client.AppiumDriver
import io.appium.java_client.MobileElement
import java.text.SimpleDateFormat
import java.util.Calendar
import org.openqa.selenium.By
import groovy.time.TimeCategory

Calendar calendar = Calendar.getInstance()
SimpleDateFormat sdf = new SimpleDateFormat(‘yyyy-MM-dd HH:mm:ss’)
String currentDateTime = sdf.format(calendar.getTime())
String elementText = Mobile.verifyElementText(findTestObject(‘GVNew/Time of Last Cards Sync’), 10)
if (elementText == currentDateTime) {
println(“Element date and time match current date and time. Continuing with statements…”)
} else {
println(“Element date and time do not match current date and time. Stopping the test case.”)
}
the error : groovy.lang.MissingMethodException: No signature of method: static com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords.verifyElementText() is applicable for argument types: (com.kms.katalon.core.testobject.MobileTestObject, java.lang.Integer) values: [TestObject - ‘Object Repository/GVNew/Time of Last Cards Sync’, …]
Possible solutions: verifyElementText(com.kms.katalon.core.testobject.TestObject, java.lang.String), verifyElementText(com.kms.katalon.core.testobject.TestObject, java.lang.String, com.kms.katalon.core.model.FailureHandling), verifyElementExist(com.kms.katalon.core.testobject.TestObject, int)

I need to compare the date and time displayed on the screen with the current date and time. I have tried many methods, including using the previous code, but I am encountering an error. I have attempted various approaches without success. Please assist me.

Please use “Code Formatting” for better readability.

Please print the value of elementText and currentDateTime into the system.out and show it to us. This would help us to understand how wrong your code is.

You used the Mobile.verifyElementText with wrong arguments. What’s wrong? Read the doc.

You are expecting the Mobiel.verifyElementText to return a String as the content of an HTML element, but it never does so. Read the doc. The keyword will return a Boolean value (true or false). And Groovy interpreter implicitly conversts the boolean true to a string "true". So your code will always see "true" or "false" as the value of a call to Mobile.verifyElementText(). That’s not what you are expecting.

I believe, you want to use Mobile.waitForElementPresent and Mobile.getText.

The java.util.Calendar class is outdated. Since Java 8, you shouldn’t use it any longer. You should prefer the Date Time API of Java 8. See

The problem unaddressed here comes directly from the title of this thread:

Quote:
Confirm that the time and date [WHERE?] match the current time and date [WHERE?]

Typically, there are at least TWO, usually THREE, sometimes more parts in play, all of which have context relating to current time and and date :

User agent (browser) ← → Web server ← → Database

If you don’t understand the context, you can’t write a meaningful test.