51Testing软件测试论坛

 找回密码
 (注-册)加入51Testing

QQ登录

只需一步,快速开始

微信登录,快人一步

手机号码,快捷登录

查看: 2128|回复: 2
打印 上一主题 下一主题

Tips :上传文件1

[复制链接]

该用户从未签到

跳转到指定楼层
1#
发表于 2010-8-13 15:06:07 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
File Upload Support

BrowserMob makes it possible for scripts to upload files as part of the browser automation. This means that if you need to run a performance or load test that uploads files (ie: user-contributed video), it is possible to do with BrowserMob.

To get started, we recommend first creating a Selenium script that uploads a local file on your company. You’ll note that when recording the script, Selenium will use the “type” command to set the value of the file upload field to the path where the file exists. Play back the script on your desktop to make sure it’s working perfectly.

Next, upload the Selenium script to BrowserMob. It will automatically start to validate and will most likely fail, since the the path referenced in the script (the one on your local desktop) does not exist on BrowserMob’s remote machines. This is OK and expected.

Once the script has been confirmed as “invalid”, click on the script name to edit the script. For our example, let’s assume it looks something like this:

var selenium = browserMob.openBrowser();

browserMob.beginTransaction();
browserMob.beginStep("Step 1");

selenium.open("http://example.com/video-upload");
selenium.type("description", "My home video");
selenium.type("file", "c:\foo.m4v");
selenium.clickAndWait("uploadBtn");

browserMob.endStep();
browserMob.endTransaction();

Now let’s edit the script slightly. Instead of using a hard-coded path for the file to upload, let’s use a BrowserMob API to get a path to a file that will soon be associated with the script:

var selenium = browserMob.openBrowser();

browserMob.beginTransaction();
browserMob.beginStep("Step 1");

// get the path for the file named foo.m4v
var filePath = browserMob.filePath("foo.m4v");

selenium.open("http://example.com/video-upload");
selenium.type("description", "My home video");
selenium.type("file", filePath);
selenium.clickAndWait("uploadBtn");

browserMob.endStep();
browserMob.endTransaction();

What is happening here is we’re now asking BrowserMob for the path to the file with the alias “foo.mp4″. As soon as you save this script, BrowserMob will recognize that you need to upload foo.mp4 and will ask you to do so:


Here you are given a list of all files you need to upload before the script is ready to be validated. The name of each file and the number of files in total is determined by each unique call to browserMob.filePath() in your script. In our example, there was one call with the parameter “foo.m4v”, which is why we were asked to upload one file.

Now when the script is validated or run during any real test, each file will be downloaded to a temporary location on the remote computer. Since the temporary location changes each time, the browserMob.filePath() function helps you dynamically determine the path based on a known alias (ie: foo.m4v). You can then use that path to set the value of the file upload field in the browser.
分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

该用户从未签到

2#
 楼主| 发表于 2010-8-13 15:07:43 | 只看该作者
上传文件2

selenium.type()
回复 支持 反对

使用道具 举报

该用户从未签到

3#
 楼主| 发表于 2010-8-13 15:08:28 | 只看该作者
回复 支持 反对

使用道具 举报

本版积分规则

关闭

站长推荐上一条 /1 下一条

小黑屋|手机版|Archiver|51Testing软件测试网 ( 沪ICP备05003035号 关于我们

GMT+8, 2024-11-22 10:11 , Processed in 0.087143 second(s), 27 queries .

Powered by Discuz! X3.2

© 2001-2024 Comsenz Inc.

快速回复 返回顶部 返回列表