selenium C#下的zencart自动化测试(WFloginUrlPayment)环境4.0

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using OpenQA.Selenium;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.Support.UI;//引用命名空间

namespace WFloginUrl
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void btnSubmit_Click(object sender, EventArgs e)//按提交按钮
{
IWebDriver driver = new FirefoxDriver();
//IWebDriver driver = new ChromeDriver();
INavigation navigation = driver.Navigate();
navigation.GoToUrl(txtURL.Text + "/login.html");
//System.Threading.Thread.Sleep(5000);
driver.FindElement(By.Id("gender-male")).Click();
driver.FindElement(By.Id("firstname")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("lastname")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("street-address")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("suburb")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("city")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("state")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("postcode")).SendKeys("1859@qq.com");
driver.FindElement(By.Id("telephone")).SendKeys("1859@qq.com");
Random ran = new Random();
int RandKey = ran.Next(1,1999);
driver.FindElement(By.Id("email-address")).SendKeys("1859" + RandKey + "@qq.com");
IWebElement passwordnew = driver.FindElement(By.Id("password-new"));
passwordnew.SendKeys("1859@qq.com");
driver.FindElement(By.Id("password-confirm")).SendKeys("1859@qq.com");
//IWebElement buttonRow = driver.FindElement(By.ClassName("buttonRow forward"));
passwordnew.Submit();
lblOutput.Text = "<font color=red>注册成功,购买产品 . . .</font>";//显示进程信息
System.Threading.Thread.Sleep(2000);

navigation.GoToUrl(txtURL.Text+"/index.php?main_page=product_info&products_id=12");

new SelectElement(driver.FindElement(By.Id("attrib-1"))).SelectByIndex(2);//SelectByText("(US):6.5=(UK):4.5=(EUR):37");

driver.FindElement(By.XPath("//div[@id='cartAdd']/input[5]")).Click();
lblOutput.Text = "加入购物车成功,运费 . . .";
//cartAdd.Click();
driver.FindElement(By.XPath("//div[@class='buttonRow forward']//a/img")).Click();
//btnForward.Click();
//System.Threading.Thread.Sleep(2000);
driver.FindElement(By.XPath("//div[@class='buttonRow forward']/input")).Click();
lblOutput.Text = "付款 . . .";
//btnForward2.Click();
//driver.FindElement(By.CssSelector("div.buttonRow.forward > input[type=\"image\"]")).Click();
//driver.FindElement(By.CssSelector("#cartAdd > input[type=\"image\"]")).Click();
// ERROR: Caught exception [ERROR: Unsupported command [selectWindow | null | ]]
// ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
// ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=toolbox-panel-iframe-inspector | ]]
// ERROR: Caught exception [Error: locator strategy either id or name must be specified explicitly.]
new SelectElement(driver.FindElement(By.Id("Fristonecc-expires-month"))).SelectByText("02");
new SelectElement(driver.FindElement(By.Id("Fristonecc-expires-year"))).SelectByText("2016");
driver.FindElement(By.Id("Fristonecc-cardNo")).Clear();
driver.FindElement(By.Id("Fristonecc-cardNo")).SendKeys("4111111111111111");
driver.FindElement(By.Id("Fristonecc-cvv")).Clear();
driver.FindElement(By.Id("Fristonecc-cvv")).SendKeys("111");
driver.FindElement(By.Name("submitbtn")).Click();
System.Threading.Thread.Sleep(30000);
driver.Quit();

}
private void Form1_Load(object sender, EventArgs e)
{
txtURL.Text = "http://www.XXX.com";//文本框输入要测试的网址
}

}
}

上一篇:DateTimePicker控件为空 分类: WinForm 2014-04-15 09:46 239人阅读 评论(0) 收藏


下一篇:1038 Recover the Smallest Number (30 分)