Ask a Question

Comparing table data in IF not working

SOLVED
Luukdb
Contributor

Comparing table data in IF not working

Hello,

 

I have this weird problem were everything seems correct but TC isn't doing the correct steps.

 

I have a data driven loop, and I am going to check if the product number is a specific product, and it should do the steps I want.

 

This has worked in the past, not sure why it stopped working.

 

In the image below, in the blue box, the product number is filled in - this is correct.

 

For the sake of testing, I added the yellow box - these also give and store the correct values.

 

The problem is in the red box, for some unknown reason it just skips the if.

 

Luukdb_0-1691142554062.png

Below is a small snippet of the test log, and you can see that the log action provided the correct product number.

 

Also, you can see that the text in the textbox is also the correct value.

 

Luukdb_1-1691142645465.png

And lastly a screenshot of the if itself.

Luukdb_2-1691142693079.png

 

Can anybody help me notice the issue?

 

Thanks in advance.

 

Luuk

28 REPLIES 28
rraghvani
Champion Level 3

In the blue section of "If Object", does the if statement also sets the text for ProductNumber or does it only set it in the else statement? The red section may fail because of this.

 

Should Value2 value be in quotes?

 

Apart from that, I can't really see anything wrong.

The "If Object" in the blue section is to check if a column for the product number without - is available.

 

If so, it will enter the product number without -.

 

But in this case that column is not available.

 

I am not sure if Value2 should be in quotes, I can try, I never put quotes there.

Marsha_R
Champion Level 3

Even though the values look like they match, the If is probably failing because there's a type mismatch. @rraghvani has the right idea. You need to force both values into a string so you know for sure they are the same type. You can use the quotes or something like aqConvert

 

https://support.smartbear.com/testcomplete/docs/reference/program-objects/aqconvert/index.html

Luukdb
Contributor

@Marsha_R I tried the quote idea but this didn't work.

 

I put the product number directly in the variable and the IF worked. This means that the data from the table isn't seen the same as if I put it directly in the variable.

I wanted to try the aqConvert, but I am not sure what to do in the keyword test.

Luukdb_0-1691402368968.png

Do you think aqConvert the table data to a string and put it in ProductID works? Or like I am doing now, put the table data in the variable beforehand and convert that to a string?

rraghvani
Champion Level 3

You can use the method like so (not a great example!),

rraghvani_0-1691403592991.png

 

Also, the value that's stored in your variable may contain a line feed or carriage return character and hence the if..statement is not working as you expect.

 

Luukdb
Contributor

Thank you. But this is also not working for this product number..

 

The strange thing is, I ran another test, and here everything works fine. So that means my original code works and your aqConvert works.

 

Now I am very lost why it doesn't work for this product number but other tests are going fine. 

rraghvani
Champion Level 3

You need to check the input and output format of your product number, is what you expect it to be.

 

Unless it's a genuine issue (bug) with TC.

Luukdb
Contributor

I ran the test were the check works and it looks like this.

Luukdb_0-1691416212821.png

The first log is the value from the table data.
The second log is the value from the variable.
The other logs are what the check is supposed to do.

As you can see for this specific scenario, it works

Luukdb_1-1691416321571.png

I am going to run more purchase scenarios and see what the results are going to be. I still think it is strange.

rraghvani
Champion Level 3

The log output may not show "hidden" characters, so don't always rely on it.

 

I can't see anything wrong with your keyword test, so it must be the data format.

cancel
Showing results for 
Search instead for 
Did you mean: