Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify working with multiple domains #257

Closed
romikoops opened this issue Nov 27, 2017 · 1 comment
Closed

Simplify working with multiple domains #257

romikoops opened this issue Nov 27, 2017 · 1 comment

Comments

@romikoops
Copy link
Contributor

romikoops commented Nov 27, 2017

Howitzer uses page object pattern. We do not need to specify protocol and host for each page class. Howitzer gets settings from default.yml (with prefix app_) and set hosts automatically. It works perfectly, until you do not need to test application with different domains. For that reason, howitzer provides site dsl method.

class FooPage < Howitzer::Web::Page
  site 'http://example.com'
end

In real life you deal with different environments and it is very important to keep the data as configurable. As a simple case, we could add new setting in default.yml

example_app_url=http://example.com

and then

class FooPage < Howitzer::Web::Page
  site Howitzer.example_app_url
end

Much better now, but what about ability to change it to https for example for staging environment and keep http for development one. Should not be a problem.

SEXY_SETTINGS="example_app_url=http://dev.example.com"
SEXY_SETTINGS="example_app_url=https://staging.example.com"

Ok, what about using basic authentication? Following code will work, but in some cases we need url without login and password in URL

SEXY_SETTINGS="example_app_url=https://user:pass@staging.example.com"

Then we could keep url parts separately and use addressable gem:

# default.yml
###########################################################
# EXAMPLE APPLICATION SETTINGS                                                                    #
###########################################################
 example_app_base_auth_login: login
 example_app_base_auth_pass: pass
 example_app_protocol: http
 example_app_host: example.com

# howitzer.rb
module Howitzer
 def self.example_app_uri
    ::Addressable::URI.new(
      user: Howitzer.example_app_base_auth_login,
      password: Howitzer.example_app_base_auth_pass,
      host: Howitzer.example_app_host,
      scheme: Howitzer.example_app_protocol || 'http'
    )
  end
end

# web/pages/foo_page.rb
class FooPage < Howitzer::Web::Page
  site Howitzer.example_app_uri.site
end

Huh, too big amount of code to deal with 1 additional url, is not it?

We need to find an approach how to simplify it. For example,

# howitzer.rb
module Howitzer
 def self.app_uri(name = nil)
    prefix = "#{name}_" if name.present?
    ::Addressable::URI.new(
      user: Howitzer.public_send("#{prefix}app_base_auth_login"),
      password: Howitzer.public_send("#{prefix}app_base_auth_pass"),
      host: Howitzer.public_send("#{prefix}app_host"),
      scheme: Howitzer.public_send("#{prefix}app_protocol") || 'http'
    )
  end
end

# web/pages/foo_page.rb
class FooPage < Howitzer::Web::Page
  site Howitzer.app_uri(:example).site
end
@romikoops
Copy link
Contributor Author

in master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant