isomorfeus-puppetmaster 0.6.12 → 0.6.15

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: 2d7381eb86e0aebdfcc20a8aab6da28f9015f61e544f967ae8ed7dff93d0066e
4
- data.tar.gz: 4ef4dd695aea946f494169161bfe8e250dcfa21c27eafe19d0031136e39264d4
3
+ metadata.gz: 269dd1f6465a3861c8590f471d3db376b11a0570fa4bf97bd44b9dfb5d9c1e42
4
+ data.tar.gz: 0315a46480c8e60a185b5ad3e8fd5649eecb937cb9c606ac6e3ab2e70e57a454
5
5
  SHA512:
6
- metadata.gz: dfe2342ae411f16d9c83ae2479a159bcca95de422ec2aca82aad9eb6cffa2e38312aee0835ea3c112b1dd225dc9ac1aff3559400bb8648116fb93186eb63ca6c
7
- data.tar.gz: 06e936622b8438b32e51b7c36cda934e60470919fe075e176a2b160dd5533101471cc59bda314bf6c54ed4bd715d56fa39d799a35387c1536835aa88ea59c433
6
+ metadata.gz: d52eb1625c95027d9ef3d7b3f57c7742d07307bf650f7b7545ef222bb6b4135500229670bf95dfc5e2081a41f623536d005cf5fcf392c887c03e7b4c7c75c263
7
+ data.tar.gz: c1af261f57a1f1ad3cce47a7cb2b10ad8c3b539300d98e925918db666231de4f72d8c5b606de64089af02cf79f3296596efbcce60a909702dc2a63808a77e8b1
data/README.md CHANGED
@@ -3,9 +3,10 @@
3
3
  <br/>
4
4
  Isomorfeus Puppetmaster<br/>
5
5
  </h1>
6
+
6
7
  A framework for acceptance tests or simply running tests in a headless browser.
7
8
  Allows for writing javascript browser tests in pure ruby.
8
- It is tailored for Isomorfeus and using [puppeteer-ruby](https://github.com/YusukeIwaki/puppeteer-ruby).
9
+ It is tailored for Isomorfeus and using [puppeteer-ruby](https://github.com/YusukeIwaki/puppeteer-ruby)
9
10
 
10
11
  ### Community and Support
11
12
  At the [Isomorfeus Framework Project](https://isomorfeus.com)
@@ -52,6 +53,16 @@ A document consists of elements. Simply working with just pages, documents and e
52
53
  1. Find something
53
54
  2. Interact with it
54
55
 
56
+ ## Sessions
57
+ Using `visit` will open a default session. However, additional browser sessions may be opened with:
58
+ ```ruby
59
+ s = new_session() # additional args may be passed, like headless: false, devtools: true
60
+ # now the session can be interacted with:
61
+ s.visit('/')
62
+ t = new_session() # multiple sessions may be active at the same time
63
+ t.visit('/')
64
+ ```
65
+
55
66
  ## Pages
56
67
  A page is a Puppeteer::Page and provides its complete API plus some additional convenience methods.
57
68
  The drivers opens a empty default page, to use that and go to the apps root page:
@@ -75,6 +86,13 @@ Both open pages can then be independently interacted with:
75
86
  page.visit('/go')
76
87
  page2.goto('/location')
77
88
  ```
89
+
90
+ For debugging:
91
+ ```ruby
92
+ page = visit('/', headless: false, devtools: true)
93
+ ```
94
+ 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.
95
+
78
96
  ### Pages and Ruby
79
97
 
80
98
  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
@@ -18,17 +18,22 @@ module Isomorfeus
18
18
  unless request.body.nil?
19
19
  request_hash = Oj.load(request.body.read, mode: :strict)
20
20
  if request_hash['key'] != @@request_key
21
+ STDERR.puts "wrong key"
21
22
  response = Rack::Response.new(Oj.dump({ 'error' => 'wrong key given, execution denied' }),
22
23
  401,
23
24
  'Content-Type' => 'application/json')
24
25
  else
25
26
  begin
27
+ if Isomorfeus.respond_to?(:init_store)
28
+ Isomorfeus.init_store
29
+ Isomorfeus.store.clear! if Isomorfeus.store.respond_to?(:clear!)
30
+ end
26
31
  result = TOPLEVEL_BINDING.eval(request_hash['code']) if request_hash['code']
27
32
  response = Rack::Response.new(Oj.dump({ 'result' => result }),
28
33
  200,
29
34
  'Content-Type' => 'application/json')
30
35
  rescue Exception => e
31
- response = Rack::Response.new(Oj.dump({ 'error' => "#{e.class}: #{e.message}", 'backtrace' => e.backtrace.join("\n") }),
36
+ response = Rack::Response.new(Oj.dump({ 'error' => "#{e.class}: #{e.message}", 'backtrace' => e.backtrace&.join("\n") }),
32
37
  200,
33
38
  'Content-Type' => 'application/json')
34
39
  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.12'
2
+ PUPPETMASTER_VERSION = '0.6.15'
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.12
4
+ version: 0.6.15
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-07 00:00:00.000000000 Z
11
+ date: 2022-08-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport