Skip to content

Commit

Permalink
added the page wait time
Browse files Browse the repository at this point in the history
  • Loading branch information
Pouyan Azari committed Jun 26, 2019
1 parent 2bbf897 commit fcd8d5d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Change Log

## [0.0.4] 2019-06-26

- Added a possibility to wait for the page to be rendered, needed for the slow pages

## [0.0.3] 2019-06-25

- Changed the name of the variables for the metrics to have login in them to avoid collisions
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ The following parameters are optional:
| expected_text_xpath| The expected text xpath (must be unique), if not given the whole text is searched for the string|
| submit_type | The type of submission that should be used it can be click or submit, default is submit|
| logout_xpath | The xpath that should be used for the logout button|
| wait_time | The time that should the form submitter wait for the page to load in seconds|


### Shibboleth
Expand Down
13 changes: 11 additions & 2 deletions collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type SingleLoginConfig struct {
Method string `yaml:"method"`
SubmitType string `yaml:"submit_type"`
LogoutXpath string `yaml:"logout_xpath"`
WaitTime int `yaml:"wait_time"`
}

/// getChromeOptions Returns the options for the chrome driver that is used
Expand Down Expand Up @@ -152,7 +153,7 @@ func getLogger() *log.Logger {

/// loginSimpleForm Logs in the simple for using the username, password and the submit button
func loginSimpleForm(page *agouti.Page, urlText string, usernameXpath string, passwordXpath string, submitXpath string,
username string, password string, submitType string) {
username string, password string, submitType string, wait int) {
err := page.Navigate(urlText)
if err != nil {
logger.WithFields(
Expand All @@ -162,6 +163,14 @@ func loginSimpleForm(page *agouti.Page, urlText string, usernameXpath string, pa
}).Warningln(err.Error())
panic(err)
}
err = page.SetImplicitWait(wait * 1000)
if err != nil {
logger.WithFields(
log.Fields{
"subsystem": "login_simple_form",
"part": "waiting",
}).Warningln(err.Error())
}
usernameField := page.FindByXPath(usernameXpath)
err = usernameField.SendKeys(username)
if err != nil {
Expand Down Expand Up @@ -444,7 +453,7 @@ func getStatus(config SingleLoginConfig) (status bool, elapsed float64) {
switch config.LoginType {
case "simple_form":
loginSimpleForm(page, config.Url, config.UsernameXpath, config.PasswordXpath, config.SubmitXpath,
config.Username, config.Password, config.SubmitType)
config.Username, config.Password, config.SubmitType, config.WaitTime)
status = checkExpected(page, config.ExpectedTextXpath, config.ExpectedText)
break
case "shibboleth":
Expand Down
3 changes: 2 additions & 1 deletion misc/login.yml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ targets:
debug: no
method: "POST"
submit_type: "click"
logout_xpath: ""
logout_xpath: ""
wait_time: 1000

0 comments on commit fcd8d5d

Please sign in to comment.