This repository has been archived by the owner on May 28, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andy B
committed
May 14, 2020
1 parent
c5744a6
commit bb056c0
Showing
8 changed files
with
323 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
require "foot_traffic" | ||
using FootTraffic | ||
|
||
opts = { | ||
headless: true, | ||
process_timeout: 10, | ||
timeout: 100, | ||
slowmo: 0.1, | ||
window_size: [1024, 768] | ||
} | ||
|
||
begin | ||
FootTraffic::Session.start(options: opts, quit: true, clones: 100) do |window, pool| | ||
pool << window.tab_thread { |tab| tab.goto "https://www.lewagon.com" } | ||
pool << window.tab_thread { |tab| tab.goto "https://www.lewagon.com/berlin" } | ||
pool << window.tab_thread { |paris| | ||
paris.goto "https://www.lewagon.com/paris" | ||
paris.at_css('[href="/paris/apply"]').click | ||
paris.at_css("#apply_first_name").focus.type("Alan") | ||
paris.at_css("#apply_last_name").focus.type("Turing", :Tab) | ||
} | ||
pool.wait | ||
end | ||
rescue FootTraffic::ResourceOverloadError | ||
puts "Oops..." | ||
exit(1) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
require "concurrent" # concurrent-ruby | ||
|
||
tokens = [] # imaginary array of auth tokens | ||
|
||
cookies = Concurrent::Hash.new | ||
|
||
opts = { | ||
headless: false, # Headless or not | ||
timeout: 300, # How long to wait for new tab to open, set for high value | ||
slowmo: 0.1, # How fast do you want bots to type | ||
window_size: [1200, 800] | ||
} | ||
|
||
FootTraffic::Session.start(options: opts, quit: true) do |window, pool| | ||
tokens.each do |token| | ||
sleep(1) # Need to sleep so we can propely save cookies | ||
pool << window.with_tab { |tab| | ||
tab.goto("https://example.com/sign_in/#{token}") | ||
cookies[token] = tab.cookies["_example_session"].value | ||
} | ||
end | ||
pool.wait | ||
end | ||
|
||
FootTraffic::Session.start(options: opts) do |window| | ||
tokens.each do |token| | ||
sleep(1) # Wait to properly load cookies | ||
window.with_tab do |tab| | ||
tab.cookies.clear | ||
tab.cookies.set( | ||
name: "_example_session", | ||
domain: "example.lewagon.co", | ||
value: cookies[token] | ||
) | ||
tab.goto("https://example.com/protected_route") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "foot_traffic" | ||
using FootTraffic | ||
|
||
FootTraffic::Session.start do |window| | ||
window.tab_thread { |tab| tab.goto "https://www.lewagon.com" } | ||
window.tab_thread { |tab| tab.goto "https://www.lewagon.com/berlin" } | ||
window.tab_thread do |paris| | ||
paris.goto "https://www.lewagon.com/paris" | ||
paris.at_css('[href="/paris/apply"]').click | ||
paris.at_css("#apply_first_name").focus.type("Alan") | ||
paris.at_css("#apply_last_name").focus.type("Turing", :Tab) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
require "foot_traffic" | ||
using FootTraffic | ||
|
||
FootTraffic::Session.start(quit: true) do |window, pool| | ||
pool << window.tab_thread { |tab| tab.goto "https://www.lewagon.com" } | ||
pool << window.tab_thread { |tab| tab.goto "https://www.lewagon.com/berlin" } | ||
pool << window.tab_thread { |paris| | ||
paris.goto "https://www.lewagon.com/paris" | ||
paris.at_css('[href="/paris/apply"]').click | ||
paris.at_css("#apply_first_name").focus.type("Alan") | ||
paris.at_css("#apply_last_name").focus.type("Turing", :Tab) | ||
} | ||
pool.wait | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
require "foot_traffic" | ||
using FootTraffic | ||
|
||
FootTraffic::Session.start do |window| | ||
window.tab_thread { |tab| tab.goto "https://www.lewagon.com" } | ||
window.tab_thread { |tab| tab.goto "https://www.lewagon.com/berlin" } | ||
window.tab_thread { |tab| tab.goto "https://www.lewagon.com/paris" } | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
require "foot_traffic" | ||
using FootTraffic | ||
|
||
FootTraffic::Session.start do |window| | ||
window.new_tab.goto "https://www.lewagon.com" | ||
window.new_tab.goto "https://www.lewagon.com/berlin" | ||
|
||
paris = window.new_tab | ||
paris.goto "https://www.lewagon.com/paris" | ||
paris.at_css('[href="/paris/apply"]').click | ||
paris.at_css("#apply_first_name").focus.type("Alan") | ||
paris.at_css("#apply_last_name").focus.type("Turing", :Tab) | ||
end |