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";//文本框输入要测试的网址
}


}
}

转载于:https://www.cnblogs.com/alex-13/p/4750355.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值