Introduced the `PageStateContainer` and `PageState` objects and added documentation to some of the code in this file.  More in description
Introduced the `PageStateContainer` and `PageState` objects and added documentation to some of the code in this file.  More in description

`PageStateContainer` holds `PageState` instances and makes them
accessible as attributes.

`PageState` objects can be used to check if the web page is in a
pre-defined state.  You can define this in the same JSON used for the
`Page` object.  Here is an updated JSON format.  Everything stays the
same except now you can add a dict of `states`.

{
  "login_root": "https://reddit.com",
  "elements": {
    "login_link": {
      "selector": "Log in or sign up",
      "lookup_method": "link_text"
    },
    "username_input": {
      "selector": "user_login",
      "lookup_method": "id"
    },
    "password_input": {
      "selector": "passwd_login",
      "lookup_method": "id"
    },
    "remember_me": {
      "selector": "rem_login",
      "lookup_method": "id"
    },
    "login_button": {
      "selector": "button",
      "lookup_method": "tag_name",
      "parent": {
        "selector": "login-form",
        "lookup_method": "id"
      }
    },
    "logout_link": {
      "selector": "logout",
      "lookup_method": "link_text"
    },
    "redditor_time": {
      "selector": "age",
      "lookup_method": "class_name"
    },
    "moderator_list": {
      "selector": "side-mod-list",
      "lookup_method": "id"
    },
    "user_profile_link": {
      "selector": "user",
      "lookup_method": "class_name"
    }
  },
  "states": {
    "login_form_displayed": {
      "displayed": [
        "username_input",
        "password_input"
      ]
    },
    "login_link_displayed": {
      "displayed": [
        "login_link"
      ]
    },
    "login_finished": {
      "appears": [
        "logout_link"
      ],
      "displayed": [
        "logout_link"
      ],
      "disappears": [
        "username_input"
      ]
    },
    "on_profile": {
      "appears": [
        "redditor_time",
        "moderator_list"
      ]
    }
  }
}

“appears” means the element appears in the DOM, “disappears” means the
element no longer appears in the DOM, “displayed” means the element is
actually displayed on the screen, and “not_displayed” means the element
is no longer displayed on the screen.

Wykleph/selenext