chemlab 0.7.3 → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 16b138dd1ea82aa663333b42dcdaa00efbba338a929d7f2fb1789aa864094747
4
- data.tar.gz: b35c1771c8ceb822ed8e948b6e1d5c40b9a89b39bfede2f9c36348ca20bbcc2e
3
+ metadata.gz: b8768461aba3f55a80a1ef51e13b894d8f876343abb1a402c7de72e4fbfa4a9e
4
+ data.tar.gz: a3a48670a730d1d873ce671d94de87198478e54bfa2f29665aa2c05bf686f328
5
5
  SHA512:
6
- metadata.gz: 417cd502e6da022cb8e6e4fbacc061bd6191c363fce8c7c6a47d910d9d9b315bde7de3fa99802455a8fbb73fe2017a5bf11164be1b597a0bf232322a4919f032
7
- data.tar.gz: 5a4272aaf6b7d431660cb595432260e59bc3b83d1078acdbb08039d8c96441f748f8fad1716ab3f3b052790c6e711419362ae4bc7eedd499ace4cd53defe3b6c
6
+ metadata.gz: 9f6b5cd6c624455c9204da1815b891f65a97725309acf4157b280df795c56f072aa905ae3d48c75a3c42c7414bee7a3408d379dcfdbbc406eb1d849f6c4da3ed
7
+ data.tar.gz: 5cc500d4395d6470dc19cb4e250721d600d34e2f0f561410de26437490cf83d2529122c19d7da64ed7f17fd135f3fbfd93cfd01e90a253faae8b54956a7b2092
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Start monkey patch of String
4
+ class String
5
+ # Find the root module (parent module) of a class or module
6
+ # @example
7
+ # 'A::B::C'.root_module #=> A
8
+ # 'A::B'.root_module => A
9
+ # @return [Module] the root module
10
+ def root_module
11
+ Object.const_get(split('::').first)
12
+ end
13
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Chemlab
4
+ # Application Library Definition
5
+ # Provides accessors for +:base_url+, +:base_url=+
6
+ # +base_url+ will default to Chemlab's configured base_url
7
+ module Library
8
+ def self.included(base)
9
+ base.module_eval do
10
+ class << self
11
+ # The Base URL where this library / application exists
12
+ # If you have multiple applications that Chemlab will target,
13
+ # this is useful for having separate base_urls.
14
+ #
15
+ # @return [String] the base_url. +Chemlab.configuration.base_url+ by default if not set
16
+ #
17
+ # @example
18
+ # Chemlab.configure do |chemlab|
19
+ # A.base_url = 'https://first_app'
20
+ # B.base_url = 'https://second_app'
21
+ # chemlab.base_url = 'https://main_app'
22
+ #
23
+ # chemlab.libraries = [A, B, C]
24
+ #
25
+ # C.base_url #=> https://main_app
26
+ # end
27
+ attr_writer :base_url
28
+
29
+ def base_url
30
+ @base_url ||= Chemlab.configuration.base_url
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'forwardable'
4
+ require 'chemlab/core_ext/string/root_module'
4
5
 
5
6
  module Chemlab
6
7
  module Runtime
@@ -17,13 +18,56 @@ module Chemlab
17
18
  @session = Session.new(browser_options)
18
19
  end
19
20
 
21
+ # Navigate to a given Page library
22
+ # @param [Class<Chemlab::Page>] page_class the class of the Page to navigate to
23
+ # @example
24
+ # Given:
25
+ # module TheLibrary
26
+ # def self.base_url
27
+ # 'https://example.com'
28
+ # end
29
+ # class ThePage < Chemlab::Page
30
+ # path '/path'
31
+ # end
32
+ # end
33
+ #
34
+ # Chemlab::Runtime::Browser.navigate_to(TheLibrary::ThePage) #=> Navigates to https://example.com/path
35
+ #
36
+ # @example
37
+ # Given:
38
+ # Chemlab.configure do |chemlab|
39
+ # chemlab.base_url = 'https://example.com'
40
+ # end
41
+ #
42
+ # class ThePage < Chemlab::Page
43
+ # path '/'
44
+ # end
45
+ #
46
+ # Chemlab::Runtime::Browser.navigate_to(ThePage) #=> Navigates to https://example.com/path
20
47
  def self.navigate_to(page_class)
21
- Chemlab.configuration.browser.navigate_to(page_class.path)
48
+ unless page_class&.name.respond_to?(:root_module)
49
+ return Chemlab.configuration.browser.navigate_to(Chemlab.configuration.base_url + page_class.path)
50
+ end
51
+
52
+ # workaround for file:// protocol. URI.join() does not work with URI.join('file:///Users', '/user')
53
+ uri = if URI(page_class.name.root_module.base_url).scheme == 'file'
54
+ URI(File.join(page_class.name.root_module.base_url, page_class.path))
55
+ else
56
+ URI.join(page_class.name.root_module.base_url, page_class.path)
57
+ end
58
+
59
+ Chemlab.configuration.browser.navigate_to(uri)
22
60
  end
23
61
 
24
- def navigate_to(path)
62
+ # Navigate to a URI or Path
63
+ # @param [URI,String] uri_or_path the URI or path
64
+ # @return [URI,String] the URI or Path that was navigated to
65
+ # @example
66
+ # Chemlab.configuration.browser.navigate_to('/path') #=> /path
67
+ # Chemlab.configuration.browser.navigate_to(URI('https://example.com/path')) #=> URI('https://example.com/path')
68
+ def navigate_to(uri_or_path)
25
69
  @session ||= Chemlab.configuration.browser.session
26
- @session.engine.goto(Chemlab.configuration.base_url + path)
70
+ @session.engine.goto(uri_or_path.to_s)
27
71
  end
28
72
 
29
73
  # The options used to create the browser session
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Chemlab
4
- VERSION = '0.7.3'
4
+ VERSION = '0.8.0'
5
5
  end
data/lib/chemlab.rb CHANGED
@@ -34,6 +34,7 @@ module Chemlab
34
34
  autoload :Element, 'chemlab/element'
35
35
  autoload :Component, 'chemlab/component'
36
36
  autoload :Page, 'chemlab/page'
37
+ autoload :Library, 'chemlab/library'
37
38
 
38
39
  # Runtime modules
39
40
  module Runtime
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chemlab
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.3
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitLab Quality
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 00:00:00.000000000 Z
11
+ date: 2021-09-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: climate_control
@@ -240,7 +240,9 @@ files:
240
240
  - lib/chemlab/component.rb
241
241
  - lib/chemlab/configuration.rb
242
242
  - lib/chemlab/core_ext/string/inflections.rb
243
+ - lib/chemlab/core_ext/string/root_module.rb
243
244
  - lib/chemlab/element.rb
245
+ - lib/chemlab/library.rb
244
246
  - lib/chemlab/page.rb
245
247
  - lib/chemlab/runtime/browser.rb
246
248
  - lib/chemlab/runtime/env.rb