首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Selenium如何在结帐页面上打印送货率

使用Selenium如何在结帐页面上打印送货率
EN

Stack Overflow用户
提问于 2014-11-25 10:47:24
回答 1查看 185关注 0票数 1

我想打印出在结帐过程中出现的发货率,发货是根据地址动态计算的,或者是购物车中的产品。我想在计算后在第二页结帐时打印出运费。

代码语言:javascript
复制
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();
}
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-11-25 12:49:33

这是我通过在Selenium IDE中运行并将测试用例导出为Selenium RC和junit程序所检索的更新代码:

代码语言:javascript
复制
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();
    }
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27124598

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档