使用Selenium我怎么打印结帐页面上的运费 [英] Using Selenium how I Print the shipping rate on the checkout page

查看:193
本文介绍了使用Selenium我怎么打印结帐页面上的运费的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要打印那些来吧结帐过程,航运是动态计算的运费率,对地址的碱或可能在购物车商品。我要打印的运费计算那些来后第二次结帐页面上。

 进口com.thoughtworks.selenium *。
进口org.junit.After;
进口org.junit.Before;
进口org.junit.Test;
引入静态org.junit.Assert *。
进口的java.util.regex.Pattern;公共类的测试{
    私人硒硒;@之前
公共无效设置()抛出异常{
    硒=新DefaultSelenium(本地主机,4444,*铬,http://testing-671.myshopify.com/);
    selenium.start();
}@测试
公共无效testtesting()抛出异常{
    selenium.open(/);
    selenium.click(链接=测试);
    selenium.waitForPageToLoad(30000);
    selenium.click(//一个[包含(文字(),'目录'));
    selenium.waitForPageToLoad(30000);
    selenium.click(CSS = IMG [ALT = \\测试\\]);
    selenium.waitForPageToLoad(30000);
    selenium.click(ID =添加到购物车);
    selenium.waitForPageToLoad(30000);
    selenium.click(ID =结账);
    selenium.waitForPageToLoad(30000);
    selenium.type(ID = checkout_email,tester@gmail.com);
    selenium.type(ID = checkout_shipping_address_first_name,测试);
    selenium.type(ID = checkout_shipping_address_last_name,测试);
    selenium.type(ID = checkout_shipping_address_company,测试);
    selenium.type(ID = checkout_shipping_address_address1,测试);
    selenium.type(ID = checkout_shipping_address_address2,测试);
    selenium.type(ID = checkout_shipping_address_city,测试);
    selenium.select(ID = checkout_shipping_address_country,标签=阿尔巴尼亚);
    selenium.click(CSS =选项[值= \\阿尔巴尼亚\\]);
    selenium.select(ID = checkout_shipping_address_country,标签=印度);
    selenium.select(ID = checkout_shipping_address_province,标签=昌迪加尔);
    selenium.type(ID = checkout_shipping_address_zip,160062);
    selenium.click(NAME =提交);
    selenium.waitForPageToLoad(30000);
}@后
公共无效拆解()抛出异常{
    selenium.stop();
}
}


解决方案

这是我在硒IDE中运行和出口测试用例的程序硒RC和JUnit检索更新code:

 进口com.thoughtworks.selenium *。
进口org.junit.After;
进口org.junit.Before;
进口org.junit.Test;
引入静态org.junit.Assert *。
进口的java.util.regex.Pattern;公共类测试用例{
    私人硒硒;    @之前
    公共无效设置()抛出异常{
        硒=新DefaultSelenium(本地主机,4444,*铬,http://testing-671.myshopify.com);
        selenium.start();
    }    @测试
    公共无效测试用例()抛出异常{
        selenium.open(/);
        selenium.click(链接=测试);
        selenium.waitForPageToLoad();
        selenium.click(//一个[包含(文字(),'目录'));
        selenium.waitForPageToLoad(30000);
        selenium.click(CSS = IMG [ALT = \\测试\\]);
        selenium.waitForPageToLoad(30000);
        selenium.click(ID =添加到购物车);
        selenium.waitForPageToLoad(30000);
        selenium.click(ID =结账);
        selenium.waitForPageToLoad(30000);
        selenium.type(ID = checkout_email,tester@gmail.com);
        selenium.type(ID = checkout_shipping_address_first_name,测试);
        selenium.type(ID = checkout_shipping_address_last_name,测试);
        selenium.type(ID = checkout_shipping_address_company,测试);
        selenium.type(ID = checkout_shipping_address_address1,测试);
        selenium.type(ID = checkout_shipping_address_address2,测试);
        selenium.type(ID = checkout_shipping_address_city,测试);
        selenium.select(ID = checkout_shipping_address_country,标签=阿尔巴尼亚);
        selenium.select(ID = checkout_shipping_address_province,标签=昌迪加尔);
        selenium.type(ID = checkout_shipping_address_zip,160062);
        selenium.click(NAME =提交);
        selenium.waitForPageToLoad(30000);
        对于(INT第二= 0 ;;第二++){
            如果(第二> = 60)失败(超时);
            尝试{如果(selenium.isElement present(//跨度[@类='总-line__name和包含(文字(),运费)] /以下同胞::强[包含(文字() 卢比。')]))打破; }赶上(例外五){}
            视频下载(1000);
        }        串价格= selenium.getText(//跨度[@类='总-line__name和包含(文字(),运费)] /以下同胞::强);
        的System.out.println(价格);
    }    @后
    公共无效拆解()抛出异常{
        selenium.stop();
    }
}

I want to print the Shipping rate those come on the checkout process, Shipping is calculated dynamically, on the bases of address or may be product in the Cart. I want to print the Shipping rate those come on the 2nd checkout page after calculation.

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;

public class testing {
    private Selenium selenium;

@Before
public void setUp() throws Exception {
    selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://testing-671.myshopify.com/");
    selenium.start();
}

@Test
public void testtesting() throws Exception {
    selenium.open("/");
    selenium.click("link=Testing");
    selenium.waitForPageToLoad("30000");
    selenium.click("//a[contains(text(),'Catalog')]");
    selenium.waitForPageToLoad("30000");
    selenium.click("css=img[alt=\"testing\"]");
    selenium.waitForPageToLoad("30000");
    selenium.click("id=add-to-cart");
    selenium.waitForPageToLoad("30000");
    selenium.click("id=checkout");
    selenium.waitForPageToLoad("30000");
    selenium.type("id=checkout_email", "tester@gmail.com");
    selenium.type("id=checkout_shipping_address_first_name", "test");
    selenium.type("id=checkout_shipping_address_last_name", "test");
    selenium.type("id=checkout_shipping_address_company", "test");
    selenium.type("id=checkout_shipping_address_address1", "test");
    selenium.type("id=checkout_shipping_address_address2", "test");
    selenium.type("id=checkout_shipping_address_city", "test");
    selenium.select("id=checkout_shipping_address_country", "label=Albania");
    selenium.click("css=option[value=\"Albania\"]");
    selenium.select("id=checkout_shipping_address_country", "label=India");
    selenium.select("id=checkout_shipping_address_province", "label=Chandigarh");
    selenium.type("id=checkout_shipping_address_zip", "160062");
    selenium.click("name=commit");
    selenium.waitForPageToLoad("30000");
}

@After
public void tearDown() throws Exception {
    selenium.stop();
}
}

解决方案

This is the updated code that I've retrieved by running in Selenium IDE and exporting the testcase as program for Selenium RC and junit:

import com.thoughtworks.selenium.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import static org.junit.Assert.*;
import java.util.regex.Pattern;

public class Testcases {
    private Selenium selenium;

    @Before
    public void setUp() throws Exception {
        selenium = new DefaultSelenium("localhost", 4444, "*chrome", "http://testing-671.myshopify.com");
        selenium.start();
    }

    @Test
    public void testCases() throws Exception {
        selenium.open("/");
        selenium.click("link=Testing");
        selenium.waitForPageToLoad("");
        selenium.click("//a[contains(text(),'Catalog')]");
        selenium.waitForPageToLoad("30000");
        selenium.click("css=img[alt=\"testing\"]");
        selenium.waitForPageToLoad("30000");
        selenium.click("id=add-to-cart");
        selenium.waitForPageToLoad("30000");
        selenium.click("id=checkout");
        selenium.waitForPageToLoad("30000");
        selenium.type("id=checkout_email", "tester@gmail.com");
        selenium.type("id=checkout_shipping_address_first_name", "test");
        selenium.type("id=checkout_shipping_address_last_name", "test");
        selenium.type("id=checkout_shipping_address_company", "test");
        selenium.type("id=checkout_shipping_address_address1", "test");
        selenium.type("id=checkout_shipping_address_address2", "test");
        selenium.type("id=checkout_shipping_address_city", "test");
        selenium.select("id=checkout_shipping_address_country", "label=Albania");
        selenium.select("id=checkout_shipping_address_province", "label=Chandigarh");
        selenium.type("id=checkout_shipping_address_zip", "160062");
        selenium.click("name=commit");
        selenium.waitForPageToLoad("30000");
        for (int second = 0;; second++) {
            if (second >= 60) fail("timeout");
            try { if (selenium.isElementPresent("//span[@class='total-line__name' and contains(text(),'Shipping')]/following-sibling::strong[contains(text(),'Rs.')]")) break; } catch (Exception e) {}
            Thread.sleep(1000);
        }

        String Price = selenium.getText("//span[@class='total-line__name' and contains(text(),'Shipping')]/following-sibling::strong");
        System.out.println(Price);
    }

    @After
    public void tearDown() throws Exception {
        selenium.stop();
    }
}

这篇关于使用Selenium我怎么打印结帐页面上的运费的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆