Selenium ruby常用api

#断言

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)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、自动化测试所属分类(站在代码可见度角度分类) 1. 黑盒测试(功能测试)2. 灰盒测试(接口测试)3. 白盒测...
    MAVIS_42bf阅读 961评论 0 0
  • [TOC] 简介 Selenium 是一个用于Web应用程序测试的工具。Selenium测试直接运行在浏览器中,就...
    Whyn阅读 1,163评论 0 2
  • from seleniumimport webdriver import unittest from timeim...
    足__迹阅读 1,284评论 0 0
  • Awesome Ruby Toolbox Awesome A collection of awesome Ruby...
    debbbbie阅读 2,976评论 0 3
  • 1.python ui自动化: 报告模板:https://github.com/GoverSky/HTMLTest...
    hao0_0阅读 1,023评论 0 1