我想打印结帐流程中的运费,运费是根据地址动态计算的,或者可能是购物车中的产品。我想打印计算后第二个结账页面上的运费。
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();
}
}
答案 0 :(得分:1)
这是我通过在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();
}
}