2

I came across a scenario, I want to submit a registration form. A new page will be loaded on successful submission. If any errors it'll end up with same registration form with error details.

Now My doubt is , How can I validate whether form submitted successfully or not?

Conditions: Can not use Page Title as it is same for all pages. Can not use URL as it is same for all pages.

I tried to use try catch to avoid handle errors. But is there any other way I can handle this scenario better.

  • capture submission alert message and validate the submission – Vel Guru Apr 19 '18 at 5:10
  • But, it doesn't show any pop up. If form filled with no error success page Will be displayed. – SQA_LEARN Apr 19 '18 at 5:19
  • @vel guru, Now I am validating exist of error in try catch. If error present form submit Boolean flag to false. Based on this I am performing other validation – SQA_LEARN Apr 19 '18 at 5:22
  • Two Ideas so far, 1. Try Catch and assign with Boolean flag isSuccess = true/false 2. findElements size is this the way PageObjects are handled ? (Now I am not using PageObjects) – SQA_LEARN Apr 19 '18 at 5:25
3

There are no ways to check if you have logged in successfully other than the real users would use.

  1. If you log in successfully then you should see some elements that the guest would not see (e.g. the user name in the corner of the screen, or some welcome message, etc.)
  2. If you failed to log in you should observe either error message or the style of some input element should change.

Both the methods require you wait for some element to appear or wait for some element to disappear. Regarding to how exactly you will perform assertion this depends on your coding style and the common approach that is used in your framework. You can:

  • use findElement and catch NoSuchElementException
  • use findElements and check for returned list size
  • use waiters and conditions approach
1

Some of the approaches you could use:

Ensure that:

  • The login form is not present
  • The 'login' link no longer appears
  • The error message is not displayed
  • Logged in text such as username: appears
  • Links only available to logged in users are present
  • Content only available to logged in users is present

There are basically 4 categories:

  • Not logged in should see x
  • Not logged in should not see y
  • Logged in should not see x
  • Logged in should see y

Which to use for a specific case depends on factors for that case

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.