Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken tests: help with logic #216

Open
sirj77 opened this issue Aug 26, 2015 · 1 comment
Open

Broken tests: help with logic #216

sirj77 opened this issue Aug 26, 2015 · 1 comment

Comments

@sirj77
Copy link

sirj77 commented Aug 26, 2015

Hi all,

I've bumped into some not really good logic in my objects. I tried to change it, but the results were pretty much the same.
A problem: when I run my tests for some functional part on the site and if one of the tests is failed, then the others probably will be also failed, because of depending.
How to re-write this piece of code to eliminate an issue?

       public HomePage LogInUser(string name, string password)
        {
            if (!LoginLink) return this;
            Find.Element(By.CssSelector(LoginLinkCss)).Click();
            Name = name;
            Password = password;
            SignIn();
            return this;
        }

        public bool LoginLink
        {
            get { return Find.Element(By.CssSelector(LoginLinkCss)).Displayed; }
        }

So, an example what I need to handle:
1st test is failed for some reason (LogInUser method is processed successfully and on some step it is failed, user is still logged in)
2nd test is running (but on the LogInUser method the test is becoming failed, because it gets LoginLink first and then it's trying to find en element By.CssSelector(LoginLinkCss) and:
TestStack.Seleno.Configuration.Interceptors.SelenoReceivedException : Unable to locate element: {"method":"css selector","selector":"[href='https:/my_site/#login']"}, because the user is already logged in)

How to re-write it that even if one test is failed for some reason it will not break the others?

@robdmoore
Copy link
Member

You have two options.

The general way to handle this is to not make assumptions in your tests. If there is a particular context that matters for the test when starting then you should do that (e.g. if the user should start logged off then send them to the log out link as the first thing then perform login).

The second option is to use the Find.OptionalElement method, which will return null if something doesn't exist. You can use that to perform conditional logic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants