Selenium 例子


sample

package come.goodhope.test.aboutpayStory;

import come.goodhope.test.FunctionalTestCase;

public class testpaymentcenter extends FunctionalTestCase {

    public void testpaymentcenter() throws Exception {
        selenium.open("https://localhost:21103/welcome.html");
        selenium.waitForPageToLoad("3000");
        assertEquals(selenium.getTitle(), "好望角-好望角钱包");
        // 好钱包首页
        clickAndWait("homeTab");
        assertEquals(selenium.getTitle(), "登录-好望角登录中心");
        selenium.type("username", "a@a.com");
        selenium.type("password", "a");
        clickAndWait("submit");
        assertTextPresent("账户安全用什么来保障?");
        // 充值
        clickAndWait("chargeTab");
        assertTextPresent("给本账户充值");
        selenium.click("ICBC");
        selenium.type("chargeAmount", "10");
        clickAndWait("charge");
        assertTextPresent("使用网上银行充值");
        clickAndWait("confirm");
        clickAndWait("Buy");
        assertTextPresent("充值成功!请查看钱包余额!");
        // 提现
        clickAndWait("withdrawMoneyTab");
        assertTextPresent("为了您银行帐户的安全,我们限制了每天最多转帐6次");
        selenium.type("bankAmount", "100");
        clickAndWait("//html/body/div[@id='layout']/div[@id='main']/div[@class='nlist']/form/div[@class='clr ctr']/strong/input");
        assertTextPresent("好望角转账手续费");
        // 用户支付密码已经设定
        selenium.type("paymentPassword", "111111");
        clickAndWait("submit");
        assertTextPresent("您提交的转账请求正在处理中,届时如果钱退回钱包,");
        // 给他人充值
        clickAndWait("anonymousChargeTab");
        assertTextPresent("给他人充值");
        selenium.click("CCB");
        selenium.type("chargeAmount", "100");
        selenium.type("userName", "a@a.com");
        selenium.type("userNameConfirm", "a@a.com");
        clickAndWait("charge");
        assertTextPresent("使用网上银行充值");
        clickAndWait("confirm");
        clickAndWait("Buy");
        assertTextPresent("充值成功!请查看钱包余额!");
        // 账户管理
        clickAndWait("accountManagementTab");
        selenium.click("chargeHistory");
        assertTextPresent("充值时间");
        clickAndWait("withdrawMoneyHistory");
        assertTextPresent("提现时间");
        clickAndWait("walletTransactionHistory");
        assertTextPresent("事件");
        clickAndWait("userBankAccount");
        assertTextPresent("已开通从钱包当中提现转账的功能。");
        clickAndWait("paymentPwdManagement");
        assertTextPresent("温馨提示");

        //返回好望角(这里有一个弹出新窗口的问题,所以写法跟其它的不太一样,selenium.browserbot.findElement()不是selenium自带的,是js里有的,所以用alt+/j是得不到的,要自己写)
        selenium.geteval_r("selenium.browserbot.findElement('gotoTA').target='MyPopUp'");
        selenium.openWindow("","MyPopUp");
        selenium.click("gotoTA");
        selenium.waitForPopUp("MyPopUp", "60000");
        selenium.selectWindow("MyPopUp");
        assertTextPresent("热门游戏");
    }
}

(如果用selenium.click("xpath的值"))这里xpath要定义到的元素并不是按钮上的那几个字,而是对应的链接:href,取与href对应的id就行了。

Joyce /
Published under (CC) BY-NC-SA in categories selenium  tagged with sample