我想打印出在结帐过程中出现的发货率,发货是根据地址动态计算的,或者是购物车中的产品。我想在计算后在第二页结帐时打印出运费。
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();
}
}发布于 2014-11-25 12:49:33
这是我通过在Selenium IDE中运行并将测试用例导出为Selenium RC和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();
}
}https://stackoverflow.com/questions/27124598
复制相似问题