0

I am in the beginning stages of learning Selenium/POM and I am curious how something like this would be laid out...

Let's say I have an app with multiple pages, and I have a Class created per page (i.e. HomePage.cs, LogInPage.cs etc....) that has all the locators and actions/logic within the page. If I want to create some Smoke Test that hits all the pages, would I do something like this?

 [TestMethod]
    public void SmokeTest()
    {
        LogIn login = new LogIn();
        //do something
        HomePage homepage = new HomePage();
        //do something
        //do something
        PostsPage postspage = new PostsPage();
        // do something
        // do something
    }

Instantiate each class as I come to it? Or is that not the correct way to structure the test? I understand the basic one page test, but I am really confused as to how my tests need to be structured if they are hitting multiple pages, given the POM design.

1 Answer 1

1

First of all, I would advise to split one, grand, smoke test into smaller chunks.I assume that you are using the MSTest(since you have TestMethod in your code).Use attribute TestClass to mark the class that will contain certain smoke tests.

By splitting your smoke test into smaller ones, you will be able to determine with an ease, what failed and what parts of the applications works fine.Image that, when you have one big test, validation at the beginning fails.The execution would stop here, the rest of the test would not be run.By chopping it, only one of the tests would fail and the rest could be run.

Now back to your main question. What is a good way to handle changing pages? If the change comes with the certain flow in the app(for example, after login in, you are redirected to home page) it is good to return object of the new page in the method that resulting in opening it. Example:

public class LoginPage
{
    private IWebDriver _driver;
    public LoginPage(IWebDriver driver)
    {
        _driver = driver;
    }
    public HomePage LoginAs(string user, string password)
    {
        // Providing user and password and clicking login button
        return new HomePage(_driver);
    }
}

HomePage:

public class HomePage
{
    private IWebDriver _driver;
    public HomePage(IWebDriver driver)
    {
        _driver = driver;
    }
    public HomePage GoTo()
    {
        // Do something
        return this;
    }
    public bool IsAt()
    {
        return true;
    }
}

I also advise to use FluentAssertion. With all of that, the test would look like:

[TestMethod]
public void Test_Login_To_Home_Page()
{
    new LoginPage(this.driver)
        .LoginAs("user", "password")
        .GoTo()
        .IsAt()
        .Should()
        .BeTrue();
}
Sign up to request clarification or add additional context in comments.

3 Comments

Thank you, that makes sense to add a method at the end of each class that returns an object of another page. Also it makes sense to break Tests down into smaller tests , and I agree in general, but for Smoke Test/End to End I can't see how that would work. If I have HomePage, LogInPage, Pages 3-10...how can I break that down if I want to test a whole flow? I cant get to Page 3, 4 etc..without going through LogIn and HomePage first. Make sense? That piece is confusing to me
also, good call on the Fluent Assertions. That will make things much more readable for others! Thanks
If you’re doing a E2E test, that covers certain flow, then you’re right, that should be in one test. When I was reading your question I thought that you want to log in and just validate few pages, without covering particular case.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.