Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7693273
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:03:06+00:00 2026-05-31T21:03:06+00:00

I have been writing Selenium test for web application and there seem to be

  • 0

I have been writing Selenium test for web application and there seem to be multiple instances of Internal Server Error in application in case of Internal Server Error, application displays custom error page and and error id is displayed to user to pursue matter with technical team, in case user encounter it.

This makes it a little laborious to debug the test failures during Selenium execution.
I was thinking to use some mechanism to keep polling a page with each step executed in test to find if there was any instance of Internal Server error, And this is when I came across Junit Rule and thought of writing a custom annotation for it, some thing like –

public class SelTestCase {
    protected WebDriver driver;

    @Before
    public void startDriver() {
        driver = new FirefoxDriver();
        driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
        driver.get("http://www.google.com/");
    }

    @After
    public void closeDriver() {
        driver.quit();
    }
}

public class GoogleSearchTest extends SelTestCase {

    @Rule
    PageChecker pageChecker = new PageChecker();

    @Test
    @CheckPage
    public void testGoogleSearch() {
        GoogleHomePage googleHomePage = PageFactory.initElements(driver,
                GoogleHomePage.class);
        googleHomePage.searchGoogle("Selenium HQ");
        assert driver.getPageSource().contains("seleniumhq") : "Selenium headquarter search failed";
    }
}

SelTestCase class creates instance of WebDriver to execute test, And here is the PageChecker class –

public class PageChecker extends SelTestCase {

    @Retention(RetentionPolicy.RUNTIME)
    @Target({ElementType.METHOD})
    public @interface CheckPage {
        // page check should take place here (Though not sure if it is right place)     
        // like if(driver.getPageSource.contains("Internal Server Error") {throw Exception ("Err")}
    }

}

This is what I am stuck with, how do I proceed with CheckPage annonations?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T21:03:07+00:00Added an answer on May 31, 2026 at 9:03 pm

    IMHO there are two solutions to your problems. If the feature is only needed by a small part of your tests, then I would not use a rule. Instead add a single line errorChecker.checkPage(driver) to each tests and implement the check in this method.

    If you need it for almost all your tests:

    1. Convert SelTestCase to a rule by extending ExternalResource.

      public class WebDriverRule extends ExternalResource {
        public WebDriver driver;
      
        @Override
        protected void before() {
          driver = new FirefoxDriver();
          driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
          driver.get("http://www.google.com/");
        }
      
        @Override
        protected void after() {
          driver.quit();
        }
      }
      
    2. Add the page check code to the rule by extending Verifier.

      public class PageChecker extends Verifier {
        private WebDriverRule webDriverRule;
        private enabled = true;
      
        public PageChecker(WebDriverRule webDriverRule) {
          this.webDriverRule = webDriverRule;
        }
      
        public void disable() {
          this.enabled = false;
        }
      
        @Override
        public void verify() {
          if(enabled && notValid())
            throw new AssertionError("foo");
        }
      
        private boolean notValid() {
          WebDriver driver = webDriverRule.driver;
          //do something with driver
        }
      }
      
    3. Use org.junit.rules.RuleChain to control the execution order of the two rules.

      public class GoogleSearchTest {
        private WebDriverRule webDriverRule = new WebDriverRule();
        private PageChecker pageChecker = new PageChecker(webDriverRule);
      
        @Rule
        public RuleChain driverAroundPageChecker
          = RuleChain.outerRule(webDriverRule).around(pageChecker);
      
        @Test
        public void testGoogleSearch() {
          GoogleHomePage googleHomePage = PageFactory.initElements(driver,
              GoogleHomePage.class);
          googleHomePage.searchGoogle("Selenium HQ");
          assert driver.getPageSource().contains("seleniumhq") : "Selenium headquarter search failed";
        }
      
        @Test
        public void testWithouPageCheck() {
          pageChecker.disable();
          //here is your real test
        }
      }
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been writing a small web application in C# .NET4.0 to try and
I have been writing web applications for quite sometime in PHP with MySQL. I
I have been writing a project who acts as a server and have services
I have been writing a small java application (my first!), that does only a
I have been writing a GUI application for rsync on Windows and I have
I have been writing some Web services to be used by a few different
I have been writing my Rails application with Cucumber in TDD mode: Tests first,
I have been writing this Android application for the past few days and everything
I have been writing a browser based application (or rather, rapid prototyping an application)
I have been writing a new version of my application in WPF. It looks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.