??xml version="1.0" encoding="utf-8" standalone="yes"?>
My previous RebelLabs post showed us that there still is a nice amount of interest among the developers in neat command line tools. This is great news as it means there are still lots of geeks reaching for their maximum l33t potential! This post will, as the title suggests, jump into 5 more tools that will hopefully tickle your fancy.
Whilst it is hard to find a set of tools relevant for every different command line professional or enthusiast, I can still wholly recommend glancing over these tools briefly. You never know when you’ll get stuck in a terminal only environment or will need to impress a friend with your exceptional command line skills. So without further ado, here are 5 more command line tools you should consider using!
1. Install it once
2. Forget it’s even there
3. Profit from its productivity: z.
OK, but what’s it all about? Well, z allows you to quickly jump from folder to folder, without having to bother writing the full absolute or relative paths. To achieve this, it simply records all the folders you visit, and then ranks them based on a combination of the frequency and time of last use. Now all you need to do is type z part/of/path
and hit enter. With this, z will automagically guide you to the highest ranking match.
To install z, download z.sh and source it in ~/.zshrc or ~/.bashrc, if you still haven’t made the inevitable jump to ZSH. Now go about your regular flow, cd
-ing all over the place, and you are done!
Alternatively, if you use the oh-my-zsh framework, simply add it in the plugins listing of ~/.zshrc.
$ vim ~/.zshrc plugins=(brew git mercurial mvn osx sbt scala vi-mode z)
By default, z stores its data in ~/.z, below are my contents after I cleared them and moved around a bit. After printing the data, you can see I moved to 2 different folders by specifying only a small part of the path, irrespective of the current folder. Take note that the directory name was matched mid-word in a case insensitive way — very handy!
All in all I highly recommend this great tool to anyone that spends any amount of time at the command line, whatever your background, interest or use case may be.
The second tool of this post is the excellent youtube-dl. A cross-platform tool allowing you to, unsuprisingly, download Youtube videos. The easiest way to install is either via Homebrew orpip as shown below. Other download options can be found via the link above.
$ brew install youtube-dl $ sudo pip install --upgrade youtube_dl
At times, for whatever reason, you may want to download a presentation for archiving’s purposes. Or better yet, imagine you spend the weekend in the Estonian countryside, devoid of internet, yet you really wanted to see the latest Virtual JUG sessions. A simple youtube-dl https://youtu.be/PQPvZkA-6bg
suffices at this point.
Other nice things to take note of:
youtube-dl -f $FORMAT $LINK
will override this. You find available formats with the -F flag.man youtube-dl
.I will assume that anyone spending significant some time at the command line will want to automate tasks using shell scripts. Bash itself is renowned for its many pitfalls, and even advanced scripters will from time to time bump into something unexpected. Unfortunately for us, a shell script has no undo button, and “unexpected” results may well be synonymous with “catastrophic” results.
Long intro short: we have a valuable tool on our side to guard ourselves against exactly this,shellcheck! In essence, it is a static analyser that will tell you where your script goes wrong.
Install shellcheck via your package manager of choice: Homebrew, Pacman, APT; build it from source, or run it inside your browser.
$ brew install shellcheck # pacman -S shellcheck # apt-get install shellcheck
This list may be of particular interest to you as it describes code samples that shellcheck can protect you against. To run, simply execute shellcheck my-script
, it will read the shebang (#!) directive to decide whether to analyse as sh, bash or ksh.
As shown in the example output above, there is one syntax error, it’s marked in red: spaces surrounding the assignment. However, shellcheck goes beyond that. In yellow markings is a warning of a potentially catastrophic event: what if toDelete is ever empty? Granted, the example is somewhat contrived, without –no-preserve-root there will be no damage should the statement resolve to /, but my point still stands! Finally, in green you will find general warnings on potential future mishaps that are best not to be ignored.
As a closing remark on shellcheck: use the neat Syntastic Vim plugin to integrate the tool inside Vim itself, configuring when it should run, how it should behave, etc. The same script that generated the ouput above now looks like the following, from our favorite text editor.
For the sys-admins and dev-opses amongst us: stop using tail -f
, and start using, multitail, tail on steroids! This ultimate log-viewer allows you to do a couple of really cool things that make it worth mentioning. Alternatively you could always either use tmux or screen to get in-shell multiplexing, or just use a modern terminal emulator allowing you to do the splitting like that, such as iTerm2 or Terminator, however in these cases you may miss some of the features below.
You know the drill how to install:
$ brew install multitail # pacman -S multitail # apt-get install multitail
For an actual example, here is a screenshot of a window where I’m developing JRebel by attaching it to Tomcat, running the infamous petclinic project. At that time I needed both Tomcat’s own output and the JRebel one. Take note of the -CS
flag, signifying “use this color scheme for all subsequent files”, followed by the name of the scheme.
As both logs color nicely with the Apache rules, they are set, finally followed by the actual paths of the logfiles.
$ multitail -CS apache "$TOMCAT_HOME/logs/catalina.out" "$HOME/.jrebel/jrebel.log"
Our final tool in this post is the essential tree utility. Tree prints a nice, structured, tree-view of your directories, allowing you to instantly get an idea about the structure of your data, without having to ls, cd or z all over the place. If it is not yet pre-installed in your favourite *NIX, then grab it via your favourite package manager.
$ brew install tree # pacman -S tree # apt-get install tree
In its most basic form, you simply type $ tree
to print the current folder’s structure.
Personally, I prefer to spice it up just a little bit, adding some flags to print human readable filesizes, hidden files, and a nice total sizecount: $ tree -ah --du
.
And that is about all I have to tell you about tree. It’s really convenient to grep its output, it gives you an awesome representation of the filesystem, and I’m sure you’ll love it from the first moment.
That concludes my list of command line tools that you won’t think will change you live, but sure enough after some time you won’t imagine yourself not using them. In fact, you’ll likely curse every time you use a command-line-muggle’s computer without these great tools installed. What are the hidden gems of your command-line-fu? Share your favorite command line utilities in the comments below, I really would like to learn new tricks.
Working on the command line will make you more productive, even on Windows!
There’s an age-old discussion between the usability and friendliness of GUI programs, versus the simplicity and productivity of CLI ones. But this is not a holy war I intend to trigger or fuel. In the past, RebelLabs has discussed built-in JDK tools and received amazing feedback, so I feel an urge to share more non-JDK command line tools which I simply couldn’t live without.
I do firmly believe every developer who’s worth their salt should have at least some notion of how to work with the command line, if only because some tools only exist in CLI variants. Plus, because geek++!
All other nuances that people pour words over, like the choice of operating system (OSX of course, they have beautiful aluminum cases), your favorite shell (really it should be ZSH), or the preference of Vim over Emacs (unless you have more fingers than usual) are much less relevant. OK, that was a little flamewar-like, but I promise that will be the last of it!
So my advice would be that you should learn how to use tools at the command line, as it will have a positive impact on your happiness and productivity at least for half a century!
Anyway, in this post I want to share with you four-five lesser-known yet pretty awesome command line gems. As an added bonus I will also advise the proper way to use shell under Windows, which is a pretty valuable bit of knowledge in itself.
The reason I wanted to write this post in the first place is because I really enjoy using these tools myself, and want to learn about other command line tools that I don’t yet know about. So please, awesome reader, leave me a comment with your favourite CLI tools — that’d be grand! Now, assuming we all have a nice, workable shell, let’s go over some neat command line tools that are worth hearing about.
The first on my list is a tool called HTTPie. Fear not, this tool has nothing to do with Internet Explorer, fortunately. In essence HTTPie is a cURL wrapper, the utility that performs HTTP requests from the command line. HTTPie adds nice features like auto-formatting and intelligent colour highlighting to the output making it much more readable and useful to the user. Additionally, it takes a very human-centric approach to its execution, not asking you to remember obscure flags and options. To perform an HTTP GET, you simply run http, to post you http POST, what can be easier or more beautiful?
Almost all command line tools are conveniently packaged for installation. HTTPie is no exception, to install it, run the following command.
brew install httpie
pip install --upgrade httpie
I personally use HTTPie a lot when developing a REST API, as it allows me to very simply query the API, returning nicely structured, legible data. Without doubt this tool saves me serious work and frustration. Luckily the usage does not stop at just REST APIs. Generally speaking, all interactions over HTTP, whether it’s inputting or outputting data, can be done in a very human-readable format.
I’d encourage you to take a look at the website, spend the 10 seconds it takes to install and give it a go yourself. Try to get the source of any website and be amazed by the output.
Protip: Combine the HTTPie greatness with jq for command line JSON manipulation or pup for HTML parsing and you’ll be unstoppable!
At ZeroTurnaround I am blessed to work with Mercurial, a very nice and easy to use VCS. On OSX the excellent GUI program SourceTree makes working with Mercurial an absolute breeze, even with the more complex stuff. Unfortunately I like to keep the number of programs/tabs/windows I have open to an absolute minimum. Since I always have a terminal window opened it makes sense to use the CLI.
All was fine and well apart from one single pitfall in my setup. This was a feature I could barely go without: side-by-side diffs. Introducing icdiff. Of all the tools I use each day, this is the one I most appreciate. Let’s take a look at a screenshot:
By itself, icdiff is an intelligent Python script, smart at detecting which of the differences are modifications, additions or deletions. The excellent colour highlighting in the tool makes it easy to distinguish between the three types of differences mentioned.
To get going with icdiff, do the following:
brew install icdiff
When you couple icdiff with a VCS such as Mercurial, you’ll see it really shine. To fully integrate it, you’ll need to complete two more configuration steps, already documented here. The gist of the instructions is to first add a wrapping script that allows the one-by-one file diff of icdiff to operate on entire directories. Secondly you need to config your VCS to actually use icdiff. The link above shows the details of configuring it for Mercurial, but porting this to Git shouldn’t be so hard.
In the spirit of “practice what you preach” I set out to write this entire blogpost via a CLI. Most of the work was done using MacVim, in iTerm2 on OSX. All of the text was written and formatted using standard MarkDown syntax. The only issue to arise here is that it’s pretty difficult sometimes to accurately guess how your eventual text will come out.
This is where the next tool comes in: Pandoc. A program so powerful and versatile it’s a wonder it was GPL’d in the first place. Let’s take a look at how we might use it.
pandoc -f markdown -t html blogpost.md > blogpost.html
Think of a markup format, any markup format. The chances are, Pandoc can convert it from one format to any other. For example, I’m writing this blogpost in Vim and use Pandoc to convert it from MarkDown into HTML, to actually see the final result. It’s a nice thing, needing only my terminal and a browser, rather than being tied to a particular online platform, fully standalone and offline.
Don’t let yourself be limited by simple formats like MarkDown though, give it some docx files, or perhaps some LaTeX. Export into PDF, epub, let it handle and format your citations. The possibilities are endless.
Once again brew install pandoc
does the trick. Did I mention I really like Homebrew? Maybe that should have made my tool list! Anyway, you get the gist of what that does!
The next tool in this post is actually a collection of nifty tools that didn’t make it into coreutils:Moreutils. It should be obtainable under moreutils in about any distro you can think of. OSX users can get all this goodness by brewing it like I did throughout this post:
brew install moreutils
Here are a list of the included programs with short descriptions:
As the maintainer hints himself sponge is perhaps the most useful tool, in that you can easily sponge up standard input into a file. However, it is not difficult to see the advantages of some of the other commands such as chronic, parallel and pee.
My personal favourite though, and the ultimate reason to include this collection, is without doubtvipe.
You can literally intercept your data as it moves from command to command through the pipe. Even though this is not a useful tool in your scripts, it can be extremely helpful when running commands interactively. Instead of giving you a useful example I will leave you with a modified fortune!
These days the Windows OS comes packaged with two different shells: its classic command line, and PowerShell. Let’s completely ignore those and have a look at the proper way or running command line tools under Windows: Babun! The reason this project is amazingly awesome is because it actually brings all the goodness of the \*NIX command line into Windows in a completely pre-configured no-nonsense manner.
Moreover, its default shell is my beloved ZSH, though it can very easily be changed to use Bash, if that’s your cup of tea. With ZSH it also packages the highly popular oh-my-zsh framework, which combines all the benefits of ZSH with no config whatsoever thanks to some very sane defaults and an impressive plugin system.
By default Babun is loaded with more applications than any sane developer may ever need, and is thus a rather solid 728 MBs(!) when expanded. In return you get essentials like Vim pre-installed and ready to go!
Under the hood Babun is basically a fancy wrapper around Cygwin. If you already have a Cygwin install you can seamlessly re-use that one. Otherwise it will default to its own packaged Cygwin binaries, and supply you with access to those.
Some more points of interest are that Babun provides its own package manager, which again wraps around Cygwin’s, and an update mechanism both for itself and for oh-my-zsh. The best thing is that no actual installation is required, nor is the usual requirement of admin rights necessary, so for those people on a locked down PC this may be just the thing they need!
I hope this small selection of tools gave you at least one new cool toy to play with. As for me, it seems it is time to look at command line browsers before writing a following blogpost, to fully ditch the world of the GUI!
By all means fire up any comments or suggestions that you have, and let’s get some tool-sharing going on. If you just want to chat just ping RebelLabs on Twitter: @ZeroTurnaround, they are pretty chatty, but great smart people.
一Q下载及安装
站长癄下蝲站最新版下蝲地址Qhttp://down.zzbaike.com/download/KeePass–1257.htmlQ下载安装包解压后双d装文件根据安装向导就可以安装?br style="padding: 0px; margin: 0px;" />
选择I accept意思也是我同意,然后nextQ下一步)Q根据提Clnext可以安装成功?br style="padding: 0px; margin: 0px;" />软g是英文的Q安装好之后我们看到界面仍旧都是英文的,我们可以去http://keepass.info/translations.htmlQ中下蝲体中文插件复制放到安装目录下Q运行Y?#8220;KeePass”Q点?#8220;View”菜单?#8220;Change Language”命oQ选择“体中?#8221;重新启动E序卛_?/p>
二:使用软g
l过上面的步骤,我们q回到桌面双击keepass的快捷键Q就可以看到软g的语a已经变成中文的了
q样可以方便我们的使用了?br style="padding: 0px; margin: 0px;" />如果是第一ơ用,我们首先的是要创建数据库Q也是存放密码的数据库QKeePass会把你的所有密码存储在q个数据库中?br style="padding: 0px; margin: 0px;" />单击菜单上的“文g—新徏”Q选择数据库存攄路径
选择一个\径来保存我们的数据库Q然后点M存,
q里需要填入数据库理密码Qƈ要确认密码,我们同时要勾选上密匙文gQƈ选择密钥的保存位|(可以选择不用密钥Q。这样将来在开启数据库时就?#8220;d?#8221;?#8220;密钥文g”同时具备才行。输入完毕后点击“定”然后点击创徏
鼠标在黑色区域划q生成的密码位数在下方可以很清楚的看刎ͼ然后点击定
在这里描q或者不描述都可以,点击定后就q入ȝ口ƈ可以看到一条示例记录,点击CZ记录在下方可以看到网址和密码ƈ且也创徏旉?a style="padding: 0px; margin: 0px; color: #aa752a;">
ȝ口的左边是密码群l,各个组又可建立子群l。右Ҏ你的密码记录。密码记录收U于不同的密码群l中。你可以使用Keepass默认的密码群l,或删除它们,创徏自己的密码组?/p>
在主H口双单击右键Q选择“d记录…”Q就可以~辑你的记录了:记录标题Q用户名Q网址Q密码,备注{。可以空着不填。确认后完成了一条记录了Q在ȝ口右边的子窗口中看到刚才新增的密码条目?br style="padding: 0px; margin: 0px;" />
当你再次使用q个文gӞ选中该条记录Q在记录上右击鼠标就可以真正使用它了。你可以用户名拯后,可以在其它的Q何Y件中_脓了,q可以将用户名拖攑ֈ其它H口中。最后,一定要C保存密码Q点?#8220;文g->保存”Q或工具栏上的保存按钮?/p>
提示Q随着数据库里的记录数目的逐步增多Q通过“~辑”菜单中的“在数据库中查?#8221;?#8220;在此组内查?#8221;命o可以q速的扑ֈ要查的信息。另外,我们可以把数据库导出为TXT、HTML、XML、CSV{格式,导入CSV、TXT、KeePass数据库等格式的文件?/p>
三:数据库的配置
点击“文g->数据库设|?#8230;”Q在弹出的窗口的选择“安全”按钮创徏一个加密算法,q设|密钥的加密ơ数Q如果选择生成密钥的话Q。通常加密ơ数的数量辑ֈ10万,也就_了?br style="padding: 0px; margin: 0px;" />
四:Keepass数据的备?br style="padding: 0px; margin: 0px;" />首先要备份KeePass.exe所在目录中的KeePass.ini文g。其ơ,备䆾你所保存的密码数据库文gQ?.kdbQ。如果你生在了密钥,q要保存密钥文g。以上文件打包后Q可以放入多动存储装|中Q或攑օ|络I间?br style="padding: 0px; margin: 0px;" />提示Q如果用L密码记录l常变动Q那么相应的KeePass数据也要l常备䆾。保存好你的数据。尽你有数不清的密码,但只需看好一个KeePass数据备䆾可以了?br style="padding: 0px; margin: 0px;" />五:密码生成?br style="padding: 0px; margin: 0px;" />在添加记录时Q我们可以利用密码生成器来生成复杂的密码Q点?#8220;密码”右侧?#8220;生成”按钮Q调?#8220;密码生成?#8221;属性框Q然后,点击“定”按钮卛_自动生成随机密码。通过点击“***”按钮密码明文显C,清楚的看到由生成器所产生的字W串?br style="padding: 0px; margin: 0px;" />
六:Keepass常用讄
打开【工兗?>【选项…】,可以对Keepass作设|了?br style="padding: 0px; margin: 0px;" />
?#8220;安全”选项卡中勾上Q设定锁定主H口旉Q?00Q自p|适合的时_
自动清空剪脓板时_讄旉?U?br style="padding: 0px; margin: 0px;" />“高”选项卡中Ҏ需要勾上适合的选项?/p>
我们现在生活中各个方面都需要用到密码,|站Q邮,论坛Q银行卡{等Q用keepass可以方便的ؓ我们服务记录各种不同的密码,使我们的操作更加省时高效Q管理更方便安全?/p>
版权xQ?/strong> 葫芦博客(www.huluboke.com )专栏作家原创
原文地址 http://www.huluboke.com/keepass-jiaocheng/转蝲请保留本版权信息
12306 订票助手 是款 Chrome 扩展Q用来对 12306.cn |址q行自动dQ自动查询,自动重试订单。@Appinn
火R四q发么,好久没发现程序员如此热情?#8230;
q款工具比较适合d的技术宅了,希望今天介绍q不太晚,Ҏ订票 12 天来看,目前Q??0日)已经可以订到1?1日的了Q距L节仅一天,基本上是攑ց的开始的最后日子了?/p>
12306 订票助手 使用前提Q须使用 Chrome 览器,以及安装 UserScriptQ然后打开 https://dynamic.12306.cn/otsweb/ 开始订?/p>
上图试登陆78ơ后成功Q而下囑ֈ开始刷?#8230;
L成功会蓝色通知以及声音提示Q此时点击预订按钮,可以进入自动提交订单页面,h意正填写实名制火R坐车h信息Q自动提及后q接到付款阶段Q无认选项。作者提供了详尽的步骤说明可以参考?/p>
雄狮已经出笼Q想必绝大部?Mac 用户都已l升U到 Lion pȝ了,虽然用户以及各大媒体都对q款操作pȝ的评价很高,但不可能做到100Q完,臛_不可能做到对每一个h来说都很完美Q难免会有一些习惯性问题和自己不了解的功能。TechCrunch ?GREG KUMPARAK 同学今天l我?a style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-style: inherit; font-family: inherit; vertical-align: baseline; text-decoration: none; color: #3399cc; ">整理?/a>Mac OS X Lion 中的九个你应该知道的东西Q这里分享给大家Q?/p>
好多人都在反应这个问题,说刚升完系l之后的几个时卡的不行Q而且发热也很严重Q神奇的是过几个时之后自己好了。吭Q你说这是ؓ什么呢Q原来,Lion W一ơ启动之后就会自己重新烦引你盘上的数据Q以方便你以后在 Spotlight 里快速搜索。由于徏立烦引这工作很耗资源,所以你会感觉又慢又热?/p>
大家不妨升?Lion 之后出M息一会儿Q呼吸呼吸新鲜空气?/p>
q个功能真是帅的一塌糊涂,?PDF 上竟然可以加上自׃手写的签名,对于每天都要{־多字的领导来说非常有用。用方法很单:
随便打开一?PDF 文档Q用预览打开Q默认)Q点?#8220;昄注解工具?#8221;按钮Q然后点?#8220;{”
按钮Q在下拉菜单中选择 创徏来自“内徏 iSight”的签名,之后你会发现摄像头已l开始拍你了。现在,你的签名写在一张白U怸Q对着摄像_你会从右边看到摄像头自动识别你的{Q完成后?#8220;接受”可以了?/p>
要在 PDF 里插入签名的时候直接点?#8220;{”按钮Q然后用鼠标选择你要插入的位|即可?/p>
q一Ҏ们在?a style="margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 0px; padding-top: 0px; padding-right: 0px; padding-bottom: 0px; padding-left: 0px; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; border-style: initial; border-color: initial; border-image: initial; outline-width: 0px; outline-style: initial; outline-color: initial; font-style: inherit; font-family: inherit; vertical-align: baseline; text-decoration: none; color: #3399cc; ">解决 Lion pȝ中鼠?触摸板反向滚动的问题》一文中已经说过了,׃多说了,其实Ҏq个没反Q只是咱们习惯用“反向”滚动了,Lion 中的滚动方向才是真正?#8220;自然”滚动方向呢,?iOS 里用手触摸的滚动方向一栗?/p>
使用之前 Mac OS X pȝ的同学都知道 Dock 栏的应用E序中,如果是正在运行的应用E序Q那么它下面会有一个白点,其实升?Lion 之后也有。但有些同学发现没有q个白点了,马情况呢?因ؓ——你是全新安装?LionQ或者说是新买的一台直接预装了 Lion 的电脑,比如最新的 Macbook Air 以及 Mac MiniQ,而不是从10.6.8升的?/p>
没有q个白点很不习惯Q因为^时我们能够在 Dock 栏很方便看到有哪些程序在q行Q现在不行了。那p己动手把“白点”昄打开吧:pȝ偏好讄——Dock——昄已打开的应用程序指C灯?/p>
虽然 Lion pȝ是最新的Q但你还是应该检查一下是否有其他应用E序更新Q比如最q?iTunes、iLife、iWOrk {都有专门针?Mac OS X Lion 的更斎ͼ所以装完系l之后还是记的点一下左上角的W号——软g更新Q检查看看有没有需要更新的应用?/p>
Lion ?Mission Control 是一个很的功能Q但是每ơ打开 Mission Control 左上角都昄的是 DashboardQ用双指切换应用程序的时候,切换到最左边也会昄 DashboardQ也是?Dashboard 是占用一个单?Space 的,?Dashboard 上的那些工具其实ƈ不实用,不实用的东西我们当然要干掉它?/p>
Ҏ很简单:pȝ偏好讄——Mission Control——L“?Dashboard 昄为空?#8221;前面的复选框?/p>
Mac 很早之前已l有?Filevault q一实时盘加密工具Q但很不好用Q稍微一有问题你的所有数据就没了。但?Lion 中这一功能得到了完完全全的重新开发,基本上除了名字还和以前一样之外,功能、稳定性、速度、安全性等斚w都比以前好的不是一点半点,如果你对数据的保密要求非帔R的话Q再l?Filevault 一ơ机会吧?/p>
pȝ偏好讄——安全与隐U?#8212;—FilevaultQ你懂的?/p>
大家可以直接打开“pȝ偏好讄”——触摸?鼠标学习q些新手势,或者修Ҏ势的定义?/p>
?iOS 上借鉴q来的一个功能,虽然理念很好Q但仍然不好用,而且׃都不是三岁小孩了Q输错的情况q是很少出现Q中文错别字又纠正不了)Q所以还是关了吧Q系l偏好设|?#8212;—语言与文?#8212;—文本Q去?#8220;自动U正拼写”前面的复选框?/p>
怿你掌握以?点之后,Mac OS X Lion 在你手中׃非常听话了,如果你还有什么可以分享给我们的,可以在文章评论区里脓出来?/p>
Selenium RC是一ƾ测试工P允许你ؓweb应用~写自动化的用户接口试Q支持Q何程序设计语a、Q何HTTP站点以及ML览器。它使用Selenium CoreQ这是个利用JavaScript执行自动览器Q务的库。Selenium试直接q行于浏览器中,像真实做的那样。这些测试既可用?em>验收试Q通过在集成系l上执行更高U的试而不是只独立地测试系l的各个单元Q,又可用于览器兼Ҏ测?/em>Q通过试不同操作pȝ和浏览器上的web应用Q?/p> 我看看下Selenium RC是如何安装的Q?/p> 现在我们可以利用它的客户/服务器协议向Selenium RC服务器发送命令了?/p>server/selenium-server.jar
?code>/usr/local/binQ例如)?/li>java -jar /usr/local/bin/selenium-server.jar
启动Selenium RC服务器?/li>
PHPUnit_Extensions_SeleniumTestCase
试用例扩展同Selenium RC通话的客?服务器协议实Cؓ专门用于web试的断aҎ?/p>
范例 19.1昄如何试http://www.example.com/
站点?code><title>元素的内宏V?/p>
范例 19.1: PHPUnit_Extensions_SeleniumTestCase使用举例
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
protected function setUp()
{
$this->setBrowser('*firefox /usr/lib/firefox/firefox-bin');
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->open('http://www.example.com/');
$this->assertTitleEquals('Example Web Page');
}
}
?>
不同?code>PHPUnit_Framework_TestCasec,扩展?code>PHPUnit_Extensions_SeleniumTestCase的测试用例类必须提供setUp()
Ҏ。该Ҏ用于配置Selenium RC会话。可用于此的Ҏ列表?a href="file:///F:/data2/PHPUnit_Pocket_Guide_-_v32/index_cn.html#selenium.seleniumtestcase.tables.seleniumrc-api.setup" title="Table 19.1. Selenium RC API: Setup" style="text-decoration: underline; color: #0044b6; ">?19.1?/p>
?19.1. Selenium RC APIQ装?/strong>
Ҏ | 含义 |
---|---|
void setBrowser(string $browser) | Selenium RC服务器用的览器?/td> |
void setBrowserUrl(string $browserUrl) | 讄用于试的基址URL?/td> |
void setHost(string $host) | 讄q接到Selenium RC服务器的L名?/td> |
void setPort(int $port) | 讄q接到Selenium RC服务器的端口受?/td> |
void setTimeout(int $timeout) | 讄q接到Selenium RC服务器的时旉?/td> |
void setSleep(int $seconds) | 讄Selenium RC客户端向Selenium RC服务器发送动作指令之间睡眠的U数?/td> |
你也可以使用一l浏览器q行每一个测试:在你的测试用例类中声明一个名?code>$browsers?code>public static数组代替使用setBrowser()
讄一个浏览器。该数组中的每一w描述一个浏览器配置。这些浏览器中的每一个都能被不同的Selenium RC服务器接待:
范例 19.2: 讄多浏览器配置
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class WebTest extends PHPUnit_Extensions_SeleniumTestCase
{
public static $browsers = array(
array(
'name' => 'Firefox on Linux',
'browser' => '*firefox /usr/lib/firefox/firefox-bin',
'host' => 'my.linux.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Safari on MacOS X',
'browser' => '*safari',
'host' => 'my.macosx.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Safari on Windows XP',
'browser' => '*custom C:\Program Files\Safari\Safari.exe -url',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
),
array(
'name' => 'Internet Explorer on Windows XP',
'browser' => '*iexplore',
'host' => 'my.windowsxp.box',
'port' => 4444,
'timeout' => 30000,
)
);
protected function setUp()
{
$this->setBrowserUrl('http://www.example.com/');
}
public function testTitle()
{
$this->open('http://www.example.com/');
$this->assertTitleEquals('Example Web Page');
}
}
?>
PHPUnit_Extensions_SeleniumTestCase
能够攉试l由Seleniumq行时的代码覆盖率信息:
PHPUnit/Extensions/SeleniumTestCase/phpunit_coverage.php
C的web服务器的文g根目录中?/li>php.ini
配置文g中,配置PHPUnit/Extensions/SeleniumTestCase/prepend.php
?code>PHPUnit/Extensions/SeleniumTestCase/append.php分别作ؓauto_prepend_file
?code>auto_append_file?/li>PHPUnit_Extensions_SeleniumTestCase
的测试用例类中,使用protected $coverageScriptUrl = 'http://host/phpunit_coverage.php';
配置用于phpunit_coverage.php
脚本的URL?/li>?19.2列出PHPUnit_Extensions_SeleniumTestCase
提供的各U断aҎ?/p>
?19.2. 断言
断言 | 含义 |
---|---|
void assertAlertPresent() | 如果不存在警告(对话框)则报错?/td> |
void assertNoAlertPresent() | 如果存在警告Q对话框Q则报错?/td> |
void assertChecked(string $locator) | 如果$locator 标识的元素未选中则报错?/td> |
void assertNotChecked(string $locator) | 如果$locator 标识的元素被选中则报错?/td> |
void assertConfirmationPresent() | 如果不存在确认(对话框)则报错?/td> |
void assertNoConfirmationPresent() | 如果存在认Q对话框Q则报错?/td> |
void assertEditable(string $locator) | 如果$locator 标识的元素不可编辑则报错?/td> |
void assertNotEditable(string $locator) | 如果$locator 标识的元素可~辑则报错?/td> |
void assertElementValueEquals(string $locator, string $text) | 如果$locator 标识的元素的g{于l定?code>$text则报错?/td> |
void assertElementValueNotEquals(string $locator, string $text) | 如果$locator 标识的元素的值等于给定的$text 则报错?/td> |
void assertElementContainsText(string $locator, string $text) | 如果$locator 标识的元素不含给定的$text 则报错?/td> |
void assertElementNotContainsText(string $locator, string $text) | 如果$locator 标识的元素包含给定的$text 则报错?/td> |
void assertElementPresent(string $locator) | 如果$locator 标识的元素不存在则报错?/td> |
void assertElementNotPresent(string $locator) | 如果$locator 标识的元素存在则报错?/td> |
void assertLocationEquals(string $location) | 如果当前位置QlocationQ不{于l定?code>$location则报错?/td> |
void assertLocationNotEquals(string $location) | 如果当前位置QlocationQ等于给定的$location 则报错?/td> |
void assertPromptPresent() | 如果不存在提C(对话框)则报错?/td> |
void assertNoPromptPresent() | 如果存在提示Q对话框Q则报错?/td> |
void assertSelectHasOption(string $selectLocator, string $option) | 如果l定的选项不可用则报错?/td> |
void assertSelectNotHasOption(string $selectLocator, string $option) | 如果l定的选项可用则报错?/td> |
void assertSelected($selectLocator, $option) | 如果l定的标{未选中则报错?/td> |
void assertNotSelected($selectLocator, $option) | 如果l定的标{被选中则报错?/td> |
void assertIsSelected(string $selectLocator, string $value) | 如果l定的值未选中则报错?/td> |
void assertIsNotSelected(string $selectLocator, string $value) | 如果l定的D选中则报错?/td> |
void assertSomethingSelected(string $selectLocator) | 如果$selectLocator 标识的选项未选中则报错?/td> |
void assertNothingSelected(string $selectLocator) | 如果$selectLocator 标识的选项被选中则报错?/td> |
void assertTextPresent(string $pattern) | 如果l定?code>$pattern不存在则报错?/td> |
void assertTextNotPresent(string $pattern) | 如果l定?code>$pattern存在则报错?/td> |
void assertTitleEquals(string $title) | 如果当前标题不等于给定的$title 则报错?/td> |
void assertTitleNotEquals(string $title) | 如果当前标题{于l定?code>$title则报错?/td> |
void assertVisible(string $locator) | 如果$locator 标识的元素不可见则报错?/td> |
void assertNotVisible(string $locator) | 如果$locator 标识的元素可见则报错?/td> |
?19.3昄PHPUnit_Extensions_SeleniumTestCase
的两个模板方法:
?19.3. 模板Ҏ
Ҏ | 含义 |
---|---|
void defaultAssertions() | 重写以执行一个测试用例中的所有测试共享的断言。该Ҏ在发送给Selenium RC服务器的每个命o之后被调用?/td> |
void sharedAssertions() | 重写以执行一个测试用例中的所有测试共享的断言。该Ҏ在一个测试执行结束之前被调用?/td> |
h?a target="_top" style="text-decoration: underline; color: #0044b6; ">Selenium Core的文?/a>获得关于可用的命令以及如何用的参考?/p>
利用runSelenese($filename)
ҎQ你也能从它的Selenese/HTML规范q行一个Selenium试。此外,利用静态属?code>$seleneseDirectoryQ你能从一个包含Selenese/HTML文g的目录自动地创徏试对象。指定的目录被递归地搜索预期包含Selenese/HTML?code>.htm文g?nbsp;范例 19.3昄一个例子?/p>
范例 19.3: 使用Selenese/HTML文g的目录作为测?/strong>
<?php
require_once 'PHPUnit/Extensions/SeleniumTestCase.php';
class SeleneseTests extends PHPUnit_Extensions_SeleniumTestCase
{
public static $seleneseDirectory = '/path/to/files';
}
?>
最Ҏ被一些h搞错地方Q就是时间设|问题,所以碰到这U情况,请首先检查你的电?font color="#3366ff">旉讄是否正确Q如果不正确导致助理从你的电脑上取到的时候,已经不在服务器发送给助理的有效时间范围内Q请你核对你的时间设|是否正。将“自动与internet旉服务器同?/font>”取消后问题消失。如果还是不行,L下面?/font>
========================================================================
一、XPpȝ下IE7.0 讉Khttps站点故障排除Q?/strong>
默认情况QXPpȝ下通过XP版本的IE 7 览器,讉Khttps加密的站炚w会出现这个提C,q个是IE7阅览器的提示Q必dơ点“l箋览此网站(不推荐)”才能查看面信息?/font>每次讉KHttps?font color="#000000">炚w需要重复点击,在操作上带来很大的麻烦。下面我们就通过安装证书步骤来解x问题?
W一步:当我们用IE7览Https站点后会在地址栏右边出C个红色的“证书错误”的提C,我们点该U色按钮Q然后选择“查看证书”?
W二步:在打开?#8220;查看证书”H口中的“常规”标签中点右下角的“安装证书”按钮?
W三步:出现“证书导入向导”后点“下一?/font>”按钮l箋?/font>
W四步:选择证书存储的系l区域,通过“览”按钮讄证书保存ؓ“受信ȝ根证书颁发机?/font>”?
W五步:之后在安全警告窗口中选择“?/font>”按钮来安装该证书?/font>
W六步:讄完毕后我们再ơ访问该https站点׃会出CQ何问题,也不会再出现q个错误提示了?/font>
========================================================================
二、Vistapȝ下IE7.0 讉Khttps站点故障排除Q?/strong>
在Vistapȝ下用IE7览器访问https站点也会出现q个错误提示Q但是他的解x骤却和XP下IE7有很大区别。这是因为在Vistapȝ中IE7讉Khttps证书查看里没有安装的提示Q错误信息提C?#8220;׃CA根证书不在受信Q的根证书颁发机构存储ZQ所以他不受信Q?/font>
那么该如何解军_Q我是至今还没有发现可以通过调整IE7览器的讄来解x问题Q不q可以通过证书导入来解冟?/font>
W一步:首先打开IE7览器,然后通过“工具->internet选项”打开属性设|窗口,q择“内容”标签Q直接点“证书”标签?/font>
W二步:选择要安装的证书cd时点“受信ȝ根证书颁发机?/font>”Q接下来点左下角?#8220;导入”按钮?
W三步:q时需要我们在“要导入的文g”讄H口中找到该|站的证书文件。至于这个证书文件如何获得,W者的Ҏ是通过在别的浏览器Q例如IE 6或XPpȝIE 7Q中该|站对应的证书以文g的Ş式导出即可,接下来回到Vistapȝ中导入此文g卛_?/font>
W四步:在证书存储设|处和上面介l的Ҏ一P选择所有的证书攑օ下列存储——受信ȝ根证书颁发机构?/font>
W五步:在安装该证书的窗口中?#8220;?/font>”按钮卛_?/font>
W六步:所有工作完成后会出现导入成功的提示Q以后我们再讉Khttps加密的站点就不会出现上面的错误提CZ?/font>
主要讲述在windows下apache配置SSL以实现http转换?a style="color: rgb(51,51,51); word-break: break-all; line-height: normal! important; text-decoration: underline" onclick="javascript:tagshow(event, 'https');" href="javascript:;" target="_self">https
SSL: SSl是ؓHttp传输提供安全的协议,通过证书认证来确保客L和网站服务器之间的数据是安全。也是说在SSL下http传输是安全的Q我们成为https.
q程Q?/p>
步骤一Q安装apache,使其支持SSL,q安装php
1.安装配有SSL模块的apache,apache_2.2.8-win32-x86-openssl-0.9.8g
2.配置apache以支持SSL:打开apache的配|文件conf/httpd.conf
1)LoadModule ssl_module modules/mod_ssl.so
Include conf/extra/httpd-ssl.conf
L两行前面?
2)注意修改httpd-ssl.conf 文g里的两个字段Q?br style="word-break: break-all; line-height: normal! important" /> SSLCertificateFile "C:/Apache2.2/conf/server.crt"
SSLCertificateKeyFile "C:/Apache2.2/conf/server.key"
3.安装php,整合apache和Php(? //此步可以省略Q如果你不需要PHP的话?br style="word-break: break-all; line-height: normal! important" /> Z面你所生成的证书和密钥地址?/p>
步骤二:为网站服务器生成证书及私钥文?br style="word-break: break-all; line-height: normal! important" />
1. 生成服务器的U钥
q入命o?
D:\local\apache2\bin\openssl genrsa -out server.key 1024
在当前目录下生成了一个server.key生成{v甌
2. 生成{v甌
D:\local\apache2\bin>openssl req -new –out server.csr -key server.key -config ..\conf\openssl.cnf
此时生成{v文gserver.csr.
步骤三:通过CA为网站服务器{v证书
1.生成CAU钥
D:\local\apache2\bin\openssl genrsa -out ca.key 1024
多出ca.key文g
2.利用CA的私钥生CA的自{v证书
D:\local\apache2\bin\openssl req -new -x509 -days 365 -key ca.key -out ca.crt -config ..\conf\openssl.cnf
此时需要输入一些信息,注意Common Name为服务器域名Q如果在本机Qؓ本机IP?br style="word-break: break-all; line-height: normal! important" /> 3.CA为网站服务器{v证书
D:\local\apache2\bin\openssl ca -in server.csr -out server.crt -cert ca.crt -keyfile ca.key -config ..\conf\openssl.cnf
但,此时会报错:
于是在在当前目录创徏demoCAQ里面创Z下文Ӟindex.txt,serial内容?1Q?a style="color: rgb(51,51,51); word-break: break-all; line-height: normal! important; text-decoration: underline" onclick="javascript:tagshow(event, '%C6%E4%CB%FB');" href="javascript:;" target="_self">其他为空,以及文g夹newcert.再执行一遍,卛_生成server.crt文g
步骤四:然后?nbsp; server.crt,server.key复制到apache的conf文g夹下Q重启apache
步骤五:讉Khttp://localhostx持https
不过׃Q我们的CA不是q三方机构颁发的,而是我们自己颁发的,所以,IE讉K的时候,会显C,q个证书不是由Trused CA Authenticator颁发Q告诉我们可能有安全隐患
1、打开注册表,扑ֈ
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell 主键(?Q如果没有新Z个)Q?br />
2、单击shellq个主键Q在下再新徏一个名?notepad 的主键,在右面的H口中,把默认项的值改成:用记事本打开 或者其他你喜欢的字栗?br />
3、再在notepad主键下新Z?command 主键。在右面的窗口中Q把默认的值改成:
notepad %1 Q注意notepad?W号之间要空一|关闭注册表?br />
现在在Q意一个文件上单击鼠标右键有“用记事本打开”q一功能了。经体验是一个很好的Ҏ。当然用其它软g也可dq一功能。(攉学习Q?/p>
另可以:打开注册表编辑器Q找C面的键|HKEY_CLASSES_ROOT\*Q接着新徏一个名?shell的子,接着再它的下Ҏ建名?#8220;Notepad”Q然后在右侧H口中将光认值改?#8220;使用C本打开”Q最后在“Notepad”下新徏名ؓ“command”的子,在右侧窗口中其值改为:notepad.exe %1可以了?/p>
保存一下内容ؓ*.regq行卛_!
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell]
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\playboyjin]
@="用记事本打开"
[HKEY_LOCAL_MACHINE\SOFTWARE\Classes\*\shell\playboyjin\command]
@="notepad.exe \"%1\""
如何d鼠标右键DOS命o
A:(1)打开注册表编辑器?(2)打开HKEY_LOCAL_MACHINE\Software\classes\directory\shell主键q中它。在右侧H口中新Z个项Q命名ؓCommandPromptQ然后把它的数值数据改为command?(3)在CommandPrompt下新Z个项Q命名ؓcommandQ改其数值数据ؓcmd /k cd %1Q退出OK了?(4)鼠标右键单击M文g夹,在弹出的菜单中,你就可以选择command命o了?/p>
B:保存下边的代码到一个记事本文gQƈ把扩展名改ؓ“.bat”Q执行一ơ这个文Ӟ以后没用了Q,找一个文件夹Q打开鼠标右键看看吧!
reg add "HKCR\*\shell\ms-dos" /ve /d ms-dos /f
reg add "HKCR\*\shell\ms-dos\command" /ve /d "cmd.exe /k cd %%1" /f
reg add "HKCR\Folder\shell\ms-dos" /ve /d ms-dos /f
reg add "HKCR\Folder\shell\ms-dos\command" /ve /d "cmd.exe /k cd %%1" /f
本文来自CSDN博客Q{载请标明出处Qhttp://blog.csdn.net/bhsky/archive/2009/02/02/3858883.aspx
@echo off echo proj 本地试环境 echo. c: cd \ if not exist proj-test\con md proj-test if exist proj-test\hosts.bak goto backup_exists echo 正在创徏备䆾…… cd \windows\system32\drivers\etc copy /y hosts \proj-test\hosts.bak > null echo 完成Q? echo. goto backup_start :backup_exists echo 备䆾文g已经存在Q无需备䆾? echo. :backup_start echo 正在写入试数据…… echo 127.0.0.1 localhost > hosts echo 192.168.3.170 proj.com >> hosts echo 192.168.3.170 www.proj.com >> hosts echo 192.168.3.170 pics.proj.com >> hosts echo 192.168.3.170 files.proj.com >> hosts echo 完成Q? echo. echo 建立 proj 本地试环境完成。按L键退?#8230;… pause > null退出测试环境:
@echo off echo proj 本地试环境 echo. c: cd \ if not exist proj-test\hosts.bak goto backup_not_exists echo 正在q原备䆾…… copy /y \proj-test\hosts.bak \windows\system32\drivers\etc > null cd \windows\system32\drivers\etc if exist hosts del /q hosts ren hosts.bak hosts echo 完成Q? echo. echo 正在U除备䆾…… cd \ rmdir /s/q \proj-test\ echo 完成Q? echo. goto backup_done :backup_not_exists echo 备䆾文g不存在,无法恢复? echo. :backup_done echo 退?proj 本地试环境完成。按L键退?#8230;… pause > null
卸蝲服务Qsc delete serviceName
or check HKEY_LOCAL_MACHINESYSTEMCurrentControlSetServices
以上修改要重h器才能生?br />
另:
启动服务Qnet start serviceName 或sc start serviceName
停止服务Qnet stop serviceName 或sc stop serviceName
[SC命o 的参数可以配|指定的服务Q检索当前服务的状态,也可以停止和启动服务Q功能上cMNET STOP/START命oQ但SC速度更快且能停止更多的服务)。]