购买商品功能的测试代码—Selenium自动化测试指南(12)

发表于:2013-9-10 11:52

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:赵卓    来源:51Testing软件测试网

  运行结果如图7-21所示。

  

图7-21  执行结果

  7.2.3  购买商品功能的测试代码

  根据表7-3所示的测试用例,可以使用程序清单7-11至程序清单7-15对购买商品功能进行测试

  程序清单7-11  Selenium IDE代码

  程序清单7-12  Selenium 1 C#代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Selenium;
using System.Threading;
namespace ConsoleApplication3
{
class Program
{
static void Main(string[] args)
{
DefaultSelenium selenium = new DefaultSelenium("localhost", 4444, "*iexplore ", http://www.google.com);
selenium.Start();
//第1步
selenium.Open(http://www.360buy.com/product/152026.html);
Console.WriteLine("检查是否成功进入商品详细页面:{0}", "http://www.360buy. com/ product/152026.html" == selenium.GetLocation());
//第2步
String ItemName = selenium.GetText("//div[@id='name']");
selenium.Click("link=加入购物车");
selenium.WaitForPageToLoad("30000");
Console.WriteLine("检查是否出现“商品已加入购物车”提示:{0}", selenium. IsTextPresent("商品已成功加入购物车!"));
//第3步
selenium.Click("link=继续购物");
Thread.Sleep(5000);
Console.WriteLine("返回之前的商品详细页面:{0}", "http://www.360buy. com/ product/152026.html" == selenium.GetLocation());
//第4步
selenium.GoBack();
Thread.Sleep(5000);
selenium.Click("link=去结算");
Thread.Sleep(7000);
Console.WriteLine("进入购物车结算页面:{0}", "我的购物车 - 京东商城" == selenium. GetTitle());
Console.WriteLine("显示之前添加的商品:{0}", selenium. IsTextPresent (ItemName));

//第5步
selenium.Click("link=去结算");
Thread.Sleep(7000);
Console.WriteLine("检查是否进入订单填写页面:{0}", "订单信息确认" == selenium. GetTitle());
selenium.Stop();
Console.ReadKey();
}
}
}

43/4<1234>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号