isomorfeus-puppetmaster 0.6.13 → 0.6.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: daa437e0662a07334e47cb067440f006bc9fa6015b2fe4f54deb57f1e11e19ee
4
- data.tar.gz: a4f75f12075a733c14d4e3a0716e4c8b7018d33de39cee4e649bc48f06e4302f
3
+ metadata.gz: 602d8e8f04c6eb2290b4f0bda9bf2c2db5903dfbd86bd0cae7bed3489846378b
4
+ data.tar.gz: ca32e34cf20340a0c2039a1b625cffa6d5261313b699dd2a2b536e9b994d2f96
5
5
  SHA512:
6
- metadata.gz: 9e63d3a9f93d812958ff8897a5f56385c4ae940790a3635e1909920d9078ae69c50cb57152646fd76970a02b1c46e71238bcf50bb3b7be59e6de7c2eff3ddb0f
7
- data.tar.gz: eb1c6e57fc5a4e5cc0b7bdf82a394cd14fdbdfaea540ea52be667c3c2440f0596d04bbf177b3c2eee054d32ae094ef0a3b8ccdaac225f7988e08ecb175321fb8
6
+ metadata.gz: 1bfc337ba3188881e904feac1ef265a72aad83dee7add3731820cdfb81a940c1b5351963a524df2164f734019ce9e7fb0dfcc6fd1c4c9a85c388add303a419bf
7
+ data.tar.gz: 13c2c4858f01844b7cf8bd05ba4d20a04ff25b3d9f3695d2cd8cf178b25501da42e30533df162f6cad778635692058dafc5fd4d221d6bfd32e462a54c072d821
data/README.md CHANGED
@@ -52,6 +52,16 @@ A document consists of elements. Simply working with just pages, documents and e
52
52
  1. Find something
53
53
  2. Interact with it
54
54
 
55
+ ## Sessions
56
+ Using `visit` will open a default session. However, additional browser sessions may be opened with:
57
+ ```ruby
58
+ s = new_session() # additional args may be passed, like headless: false, devtools: true
59
+ # now the session can be interacted with:
60
+ s.visit('/')
61
+ t = new_session() # multiple sessions may be active at the same time
62
+ t.visit('/')
63
+ ```
64
+
55
65
  ## Pages
56
66
  A page is a Puppeteer::Page and provides its complete API plus some additional convenience methods.
57
67
  The drivers opens a empty default page, to use that and go to the apps root page:
@@ -75,6 +85,13 @@ Both open pages can then be independently interacted with:
75
85
  page.visit('/go')
76
86
  page2.goto('/location')
77
87
  ```
88
+
89
+ For debugging:
90
+ ```ruby
91
+ page.visit('/', headless: false, devtools: true)
92
+ ```
93
+ This will close the current browser if the options for headless and devtools dont match, and open a new one with the supplied headless and devtools options.
94
+
78
95
  ### Pages and Ruby
79
96
 
80
97
  Ruby can be executed within pages by simply providing a block or a string:
@@ -3,7 +3,7 @@ module Isomorfeus
3
3
  module DSL
4
4
  @@launch_options = nil
5
5
 
6
- def set_launch_options(app: nil, args: nil, channel: nil, default_viewport: nil, devtools: nil, dumpio: nil,
6
+ def set_launch_options(app: nil, args: nil, channel: nil, default_viewport: nil, devtools: false, dumpio: nil,
7
7
  env: nil, executable_path: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil,
8
8
  headless: true, ignore_default_args: nil, ignore_https_errors: nil, pipe: nil,
9
9
  product: :chrome, slow_mo: nil, timeout: nil, user_data_dir: nil)
@@ -34,11 +34,11 @@ module Isomorfeus
34
34
  session.default_page
35
35
  end
36
36
 
37
- def goto(uri, referer: nil, timeout: nil, wait_until: 'networkidle0')
38
- session.goto(uri, referer: referer, timeout: timeout, wait_until: wait_until)
37
+ def visit(uri, referer: nil, timeout: nil, wait_until: 'networkidle0', headless: true, devtools: false)
38
+ session(headless: headless, devtools: devtools).visit(uri, referer: referer, timeout: timeout, wait_until: wait_until, headless: headless, devtools: devtools)
39
39
  session.default_page
40
40
  end
41
- alias_method :visit, :goto
41
+ alias_method :goto, :visit
42
42
 
43
43
  def isomorphic(ruby_source = '', &block)
44
44
  ruby_source = Isomorfeus::Puppetmaster.block_source_code(&block) if block_given?
@@ -56,7 +56,7 @@ module Isomorfeus
56
56
  Isomorfeus::Puppetmaster.served_app.on_server(ruby_source, &block)
57
57
  end
58
58
 
59
- def new_session(app: nil, args: nil, channel: nil, default_viewport: nil, devtools: nil, dumpio: nil,
59
+ def new_session(app: nil, args: nil, channel: nil, default_viewport: nil, devtools: false, dumpio: nil,
60
60
  env: nil, executable_path: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil,
61
61
  headless: true, ignore_default_args: nil, ignore_https_errors: nil, pipe: nil,
62
62
  product: :chrome, slow_mo: nil, timeout: nil, user_data_dir: nil)
@@ -109,8 +109,8 @@ module Isomorfeus
109
109
  Isomorfeus::Puppetmaster.served_app.on_server(ruby_source)
110
110
  end
111
111
 
112
- def session
113
- @@puppetmaster_session ||= new_session(app: Isomorfeus::Puppetmaster.served_app)
112
+ def session(headless: true, devtools: false)
113
+ @@puppetmaster_session ||= new_session(app: Isomorfeus::Puppetmaster.served_app, headless: headless, devtools: devtools)
114
114
  end
115
115
  end
116
116
  end
@@ -4,23 +4,24 @@ module Isomorfeus
4
4
  TIMEOUT = 30000 # milliseconds
5
5
 
6
6
  attr_accessor :app, :browser, :default_page, :product, :response
7
+ attr_reader :headless, :devtools
7
8
 
8
- def initialize(app:, args: nil, channel: nil, default_viewport: nil, devtools: nil, dumpio: nil,
9
+ def initialize(app:, args: nil, channel: nil, default_viewport: nil, devtools: false, dumpio: nil,
9
10
  env: nil, executable_path: nil, handle_SIGINT: nil, handle_SIGTERM: nil, handle_SIGHUP: nil,
10
11
  headless: true, ignore_default_args: nil, ignore_https_errors: nil, pipe: nil,
11
12
  product: :chrome, slow_mo: nil, timeout: nil, user_data_dir: nil)
12
- @app = app
13
+ @parameters = binding.local_variables.map { |v| [v, binding.local_variable_get(v)] }.to_h
14
+ @parameters[:channel] = @parameters[:channel].to_s if channel
15
+ @parameters[:timeout] = TIMEOUT unless timeout
16
+ @app = @parameters.delete(:app)
17
+ @headless = headless
18
+ @devtools = devtools
19
+ @channel = channel
20
+ default_viewport
13
21
  product = product.to_s
14
- @product = %w[chrome firefox].include?(product) ? product : 'chrome'
15
- @browser = ::Puppeteer.launch(args: args, channel: channel&.to_s, devtools: devtools, default_viewport: default_viewport,
16
- dumpio: dumpio, env: env, executable_path: executable_path, handle_SIGINT: handle_SIGINT,
17
- handle_SIGTERM: handle_SIGTERM, handle_SIGHUP: handle_SIGHUP, headless: headless,
18
- ignore_default_args: ignore_default_args, ignore_https_errors: ignore_https_errors,
19
- pipe: pipe, product: product, slow_mo: slow_mo, timeout: timeout ? timeout : TIMEOUT,
20
- user_data_dir: user_data_dir)
21
- @original_user_agent = @browser.user_agent
22
- @default_page = @browser.new_page
23
- @default_page.puppetmaster_session = self
22
+ @parameters[:product] = %w[chrome firefox].include?(product) ? product : 'chrome'
23
+ @product = @parameters[:product]
24
+ launch_browser
24
25
  ObjectSpace.define_finalizer(self, self.class.close_browser(self))
25
26
  end
26
27
 
@@ -40,12 +41,18 @@ module Isomorfeus
40
41
  @browser.pages
41
42
  end
42
43
 
43
- def goto(uri, referer: nil, timeout: nil, wait_until: 'networkidle0')
44
+ def visit(uri, referer: nil, timeout: nil, wait_until: 'networkidle0', headless: true, devtools: false)
45
+ if @headless != headless || @devtools != devtools
46
+ @browser.close
47
+ @headless = headless
48
+ @devtools = devtools
49
+ launch_browser
50
+ end
44
51
  parsed_uri = parse_uri(uri)
45
52
  @response = @default_page.goto(parsed_uri.to_s, referer: referer, timeout: timeout, wait_until: wait_until)
46
53
  @default_page
47
54
  end
48
- alias_method :visit, :goto
55
+ alias_method :goto, :visit
49
56
 
50
57
  def network_conditions
51
58
  ::Puppeteer::NETWORK_CONDITIONS
@@ -144,6 +151,15 @@ module Isomorfeus
144
151
  instance.browser.close if instance.browser
145
152
  end
146
153
  end
154
+
155
+ def launch_browser
156
+ @parameters[:headless] = @headless
157
+ @parameters[:devtools] = @devtools
158
+ @browser = ::Puppeteer.launch(**@parameters)
159
+ @original_user_agent = @browser.user_agent
160
+ @default_page = @browser.new_page
161
+ @default_page.puppetmaster_session = self
162
+ end
147
163
  end
148
164
  end
149
165
  end
@@ -1,3 +1,3 @@
1
1
  module Isomorfeus
2
- PUPPETMASTER_VERSION = '0.6.13'
2
+ PUPPETMASTER_VERSION = '0.6.14'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: isomorfeus-puppetmaster
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.13
4
+ version: 0.6.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jan Biedermann
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-09 00:00:00.000000000 Z
11
+ date: 2022-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport