Class: LoginPage

Inherits:
Object
  • Object
show all
Defined in:
lib/leap_salesforce_ui/login_page.rb

Constant Summary collapse

DISABLE_2STEP_URL =
"https://gitlab.com/leap-dojo/leap_salesforce_ui/-/wikis/Disable-2-step-authentication-and-allow-IP-range"

Class Method Summary collapse

Class Method Details

.browserWatir::Browser

Returns:

  • (Watir::Browser)


8
9
10
# File 'lib/leap_salesforce_ui/login_page.rb', line 8

def browser
  LeapSalesforce.browser
end

.error_messageObject



16
17
18
# File 'lib/leap_salesforce_ui/login_page.rb', line 16

def error_message
  error_message_element.text
end

.error_message?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/leap_salesforce_ui/login_page.rb', line 20

def error_message?
  error_message_element.present?
end

.error_message_elementObject



12
13
14
# File 'lib/leap_salesforce_ui/login_page.rb', line 12

def error_message_element
  browser.div(id: "error")
end

.loginObject



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/leap_salesforce_ui/login_page.rb', line 43

def 
  raise "Need to set LeapSalesforce.ui_user" unless LeapSalesforce.ui_user
  LeapSalesforce.logger.info "Logging in as user '#{LeapSalesforce.ui_user}'"
  if LeapSalesforce.
    browser.goto SoqlHandler.instance_url
    user = LeapSalesforce::Users.where username: LeapSalesforce.ui_user
    session = LeapSalesforce::Session.new user.username, LeapSalesforce.password, user.security_token
    browser.cookies.add "sid", session.session_id
    browser.cookies.add "sidClient", session.user_id
    browser.goto SoqlHandler.instance_url
  else
    browser.goto "#{LeapSalesforce.general_url}/?un=#{LeapSalesforce.ui_user}&pw=#{LeapSalesforce.password}"
  end
  continue_button = browser.button(id: "thePage:inputForm:continue")
  if continue_button.exists?
    browser.checkbox(id: "thePage:inputForm:remember").set
    continue_button.click
  end
end

.login_manuallyObject

Could be used if a user wants to login through UI for login specific tests which should not be necessary



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/leap_salesforce_ui/login_page.rb', line 26

def 
  browser.goto LeapSalesforce.general_url
  browser.text_field(id: "username").set(LeapSalesforce.ui_user)
  browser.text_field(id: "password").set(LeapSalesforce.password)
  browser.button(id: "Login").click
  Watir::Wait.until(timeout: 60, message: "Did not login within the expected time") do
    raise "Cannot Login. #{error_message}" if error_message?

    if browser.url.include? "_ui/identity/verification/"
      raise LeapSalesforce::SetupError, "2 step verification page appears.
Go to #{DISABLE_2STEP_URL} to learn how to disable it"
    end

    !browser.url.include? LeapSalesforce.general_url
  end
end