This is a migrated thread and some comments may be shown as answers.

How to get around the error element not found

3 Answers 75 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Pieter
Top achievements
Rank 1
Pieter asked on 09 Jul 2015, 12:49 PM

Hi,

 we are currently facing an issue with the following scenario.

We use excel to test multiple logins

In a specific scenario an error message is displayed (when using a specific user), when the error message is displayed we want the test to break. I tried the logical steps but it did not work for me.

I then created my own coded step.

What it does is it has an if else statement, but as soon as the step is reached the error has not yet been thrown.  So I then get the Element not found error.

I don't want an error to be thrown as this is the functionality is correct.  However when the test is rerun with the new user name and password, we want it to break.

So here is my problem.
string userLogedin = Data["userName"].ToString();
try
{
bool Error = true;
Error = Pages.Page.errorMessage.IsEnabled;

if (Error == true)
{
Console.WriteLine("an error occured in the tests");
Console.ReadLine();
Log.CaptureBrowser(ActiveBrowser, "C:\\Users\\user\\Pictures\\Page"+DateTime.Now.ToString("MM_dd_yyyy_HH_mm_ffff")+".png", true);
Log.WriteLine(LogType.Error, "Login failed");
}

else
{
Element ErrorMessage = Manager.ActiveBrowser.Find.ById("ctl00_maincontent_lblHeader");
Assert.IsNull(ErrorMessage);
}
}
catch
{
}

Now using this code, it works correctly for the user who does not get the error, but when the user comes in where the error should be displayed it does not fail the test.

This part

Log.WriteLine(LogType.Error, "Login failed");

 Does not seem to work.

I keep getting an error that it is trying to convert it to a exception.

So I am in a catch 22 situation.

The test that should succeed, succeeds.  The test that needs to fail, succeeds.

The test that should succeed, fails.  The test that needs to fail, fails.

Can you please point me into the right direction?  this is rather critical, as this will be the base for check where elements are not available in certain scenario's.

Thank you in advance.

3 Answers, 1 is accepted

Sort by
0
Ivaylo
Telerik team
answered on 14 Jul 2015, 12:22 PM
Hello Pieter,

I do not see the need to use if else in a try catch. What is the point of this? What exactly you are trying to achieve, provide example.

Also it looks now the code you are using is not entering in the if statement, and does not output nothing since the catch is empty. Furthermore I am sure that you can accomplish this scenario without using code.

In order to assist you any further we need access to the application with exact scenario and the test you are trying to execute. Please if this is any sensitive data you need to provide it in a ticket, not in a public thread.

Regards,
Ivaylo
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
0
Pieter
Top achievements
Rank 1
answered on 14 Jul 2015, 01:22 PM

Hi Ivaylo,

 thank you for the reply.

I just spoke to Ryan as he gave me a demo on test studio.

He also showed me how to get past this. but thank you for the reply.

0
Ivaylo
Telerik team
answered on 17 Jul 2015, 07:47 AM
Hello Pieter,

Thanks for the update. Glad to hear you got this passed.

Regards,
Ivaylo
Telerik
 
The New Release of Telerik Test Studio Is Here! Download, install,
and send us your feedback!
Tags
General Discussions
Asked by
Pieter
Top achievements
Rank 1
Answers by
Ivaylo
Telerik team
Pieter
Top achievements
Rank 1
Share this question
or