Last active
August 29, 2015 14:03
-
-
Save gotunandan/6716794385ec1c058b0c to your computer and use it in GitHub Desktop.
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
require 'curb' | |
require 'json' | |
$url = "http://google.com" | |
$selhost = "http://localhost:4444/wd/hub/" | |
def curl_delete(paramas, map) | |
url_path = $selhost + map | |
curl_easy = Curl.delete(url_path, paramas) do |http| | |
http.headers['Content-Type'] = 'application/json;charset=UTF-8' | |
http.headers['Accept'] = 'application/json' | |
end | |
return curl_easy.body_str | |
end | |
def curl_transfer(params, map) | |
url_path = $selhost + map | |
curl_easy = Curl.post(url_path, params) do |http| | |
http.headers['Content-Type'] = 'application/json;charset=UTF-8' | |
http.headers['Accept'] = 'application/json' | |
end | |
return curl_easy.body_str | |
end | |
def get_id(capabilities) | |
params = JSON.dump(capabilities) | |
map = "session" | |
body_str = curl_transfer(params, map) | |
puts body_str | |
response = JSON.parse(body_str) | |
return response["sessionId"] | |
end | |
def main() | |
capabilities = { | |
"browserName" => "firefox", | |
"platform" => "ANY", | |
"javascriptEnabled" => true | |
} | |
desired_capabilities = {"desiredCapabilities" => capabilities} | |
session_id = get_id(desired_capabilities) | |
puts("Session Id is #{session_id}") | |
session = "session/#{session_id}" | |
map = "#{session}/url" | |
params = JSON.dump({"url" => $url}) | |
puts(curl_transfer(params, map)) | |
map = "#{session}/element" | |
params = JSON.dump({"using" => "id", "value" => "gbqfq"}) | |
puts(curl_transfer(params, map)) | |
map = "#{session}/element/0/value" | |
params = JSON.dump({"value" => ["seleniumhq"]}) | |
puts(curl_transfer(params, map)) | |
map = "#{session}/element" | |
params = JSON.dump({"using" => "id", "value" => "gbqfb"}) | |
puts(curl_transfer(params, map)) | |
map = "#{session}/element/1/click" | |
params = {} | |
puts(curl_transfer(params, map)) | |
sleep(10) | |
map = "#{session}/window" | |
params = {} | |
puts(curl_delete(params, map)) | |
end | |
###################### | |
if __FILE__ == $0 | |
main() | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment