3

I've created a basic test for checking if some article is displayed and I have a question regarding Page object model. In my solution, I've testing page, base page, map page with element id's, and method page with main logic. Test is something like - open site, navigate to articles, search for 'ArticleX', click on it, add it to the basket, edit the basket. For those operations, I've created 5 tests in my testing page, but now wondering is correct, or I should reduce them? All of them have repeated methods, which I test, for example the last test, called 'Edit basket'. I performing the following operations:

[Test]  
public void TestEditBasket() {  
    logicPage = new LogicPage();  
    logicPage.NavigateTo();
    logicPage.ClickArticles(); 
    logicPage.SearchArticleX();
    logicPage.PressArticleX();   
    logicPage.AddArticleXToBasket(); 
    logicPage.EditBasket(); 

   //this test only checks name, quantity, price when you're editing basket
    Assert.IsTrue(logicPage.ArticleNameInBasket.Text.Contains("ArticleXHeading"));  
    Assert.IsTrue(logicPage.ArticleQuantityInBasket.Text.Contains("1"));   
    Assert.IsTrue(logicPage.ArticlePriceInBasket.Text.Contains("$10")); 

NavigateTo, ClickArticles, SearchArticleX, PressArticleX, AddArticleXToBasket are already tested in the previous tests, but I cannot go directly to the last step - EditBasket, that's why I'm using them in this test. I can delete the other tests and left only this one. But will add around of 10 more asserts. Any advice?

1
  • You've given us an example of a test method, but your question is on POM. Can you add your code for the class that is setup as a page object? – Lee Jensen Feb 5 at 19:24
4

I cannot go directly to the last step

The whole situation is caused by the fact you can't manipulate your application state. It may be an indication that the tools you choose do not match the testability characteristics of your application.

Reconsidering either your tool or the way your application exposes state manipulation APIs may be important for you.

But will add around of 10 more asserts

If you can't manipulate your application's state and still want to get the performance optimization you described, either you can run your tests in parallel* or you would have to add additional asserts indeed.

However, you can keep your @Test functions more clear by pushing down your assert blocks to specific functions or objects:

Assert.IsTrue(logicPage.ArticleNameInBasket.Text.Contains("ArticleXHeading"));  
Assert.IsTrue(logicPage.ArticleQuantityInBasket.Text.Contains("1"));   
Assert.IsTrue(logicPage.ArticlePriceInBasket.Text.Contains("$10")); 

Becomes

validateBasket(
    existingArticleName = "ArticleXHeading", 
    quantityOfItems = 1, 
    price = "$10"
); 

* This will decrease the running time, but, naturally, will not affect the running cost, since you will still process the same flow repeatedly.

0
3

Are you sure you are using Page Object Model?

logicPage.NavigateTo();
logicPage.ClickArticles(); 
logicPage.SearchArticleX();
logicPage.PressArticleX();   
logicPage.AddArticleXToBasket(); 
logicPage.EditBasket(); 

You could have splited NavigateTo() , SearchArticle, EditBasket each one as separate pages

Assuming that these pages are too small to be considered as separate page ,

Lets consider having only one page "loginPage" is correct, still

instead of writing all the steps again you can have two different approaches

  1. Add these repetitive steps in Before hooks`

  2. in the loginPage create a method like navigateToEditScreen

        public navigateToEditScreen(){
           this.NavigateTo();
           this.blabla();
           this.EditScreen();
        } 
    

Now you can loginPage.navigateToEditScreen() instead

0
0

@PDHide I've shorted the test to:

[Test]  
public void TestEditBasket() {  
logicPage = new LogicPage();  
logicPage.BasketAsserts();
Assert.IsTrue(logicPage.ArticleNameInBasket.Text.Contains("ArticleXHeading"));  
Assert.IsTrue(logicPage.ArticleQuantityInBasket.Text.Contains("1"));   
Assert.IsTrue(logicPage.ArticlePriceInBasket.Text.Contains("$10")); 

and put the repeated logic in a separate method in the methods page.There's still repeating, but later I'll try with 'Before' and 'Paralel'

public void BasketAsserts()
    {
        this.NavigateTo();
        this.ClickArticles(); 
        this.SearchArticleX();
        this.PressArticleX();              
        BasketButton.Click();
    }
-1

Share data between tests

In these scenarios what I have done is to save and share data between tests so that once one test is over, next test can pick it up same data to test next step.

The key is don't log off and continue next test from where previous test case left off.

Suite Start


Test 1:

Login Search Article Add Article to basket

Test 2:

Edit basket Save it

Test 3:

Delete basket Log Off

Suite Ends


This approach works best where application is mature and very far and few failures happen as it runs very fast without performing any duplicate steps.

Trade Off

Having said that, there is one big trade off with this approach that if one test fails , all the subsequent tests will fail as there is test dependency .Keep that in mind.

7
  • That's very bad advice, from the maintainability perspective. The more tests you will get - the less reliable they would be and the more harder it would be to maintain and debug them. See testautomationpatterns.org/wiki/index.php/… – 501NotImplemented Feb 10 at 20:49
  • There is no such thing as "Perfect" or best practice , everything depends on context hence trade off as I mentioned in the answer itself. – Vishal Aggarwal Feb 11 at 1:56
  • Also I would love to know why do you think its harder to maintain and debug? – Vishal Aggarwal Feb 11 at 1:57
  • In case you have 15 tests within a fixture (for example), and you need to debug the 8th test - before you'll be able to do that - you need to figure out which tests are performing required preconditions, run them, and verify your changes. And repeat this over and over, while the test will be fixed. – 501NotImplemented Feb 11 at 8:01
  • For the test result analysis - having 15 failed tests in a row will make your test analysis time-consuming since there will be no direct way to find a root cause. That's a widely used antipattern, tests should be hermetic, independent, and manage their own state and preconditions. – 501NotImplemented Feb 11 at 8:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.