webdriver-user-agent-randomizer 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +19 -0
- data/.rvmrc +2 -0
- data/Gemfile +4 -0
- data/HISTORY.md +7 -0
- data/LICENSE +22 -0
- data/README.md +54 -0
- data/Rakefile +7 -0
- data/bin/generate_user_agents.rb +22 -0
- data/lib/user_agents.txt +9057 -0
- data/lib/webdriver-user-agent-randomizer.rb +39 -0
- data/spec/webdriver-user-agent-randomizer_spec.rb +41 -0
- data/webdriver-user-agent-randomizer.gemspec +22 -0
- metadata +157 -0
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'selenium-webdriver'
|
2
|
+
require 'facets/hash/except'
|
3
|
+
require 'yaml'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
UA_FILE = "../user_agents.txt"
|
7
|
+
|
8
|
+
module UserAgent
|
9
|
+
def self.driver options={}
|
10
|
+
options[:browser] ||= :firefox
|
11
|
+
|
12
|
+
user_agent = ua_pool[Random.rand(ua_pool.size)]
|
13
|
+
|
14
|
+
case options[:browser]
|
15
|
+
when :firefox
|
16
|
+
options[:profile] ||= Selenium::WebDriver::Firefox::Profile.new
|
17
|
+
options[:profile]['general.useragent.override'] = user_agent
|
18
|
+
when :chrome
|
19
|
+
options[:switches] ||= []
|
20
|
+
options[:switches] << "--user-agent=#{user_agent}"
|
21
|
+
else
|
22
|
+
raise "WebDriver UserAgent currently only supports :firefox and :chrome."
|
23
|
+
end
|
24
|
+
driver = Selenium::WebDriver.for options[:browser], options.except(:browser)
|
25
|
+
driver
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.ua_pool
|
29
|
+
@ua_pool = []
|
30
|
+
ua_file = File.open(File.expand_path(UA_FILE, __FILE__), 'r') do |f|
|
31
|
+
f.readlines
|
32
|
+
end
|
33
|
+
ua_file.each do |ua|
|
34
|
+
@ua_pool << ua
|
35
|
+
end
|
36
|
+
@ua_pool
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
5
|
+
require 'webdriver-user-agent-randomizer'
|
6
|
+
require 'selenium-webdriver'
|
7
|
+
require 'watir-webdriver'
|
8
|
+
require 'nokogiri'
|
9
|
+
|
10
|
+
describe "webdriver user agent randomizer" do
|
11
|
+
after :each do
|
12
|
+
@driver.quit if @driver
|
13
|
+
end
|
14
|
+
|
15
|
+
it "can create a new webdriver driver using Firefox and a random user agent" do
|
16
|
+
@driver = UserAgent.driver
|
17
|
+
@driver.browser.should == :firefox
|
18
|
+
@driver.execute_script('return navigator.userAgent').should_not be_nil
|
19
|
+
end
|
20
|
+
|
21
|
+
it "can create a new webdriver driver using Chrome and a random user agent" do
|
22
|
+
@driver = UserAgent.driver(:browser => :chrome)
|
23
|
+
@driver.browser.should == :chrome
|
24
|
+
@driver.execute_script('return navigator.userAgent').should_not be_nil
|
25
|
+
end
|
26
|
+
|
27
|
+
it "can create a new webdriver driver using an existing Firefox profile" do
|
28
|
+
profile = Selenium::WebDriver::Firefox::Profile.new
|
29
|
+
profile['browser.startup.homepage'] = "data:text/html,<title>hello</title>"
|
30
|
+
@driver = UserAgent.driver(:browser => :firefox, :profile => profile)
|
31
|
+
@driver.browser.should == :firefox
|
32
|
+
@driver.execute_script('return navigator.userAgent').should_not be_nil
|
33
|
+
@driver.title.should == 'hello'
|
34
|
+
end
|
35
|
+
|
36
|
+
it "can allow using selenium driver for watir browser" do
|
37
|
+
@driver = UserAgent.driver(:browser => :firefox)
|
38
|
+
@browser = Watir::Browser.new @driver
|
39
|
+
@browser.url.should == "about:blank"
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |gem|
|
4
|
+
gem.authors = ["Christoph Pilka"]
|
5
|
+
gem.email = ["c.pilka@asconix.com"]
|
6
|
+
gem.description = %q{A helper gem to emulate random generated web browser user agents when using webdriver}
|
7
|
+
gem.summary = %q{A helper gem to emulate random generated web browser user agents when using webdriver}
|
8
|
+
gem.homepage = "http://github.com/asconix/webdriver-user-agent-randomizer"
|
9
|
+
|
10
|
+
gem.files = `git ls-files`.split($\)
|
11
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
12
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
13
|
+
gem.name = "webdriver-user-agent-randomizer"
|
14
|
+
gem.require_paths = ["lib"]
|
15
|
+
gem.version = "0.0.1"
|
16
|
+
gem.add_dependency 'selenium-webdriver'
|
17
|
+
gem.add_dependency 'facets'
|
18
|
+
gem.add_dependency 'json'
|
19
|
+
gem.add_dependency 'nokogiri'
|
20
|
+
gem.add_development_dependency 'rspec'
|
21
|
+
gem.add_development_dependency 'watir-webdriver'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: webdriver-user-agent-randomizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Christoph Pilka
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-09-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: selenium-webdriver
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: facets
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: json
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: nokogiri
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :runtime
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: rspec
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: watir-webdriver
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: A helper gem to emulate random generated web browser user agents when
|
111
|
+
using webdriver
|
112
|
+
email:
|
113
|
+
- c.pilka@asconix.com
|
114
|
+
executables:
|
115
|
+
- generate_user_agents.rb
|
116
|
+
extensions: []
|
117
|
+
extra_rdoc_files: []
|
118
|
+
files:
|
119
|
+
- .gitignore
|
120
|
+
- .rvmrc
|
121
|
+
- Gemfile
|
122
|
+
- HISTORY.md
|
123
|
+
- LICENSE
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/generate_user_agents.rb
|
127
|
+
- lib/user_agents.txt
|
128
|
+
- lib/webdriver-user-agent-randomizer.rb
|
129
|
+
- spec/webdriver-user-agent-randomizer_spec.rb
|
130
|
+
- webdriver-user-agent-randomizer.gemspec
|
131
|
+
homepage: http://github.com/asconix/webdriver-user-agent-randomizer
|
132
|
+
licenses: []
|
133
|
+
post_install_message:
|
134
|
+
rdoc_options: []
|
135
|
+
require_paths:
|
136
|
+
- lib
|
137
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
138
|
+
none: false
|
139
|
+
requirements:
|
140
|
+
- - ! '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
requirements: []
|
150
|
+
rubyforge_project:
|
151
|
+
rubygems_version: 1.8.24
|
152
|
+
signing_key:
|
153
|
+
specification_version: 3
|
154
|
+
summary: A helper gem to emulate random generated web browser user agents when using
|
155
|
+
webdriver
|
156
|
+
test_files:
|
157
|
+
- spec/webdriver-user-agent-randomizer_spec.rb
|