Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 98783

How to handle an variable that returns null inside an Assert

$
0
0

I'm hustling around with selenium and having a little hard time with my Assert. I have something like this.

_request = new RestRequest($"applications", Method.GET);
var result = JsonConvert.DeserializeObject<AppRoot[]>(_restClient.Execute(_request).Content);

var org = result.FirstOrDefault(a => a.orgNr.ToString() == "1337");

Assert.IsTrue((org.applicationType == type && org == null) ? true : false, "Failed" + type);

Now if org.applicationType match the type Assert is passing (true).

And if var org = null, I want the Assert to return false, with the message - Failed type

But here the assert is looking for the variable and fails with the classic System.NullReferenceException : Object reference not set to an instance

Any ideas on how this can be handled?

Thanks in advance.


Viewing all articles
Browse latest Browse all 98783

Trending Articles