-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparallel_test_ruby.rb
58 lines (54 loc) · 3 KB
/
parallel_test_ruby.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
require 'rubygems'
require 'selenium-webdriver'
def run_session(browser, browser_version, platform_name, os, osVersion, buildName, sessionName, seleniumVersion)
options = Selenium::WebDriver::Options.send browser
options.browser_version = browser_version
options.platform_name = platform_name
bstack_options = {
"os" => os,
"osVersion" => osVersion,
"buildName" => buildName,
"sessionName" => sessionName,
"seleniumVersion" => seleniumVersion,
}
options.add_option('bstack:options', bstack_options)
driver = Selenium::WebDriver.for(:remote,
:url => "https://YOUR_USER_NAME:[email protected]/wd/hub",
:capabilities => options)
begin
# opening the bstackdemo.com website
driver.navigate.to "https://bstackdemo.com"
wait = Selenium::WebDriver::Wait.new(:timeout => 10) # seconds
wait.until { !driver.title.match(/StackDemo/i).nil? }
# getting name of the product available on the webpage
product = driver.find_element(:xpath, '//*[@id="1"]/p')
wait.until { product.displayed? }
product_text = product.text
# waiting until the Add to Cart button is displayed on webpage and then clicking it
cart_btn = driver.find_element(:xpath, '//*[@id="1"]/div[4]')
wait.until { cart_btn.displayed? }
cart_btn.click
# waiting until the Cart pane appears
wait.until { driver.find_element(:xpath, '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]').displayed? }
# getting name of the product in the cart
product_in_cart = driver.find_element(:xpath, '//*[@id="__next"]/div/div/div[2]/div[2]/div[2]/div/div[3]/p[1]')
wait.until { product_in_cart.displayed? }
product_in_cart_text = product_in_cart.text
# checking if the product has been added to the cart
if product_text.eql? product_in_cart_text
# marking test as 'passed' if the product is successfully added to the cart
driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"passed", "reason": "Product has been successfully added to the cart!"}}')
else
# marking test as 'failed' if the product is not added to the cart
driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Failed to add product to the cart"}}')
end
# marking test as 'failed' if test script is unable to open the bstackdemo.com website
rescue
driver.execute_script('browserstack_executor: {"action": "setSessionStatus", "arguments": {"status":"failed", "reason": "Some elements failed to load"}}')
end
driver.quit
end
t1 = Thread.new{ run_session("chrome", "latest", "MAC", "OS X", "Sierra", "parallel-snippet-test", "ruby 2", "4.0.0") }
t2 = Thread.new{ run_session("firefox", "latest", "MAC", "OS X", "Sierra", "parallel-snippet-test", "ruby 3", "4.0.0") }
t1.join()
t2.join()