Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Ruby introduction to QA people
Search
SiweiShen
January 03, 2013
1
58
Ruby introduction to QA people
how to use ruby in QA work.
SiweiShen
January 03, 2013
Tweet
Share
More Decks by SiweiShen
See All by SiweiShen
unit tests in ruby
sg552sg552
1
91
ruby introduction ( Chinese)
sg552sg552
1
62
meta programming ruby
sg552sg552
5
220
Featured
See All Featured
Speed Design
sergeychernyshev
28
870
The Invisible Side of Design
smashingmag
299
50k
Measuring & Analyzing Core Web Vitals
bluesmoon
6
360
Embracing the Ebb and Flow
colly
85
4.6k
Bash Introduction
62gerente
611
210k
Facilitating Awesome Meetings
lara
53
6.3k
Building Applications with DynamoDB
mza
94
6.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
30k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
40
2.1k
Improving Core Web Vitals using Speculation Rules API
sergeychernyshev
12
630
Building a Scalable Design System with Sketch
lauravandoore
462
33k
The Language of Interfaces
destraynor
157
24k
Transcript
RUBY: 新 言的代表 兴语 • 可 性更好 读 : File.read(“some_file.txt”)
• 代 更少: 码 JAVA 代 的 码 1/3 ~ 1/5 • 文档丰富,社区火爆,各 工具 出不 种 层 穷 • JAVA 者 终结 • 缺点 1 : RUBY 程序 太少 员 • 缺点 2 : 英文要求高(文档全英文) 对
例子 1 :部署 • 我要做一次部署,人肉的 是: 步骤 • 1. 从
GIT 下 代 到本地 载 码 • 2. 上 最新代 到服 器 传 码 务 • 3. 做某些 服 器 境的 置(数据 等) 针对 务 环 设 库 • 4. 重启服 器 务 • 5. 万一出 了,回 到前一个版本 错 滚 .
SHELL 脚本: • 1. git clone git://scm.org/your_project.git • 2. scp
your_project login@server.com:/target_dir • 3. ssh server.com • 3.1 $ cp database.property config/ • 3.2 $ cp other_files... • 3.3 $ tomcat restart • 4. Roll back? 度太大 实现难
Ruby 脚本 : • 1. 配置好 config/deploy.rb set :deploy_to “target_folder”
set :user_name “kcv478” • 2. 部署 : $cap deploy • ssh to server • checkout code • copy config files.. • restart server • rollback if failed...
例子 2 :替 某些文本 换 • 在 去的一个 目中,由于服 器的某个
置 过 项 务 设 问 , 次部署的 候,都需要修改 题 每 时 4 个 css 文 件,一个 js 文件,和 3 个文本文件,它 要 们 做的事情都是一个: • 把 url(“some_image_path”) • 替 成 换 url(“sub_uri/some_image_path”)
SHELL 脚本:使用了 expect #!/usr/bin/expect # open public/stylesheets/application.css send ":e public/stylesheets/application.css\r"
sleep 2 expect "application.css" # execute replace command send ":%s/url(\\/im/url(\\/$sub_uri\\/im/g\r" sleep 2 expect ] send ":w\r" expect written
RUBY 脚本 content = File.read(“application.css”) File.write(“application.css”, 'w') do |file| file.puts
content.gsub “url(“, “url(/sub_uri/” end
例子 3 : 找包含特定字符的文件 查 • SHELL: find . -name
\*.rb -print0 | xargs -0 grep some_method • RUBY: (注意可 性) 读 dir['**/*.rb'].search(/some_method/)
: 大部分 候,用 结论 绝 时 RUBY • http://stackoverflow.com/questions/2342894/ruby-or- python-instead-of-shell
• 极其 的情况可以使用 简单 纯shell: $ who | grep -i admin | cut -c10-20 • 其他情况,全用 RUBY :
例子 4 : Java, Python, Ruby 比较 • java 的配置文件
(Maven) <dependencies> <dependency> <groupId>org.seleniumhq.selenium</groupId> <artifactId>selenium-java</artifactId> <version>2.25.0</version> </dependency> <dependency> <groupId>com.opera</groupId> <artifactId>operadriver</artifactId> </dependency> </dependencies>
例子 4 : Java, Python, Ruby 比较 • Python 的配置文件
(Fabric) def deploy(setup_initial_data = None, server_password = None ): deployed_to = fabric.operations.prompt("Where do you want it deployed?", default = settings["default_deployed_to"]) print " === now executing the deploy script” print “, result will be saved as:{0}".format(log_file) command = “ deploy command... “ local(command.format(server_password, log_file, user, portal_server, deployed_to), capture=True)
例子 4 : Java, Python, Ruby 比较 • Ruby 的配置文件
(Capistrano) • namespace :deploy do set :use_sudo, true task :start do run "/opt/nginx/sbin/nginx" end task :stop do run "/opt/nginx/sbin/nginx -s stop" end end
直 感受:可 性 观 读 • 在可 性上, 读 Java
< Python < Ruby • Ruby 更接近于自然 言 语
例子 5 Ruby 行 进 Selenium 测试 • 1. admin.html:
出 导 : java: 182 行 Ruby: 95 行
Java public class Admin { private WebDriver driver; private String
baseUrl; private StringBuffer verificationErrors = new StringBuffer(); @Before public void setUp() throws Exception { driver = new FirefoxDriver(); baseUrl = "https://admin-qa300.blurdev.com/"; driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); }
Ruby 代码 def setup @driver = Selenium::WebDriver.for :firefox @base_url =
"https://adminqa300.blurdev.com/" @driver.manage.timeouts.implicit_wait = 30 end
Ruby 使用的工具 (RubyGem) : • 自 化部署: 动 Capistrano •
自 化 : 动 测试 Selenium, Water • 日常 用自 化: 内置了无数方法 应 动 • google 一下 , 有更多工具等着你~
与其他 言比 的 : 语 较 结论 • Java ,
Python 能做的 , Ruby 都能做 • web 开发 • 自 化 动 测试 • 运维 • 代替 SHELL 脚本 • 可 性 最好 读 • 上手 ,适合新手 简单
缺点: • 除了 JRUBY ,目前只支持 程 单线 • 国内 Ruby
程序 太少 员 • 速度比 JAVA 慢一点儿,不适合做 3D 的 实时类 游 。 戏
对QA 人 的建 : 员 议 • 日常操作中 使用 RUBY
代替 SHELL 脚本 • JAVA 的 目自 化,尽量 是用 项 动 还 Java + selenium. 可以得到技 支持 这样 术
大家! 谢谢 •