1

I am attempting to ensure that hours are not off minutes I am not too concerned with but can't seem to break them off the code. Is there a way to allow the assertion to be 10 minutes off?

    public void DeviceTimeAssertion()
    {
        IWebElement TimeTitle = _driver.FindElementByXPath(" 
        (//android.widget.TextView[@content-desc='xpathvalue'])[1]");
        string Time = DateTime.Now.ToString("MM/dd/yy h:mm tt");
        //string Time = DateTime.Now.ToString("MM/dd/yy h:mm"); 
        string ActText = TimeTitle.Text;
        string ExpectedTime = "Check-in: " + Time;
        //if (ExpText.Equals(ActText))
        Assert.AreEqual(ExpectedTime, ActText);

1 Answer 1

2

I think you need to do that with actual DateTime objects. You can try to do that:

var time = DateTime.Now;
var actText = TimeTitle.Text;
var isTime = DateTime.TryParse(actText.Split(' ')[1], out var actTime)
if(isTime) 
{
  var diff = TimeSpan.FromMinutes(10);
  Assert.IsTrue(time + diff > actTime && time - diff < actTime);
}
else
{
  throw new ArgumentException("There was no Time in the text :(");
}

Hope that helps

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.