webdrone 0.3.0 → 0.4.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
  SHA1:
3
- metadata.gz: ce1ac20c62a89e4f9432d957bd6939f8e522888c
4
- data.tar.gz: 42e14188457d80576e548a5c15636caf45efafd4
3
+ metadata.gz: cb888344d4b82d0c3747d3812b275d13313accc0
4
+ data.tar.gz: 1b373f581493ed391fc44e82fa1040909ac037cc
5
5
  SHA512:
6
- metadata.gz: 3f87bd8257def21f12b14499c8103514e9dff4a752e7f207456729f3aaec49f633b8dad8056d25ebf4e442b283bf26a880115314cd3380dd30a8d42ee6cbb81e
7
- data.tar.gz: c43aa6c3d7036b06a7fc62d99e974ce7bc04acb2ef888c73d254c22a57c263185770de02fbe2e4242da2059ba9a22117cb5e5313769b6fa0cc0e9f6c40cca7dc
6
+ metadata.gz: 545229f0fa9da4eff8a7e477810e37bb10112a1684cccde6c210e861ea9e1d0ec43c31eecbf17d7e886ec7094ed0ea0ba0890b6d60cf6c0d104082623b4e88d1
7
+ data.tar.gz: 384975fb4517f9a7bf2923798e94db24c0a3686d92d77cfa0110777ddfe89b05f8e481adc2556ba713a6199809791006c316005d30781f43392d5111db3db5f7
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015 Aldrin Martoq
3
+ Copyright (c) 2015 Servicios A0 SpA
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  Yet another selenium webdriver wrapper, ruby version.
4
4
 
5
+ There is a groovy version available, at https://github.com/a0/a0-webdrone-groovy.
6
+
5
7
  ## Installation
6
8
 
7
9
  Add this line to your application's Gemfile:
@@ -26,53 +28,69 @@ Create a browser:
26
28
  require 'webdrone'
27
29
 
28
30
  a0 = Webdrone.create
29
- a0.open.url 'http://www.google.com/'
31
+ a0.open.url 'http://www.google.com/'
30
32
  a0.quit
31
33
 
32
34
  # or
33
35
  Webdrone.create do |a0|
34
- a0.open.url 'http://www.google.com/'
36
+ a0.open.url 'http://www.google.com/'
35
37
  end
36
38
  ```
37
39
 
38
40
  Take a screenshot:
39
41
 
40
42
  ```ruby
41
- require 'webdrone'
42
-
43
- Webdrone.create do |a0|
44
- a0.open.url 'http://www.google.com/'
45
- a0.shot.name 'start page'
46
- end
43
+ a0.shot.name 'login' # saves to screenshot-0001-login.png
44
+ a0.shot.name 'home' # saves to screenshot-0002-home.png
47
45
  ```
48
46
 
49
- Filling a form:
47
+ Working with forms:
50
48
 
51
49
  ```ruby
52
- require 'webdrone'
53
-
54
- Webdrone.create do |a0|
55
- a0.open.url 'http://www.google.com/'
56
- a0.form.set 'q', 'A0::WebDrone'
57
- a0.form.submit
50
+ a0.form.set 'q', 'A0::WebDrone'
51
+ a0.form.submit
58
52
  end
59
53
 
60
54
  # or
61
- a0.open.url 'http://www.google.com/'
62
55
  a0.form.with_xpath '//label[contains(.,"%s")]/following-sibling::*/*[self::input | self::textarea | self::select]' do
63
- set 'label', 'value'
64
- xlsx sheet: 'ejemplo'
56
+ set 'label', 'value'
57
+ xlsx sheet: 'ejemplo'
65
58
  end
66
59
  a0.form.submit
67
60
  ```
68
61
 
62
+ Filling a form from an xlsx spreadsheet:
63
+ ```ruby
64
+ a0.conf.timeout 10
65
+ ```
66
+
67
+
68
+
69
69
  Config:
70
70
 
71
71
  ```ruby
72
72
  a0.conf.timeout 10
73
73
  ```
74
74
 
75
- Context, text and verification:
75
+ Saving screenshots and downloaded files to a directory:
76
+
77
+ ```ruby
78
+ a0 = Webdrone.create create_outdir: true
79
+ print a0.conf.outdir # <= default is webdrone_output_%date%_%time%
80
+
81
+ a0.open.url 'http://www.google.cl/'
82
+ a0.form.set 'q', "Download sample file filetype:xls\n"
83
+ a0.shot.screen 'homepage' # screenshot is saved in output directory
84
+ a0.clic.xpath '//h3' # xls file is saved in output directory
85
+
86
+ # or specify directory yourself
87
+ a0 = Webdrone.create outdir: '/tmp/evidences'
88
+ print a0.conf.outdir # <= "/tmp/evidences"
89
+ ```
90
+
91
+
92
+
93
+ Creating tabs and switching iframes:
76
94
 
77
95
  ```ruby
78
96
  a0.ctxt.create_tab
@@ -80,11 +98,22 @@ a0.open.url 'http:://example.com/'
80
98
  a0.ctxt.with_frame 'iframe_name' do
81
99
  a0.find.on 'Some link or button'
82
100
  end
83
- puts a0.text.id('something')
101
+ ```
102
+
103
+ Getting text:
84
104
 
85
- a0.vrfy.id 'another', contains: 'SOME TEXT'
86
- a0.vrfy.id 'another', eq: 'EXACT TEXT'
105
+ ```ruby
106
+ puts a0.text.id 'some_id'
107
+ puts a0.text.xpath 'some_xpath'
108
+ ```
109
+
110
+ Verifying text and HTML attributes
111
+
112
+ ```ruby
113
+ a0.vrfy.id 'some_id', contains: 'SOME TEXT'
114
+ a0.vrfy.xpath 'some_xpath', eq: 'EXACT TEXT'
87
115
  a0.vrfy.link 'link', attr: 'disabled', eq: 'true'
116
+ a0.vrfy.link 'link', attr: 'sample', contains: 'something'
88
117
  ```
89
118
 
90
119
 
@@ -97,7 +126,7 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
97
126
 
98
127
  ## Contributing
99
128
 
100
- Bug reports and pull requests are welcome on GitHub at https://github.com/a0/webdrone-ruby.
129
+ Bug reports and pull requests are welcome on GitHub at https://github.com/a0/a0-webdrone-ruby.
101
130
 
102
131
 
103
132
  ## License
@@ -17,6 +17,7 @@ require 'selenium-webdriver'
17
17
  require 'xpath'
18
18
  require 'rubyXL'
19
19
  require 'irb'
20
+ require 'fileutils'
20
21
 
21
22
  module Webdrone
22
23
  def self.create(*args)
@@ -26,7 +27,7 @@ module Webdrone
26
27
  yield a0
27
28
  ensure
28
29
  a0.quit
29
- end
30
+ end
30
31
  else
31
32
  a0
32
33
  end
@@ -2,8 +2,24 @@ module Webdrone
2
2
  class Browser
3
3
  attr_accessor :driver
4
4
 
5
- def initialize(browser: 'chrome')
6
- @driver = Selenium::WebDriver.for browser.to_sym
5
+ def initialize(browser: 'chrome', create_outdir: false, outdir: nil)
6
+ if create_outdir or outdir
7
+ outdir ||= "webdrone_output_#{Time.new.strftime('%Y%m%d_%H%M')}"
8
+ self.conf.outdir = outdir
9
+ end
10
+ if outdir != nil and browser.to_sym == :chrome
11
+ prefs = { download: { prompt_for_download: false, default_directory: outdir } }
12
+ @driver = Selenium::WebDriver.for browser.to_sym, prefs: prefs
13
+ elsif outdir != nil and browser.to_sym == :firefox
14
+ profile = Selenium::WebDriver::Firefox::Profile.new
15
+ profile['browser.download.dir'] = outdir
16
+ profile['browser.download.folderList'] = 2
17
+ profile['browser.download.manager.showWhenStarting'] = false
18
+ profile['browser.helperApps.neverAsk.saveToDisk'] = "images/jpeg, application/pdf, application/octet-stream"
19
+ @driver = Selenium::WebDriver.for browser.to_sym, profile: profile
20
+ else
21
+ @driver = Selenium::WebDriver.for browser.to_sym
22
+ end
7
23
  end
8
24
 
9
25
  def quit
@@ -12,8 +12,8 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(id)
16
- @a0.find.id(id).click
15
+ def id(text)
16
+ @a0.find.id(text).click
17
17
  end
18
18
 
19
19
  def link(text, n: 1, all: false, visible: true)
@@ -28,6 +28,10 @@ module Webdrone
28
28
  @a0.find.on(text, n: n, all: all, visible: visible).click
29
29
  end
30
30
 
31
+ def option(text, n: 1, all: false, visible: true)
32
+ @a0.find.option(text, n: n, all: all, visible: visible).click
33
+ end
34
+
31
35
  def xpath(text, n: 1, all: false, visible: true)
32
36
  @a0.find.xpath(text, n: n, all: all, visible: visible).click
33
37
  end
@@ -6,15 +6,21 @@ module Webdrone
6
6
  end
7
7
 
8
8
  class Conf
9
- attr_accessor :a0, :timeout
9
+ attr_accessor :a0, :timeout, :outdir
10
10
 
11
11
  def initialize(a0)
12
12
  @a0 = a0
13
+ @outdir = "."
13
14
  end
14
15
 
15
16
  def timeout=(val)
16
17
  @timeout = val
17
18
  @a0.driver.manage.timeouts.implicit_wait = val
18
19
  end
20
+
21
+ def outdir=(val)
22
+ @outdir = val
23
+ FileUtils.mkdir_p val
24
+ end
19
25
  end
20
26
  end
@@ -28,7 +28,7 @@ module Webdrone
28
28
  @current_frame = name
29
29
  if block_given?
30
30
  yield
31
- @a0.driver.switch_to.parent_frame
31
+ @a0.driver.switch_to.frame old_frame
32
32
  @current_frame = old_frame
33
33
  end
34
34
  @current_frame
@@ -12,9 +12,9 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(id)
15
+ def id(text)
16
16
  @a0.wait.for do
17
- @a0.driver.find_element :id, id
17
+ @a0.driver.find_element :id, text
18
18
  end
19
19
  end
20
20
 
@@ -30,6 +30,10 @@ module Webdrone
30
30
  self.xpath XPath::HTML.link_or_button(text).to_s, n: n, all: all, visible: visible
31
31
  end
32
32
 
33
+ def option(text, n: 1, all: false, visible: true)
34
+ self.xpath XPath::HTML.option(text).to_s, n: n, all: all, visible: visible
35
+ end
36
+
33
37
  def xpath(text, n: 1, all: false, visible: true)
34
38
  @a0.wait.for do
35
39
  items = @a0.driver.find_elements :xpath, text
@@ -12,8 +12,8 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(id, color: 'red')
16
- flash @a0.find.id(id), color: color
15
+ def id(text, color: 'red')
16
+ flash @a0.find.id(text), color: color
17
17
  end
18
18
 
19
19
  def link(text, color: 'red', n: 1, all: false, visible: true)
@@ -28,24 +28,28 @@ module Webdrone
28
28
  flash @a0.find.on(text, n: n, all: all, visible: visible), color: color
29
29
  end
30
30
 
31
+ def option(text, color: 'red', n: 1, all: false, visible: true)
32
+ flash @a0.find.option(text, n: n, all: all, visible: visible), color: color
33
+ end
34
+
31
35
  def xpath(text, color: 'red', n: 1, all: false, visible: true)
32
36
  flash @a0.find.xpath(text, n: n, all: all, visible: visible), color: color
33
37
  end
34
38
 
35
39
  def flash(item, color: 'red')
36
40
  3.times do
37
- border 'white', item
41
+ border item, 'white'
38
42
  sleep 0.1
39
- border 'blue', item
43
+ border item, 'blue'
40
44
  sleep 0.1
41
- border color, item
45
+ border item, color
42
46
  sleep 0.1
43
47
  end
44
48
  item
45
49
  end
46
50
 
47
51
  protected
48
- def border(color, item)
52
+ def border(item, color)
49
53
  if item.is_a? Array
50
54
  item.each do |item|
51
55
  @a0.exec.script("arguments[0].style.border = '2px solid #{color}'", item)
@@ -15,6 +15,7 @@ module Webdrone
15
15
  def screen(name)
16
16
  @counter = (@counter || 0) + 1
17
17
  filename = sprintf "screenshot-%04d-%s.png", @counter, name
18
+ filename = File.join(@a0.conf.outdir, filename)
18
19
  @a0.driver.save_screenshot filename
19
20
  end
20
21
  end
@@ -12,8 +12,8 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(id)
16
- @a0.find.id(id).text
15
+ def id(text)
16
+ @a0.find.id(text).text
17
17
  end
18
18
 
19
19
  def link(text, n: 1, all: false, visible: true)
@@ -28,6 +28,10 @@ module Webdrone
28
28
  @a0.find.on(text, n: n, all: all, visible: visible).text
29
29
  end
30
30
 
31
+ def option(text, n: 1, all: false, visible: true)
32
+ @a0.find.option(text, n: n, all: all, visible: visible).text
33
+ end
34
+
31
35
  def xpath(text, n: 1, all: false, visible: true)
32
36
  @a0.find.xpath(text, n: n, all: all, visible: visible).text
33
37
  end
@@ -1,3 +1,3 @@
1
1
  module Webdrone
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -12,8 +12,8 @@ module Webdrone
12
12
  @a0 = a0
13
13
  end
14
14
 
15
- def id(id, attr: nil, eq: nil, contains: nil)
16
- vrfy @a0.find.id(id), attr: attr, eq: eq, contains: contains
15
+ def id(text, attr: nil, eq: nil, contains: nil)
16
+ vrfy @a0.find.id(text), attr: attr, eq: eq, contains: contains
17
17
  end
18
18
 
19
19
  def link(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
@@ -28,6 +28,10 @@ module Webdrone
28
28
  vrfy @a0.find.on(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
29
29
  end
30
30
 
31
+ def option(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
32
+ vrfy @a0.find.option(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
33
+ end
34
+
31
35
  def xpath(text, n: 1, visible: true, attr: nil, eq: nil, contains: nil)
32
36
  vrfy @a0.find.xpath(text, n: n, visible: visible), attr: attr, eq: eq, contains: contains
33
37
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: webdrone
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Aldrin Martoq
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2015-09-08 00:00:00.000000000 Z
11
+ date: 2015-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler