#断言
def assert_true(actual, expect)
expect(actual).to eq(expect)
end
def assert_false(actual, expect)
expect(actual).not_to eq(expect)
end
def assert_include(actual, expect)
expect(actual).to include(expect)
end
def assert_not_include(actual, expect)
expect(actual).not_to include(expect)
end
#关闭当前的tab
Driver.close
#获取浏览器的tab数
Driver.window_handles.length
#根据location来点击元素
Driver.action.move_to_location(location_x, location_y).click.perform
#页面scroll up
Driver.execute_script('window.scrollTo(0,0))
#页面scroll down
Driver.execute_script('window.scrollTo(0,document.body.scrollHeight);)
#scroll到特定的元素
Driver.execute_script('arguments[0].scrollintoView();, element)
#获取当前的page的url
Driver.current_url
#获取当前浏览器的title
Driver.title
# switch to特定的frame
Driver.switch_to.frame(target)
#返回到原来的frame
Driver.switch_to.default_content
#删除所有的cookies
Driver.manage.delete_all_cookies
#浏览器返回上一页
Driver.navigate.back
# switch to一个新的tab页:
def switch_to_new_window
current_handle = Driver.window_handle rescue nilDriver.window_handles.each do |handle|next if current_handle == handleDriver.switch_to.window(handle)end
end
#在浏览器创建新的tab页,并且输入URL
current_window_handle =Driver.window handle
before_window_handles =Driver.window handles
Driver.execute_script('window.open())
switch_to_new_window
Driver.navigate.to(new_url)
#浏览器页面刷新
Driver.navigate.refresh
#获取页面元素的,X,Y坐标值
target = Driver.find_element(:id,‘elemeny_id_01')
target.rect.y
target.rect.x
#获取元素的个数
target.size
#获取元素的css
target.css_value(attri)
#获取元素的attribute.target.attribute(attri)
网友评论