Skip to content

Instantly share code, notes, and snippets.

View Blue-Pix's full-sized avatar
💭
🤔

Blue-Pix Blue-Pix

💭
🤔
  • Amazon Web Services Japan G.K.
  • Tokyo
View GitHub Profile
@Blue-Pix
Blue-Pix / app.sh
Created April 24, 2019 09:28
see code deploy log verbose
less /opt/codedeploy-agent/deployment-root/deployment-logs/codedeploy-agent-deployments.log
# set verbose log true
# :verbose: => true
vi /etc/codedeploy-agent/conf/codedeployagent.yml
@Blue-Pix
Blue-Pix / cli.sh
Created April 24, 2019 09:18
get parameters from parameter store using aws cli and ruby(vi aws-sdk gem)
# get by name
aws ssm get-parameter --name "foo"
# get by path
aws ssm get-parameters-by-path --path /foo/bar/
# option
# maximum number of items to return
@Blue-Pix
Blue-Pix / app.rb
Created April 22, 2019 10:59
manipulate browser popup(alert, confirm, prompt) using selenium
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
# focus on popup
# whatever popup is, use `switch_to.alert`.
alert = driver.switch_to.alert
# if no popup found, raises
Selenium::WebDriver::Error::NoAlertPresentError
@Blue-Pix
Blue-Pix / app.rb
Created April 22, 2019 10:46
initialize selenium web driver for chrome with proxy
require "selenium-webdriver"
# optional
args = [
"--headless", "--single-process", "--disable-gpu", "--no-sandbox",
"--ignore-certificate-errors", "--password-store=detect", "--incognito",
"--user-data-dir=foo"
]
ip_address = 127.0.0.1
@Blue-Pix
Blue-Pix / app.rb
Created April 22, 2019 10:44
initialize selenium driver for chrome
require "selenium-webdriver"
# optional
args = [
"--headless", "--single-process", "--disable-gpu", "--no-sandbox",
"--ignore-certificate-errors", "--password-store=detect", "--incognito",
"--user-data-dir=foo"
]
caps = Selenium::WebDriver::Remote::Capabilities.chrome :chromeOptions => { :args => args }
@Blue-Pix
Blue-Pix / app.rb
Created April 22, 2019 10:42
terminate properly selenium driver process without causing memory leak
require "selenium-webdriver"
begin
driver = Selenium::WebDriver.for :chrome
# do something
ensure
driver.quit unless driver.nil?
end
# some code in the Internet, use `drive.close`,
@Blue-Pix
Blue-Pix / app.rb
Last active April 22, 2019 11:16
cheat sheet for selenium
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
# open url
driver.navigate.to "https://foo.bar"
# refresh page
driver.navigate.refresh
@Blue-Pix
Blue-Pix / app.rb
Created April 22, 2019 10:17
wait particular element rendered using selenium
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
# `implicit wait`
# this is a king of request timeout.
driver.manage.timeouts.page_load = 10
# `explicit wait`
# until `wait.until` block returns true, does not proceed further in the code.
@Blue-Pix
Blue-Pix / app.rb
Last active April 22, 2019 09:42
manipulate selectbox using selenium
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
element = driver.find_element(:id, "foo")
selectbox = Selenium::WebDriver::Support::Select.new(element)
# select by text
selectbox.select_by(:text, "Japan")
@Blue-Pix
Blue-Pix / app.rb
Last active April 22, 2019 09:44
check particular element exists? using selenium
require "selenium-webdriver"
driver = Selenium::WebDriver.for :chrome
# if multiple or no elements may exist.
elements = driver.find_elements(:class, "foo")
# `find_elements` returns Array. if no element found, returns [].
elements.size.positive?