java - HTMLUnit : Determine if the "login" was successful -


i have developed script sole purpose check if website/service , running. way ,it connects page using url , logs in site using user credentials. if login successful service running fine.

this script has been written in java , uses htmlunit. here lies problem. how ensure html page returned after logging in(clicking login/sign in button after filling out form) post-login "account home page".in other words how determine if login operation successful.

here how doing right now. account pages have user related info. instance if log in yahoo mail have "welcome , username" on top right corner of page or page have "compose" or "inbox" on it. using logic test success.

this has been observation while testing script. have come across cases rule falls apart.

  • some times page returned after login error page asking to
    check entered credentials.

  • there times page returned may ask turn on javascript or
    enable cookie in browser.

  • i have come across case page returned server has been same pre-login page (no explanation given why)

  • some web pages dynamic in nature hence content changes time time. in such cases key-word search may result in false
    negatives.which why logic of searching presence of string hinges
    purely on choice of "search string/keywords".

the point trying make coding these cases upfront not realistic.

i tried comparing urls of pre-login , post-login pages found out
there many cases both same.hence method not conclusive.

i need sure shot way of determining if login successful. not professional web developer. server return status code new page, can resolved? htmlunit have ability test success , failure.

i appreciate help/comments.thank you!!!

well... kind of tricky question. because you've no control of server. ask might receive should prepared receive b, c , d... , miss e.

i need sure shot way of determining if login successful.

based on comments, looking "welcome <username>" string should quite sure shot. in other (more programmatic) words, if you have string in result page logged in. there sure shot.

now, you've mentioned there cases in try log in , don't receive string. in cases, , based on examples, should not logged in.

however, said, can change string "welcome, <username>" "there again!" , getting false negatives. unlikely, however, ever false positives applying logic.

so, there way have 100% success on guessing if user logged in , 100% success on guessing if user not logged in? no, there isn't. simplest way understand using web in human-like way:

scenario 1:

  1. try log in
  2. you see red label saying "user , password incorrect
  3. you infer not logged in. right

scenario 2:

  1. try log in
  2. you see "welcome <username>"
  3. you infer logged in. right

scenario 3:

  1. try log in
  2. you "enable javascript" message
  3. you infer not logged in. however, happened advice server , logged in. refresh page , see "welcome . here failed human

scenario 4:

  1. try log in
  2. you timeout
  3. you infer not logged in. however, login request got server logged in , when server answered htmlpage internet connection, isp, or internet broke down millisecond , packet got lost. here failed human

those few scenarios there many more. think of this: human head con not 100% sure of result of log in trial... how can expect headless browser be? :)


Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -