2016-12-05 2 views
0

問題は、SeleniumがCheckoutボタンを検出してカートに商品を追加できないことです。SeleniumがCheckoutボタンを検出できず、カートに商品を追加できません

package automationFramework; 

import java.util.regex.Pattern; 
import java.util.concurrent.TimeUnit; 
import org.junit.*; 
import static org.junit.Assert.*; 
import static org.hamcrest.CoreMatchers.*; 
import org.openqa.selenium.*; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.openqa.selenium.support.ui.Select; 

public class Checkout { 
    private WebDriver driver; 
    private String baseUrl; 
    private boolean acceptNextAlert = true; 
    private StringBuffer verificationErrors = new StringBuffer(); 

    @Before 

    public void setUp() throws Exception { 
    driver = new FirefoxDriver(); 
    baseUrl = "http://sng.bestpricewebsitedesign.com/"; 
    driver.manage().timeouts().implicitlyWait(90, TimeUnit.SECONDS); 

    } 

    @Test 
    public void testNewCheckout() throws Exception { 
    driver.get(baseUrl + "/index.php?route=common/home"); 
    driver.findElement(By.linkText("Home")).click(); 
    driver.findElement(By.linkText("Login")).click(); 
    driver.findElement(By.id("input-email")).clear(); 
    driver.findElement(By.id("input-email")).sendKeys("[email protected]"); 
    driver.findElement(By.id("input-password")).clear(); 
    driver.findElement(By.id("input-password")).sendKeys("asdfgh"); 
    driver.findElement(By.cssSelector("input.btn.btn-primary")).click(); 
    driver.findElement(By.linkText("Store")).click(); 
    driver.findElement(By.xpath("(//button[@type='button'])[14]")).click(); 
    driver.findElement(By.cssSelector("#cart > button.dropdown-toggle")).click(); 

    driver.findElement(By.id("button-payment-address")).click(); 
    driver.findElement(By.id("button-shipping-address")).click(); 
    driver.findElement(By.id("button-shipping-method")).click(); 
    driver.findElement(By.name("agree")).click(); 
    driver.findElement(By.id("button-payment-method")).click(); 
    driver.findElement(By.id("button-confirm")).click(); 
    driver.findElement(By.linkText("Continue")).click(); 
    driver.findElement(By.linkText("Logout")).click(); 
    } 

    @After 
    public void tearDown() throws Exception { 
    driver.quit(); 
    String verificationErrorString = verificationErrors.toString(); 
    if (!"".equals(verificationErrorString)) { 
     fail(verificationErrorString); 
    } 
    } 

    private boolean isElementPresent(By by) { 
    try { 
     driver.findElement(by); 
     return true; 
    } catch (NoSuchElementException e) { 
     return false; 
    } 
    } 

    private boolean isAlertPresent() { 
    try { 
     driver.switchTo().alert(); 
     return true; 
    } catch (NoAlertPresentException e) { 
     return false; 
    } 
    } 

    private String closeAlertAndGetItsText() { 
    try { 
     Alert alert = driver.switchTo().alert(); 
     String alertText = alert.getText(); 
     if (acceptNextAlert) { 
     alert.accept(); 
     } else { 
     alert.dismiss(); 
     } 
     return alertText; 
    } finally { 
     acceptNextAlert = true; 
    } 
    } 
} 
+1

ここであなたの仕事をするように人々に依頼しないでください。スタックオーバーフローは自由労働ではなく、ボランティア支援の源泉です。 – halfer

+0

私はすべてを試しましたが、何も問題を修正するようです。よく穴を掘ることを求めていません........ – Nasir

+0

執筆コードが「実際の仕事ではない」との見方はよくありますが、その意見は間違っています。デザイナーやアーティストはしばしば無料で仕事をするように求められていますが、支払いをせずに人工労働を請け負うことを夢見ることはありません。最終的には、「誰かがそれを修正する」という言葉の問題は、ボランティアに発行するための受け入れ可能な指示ではない。希望が助けてくれる! – halfer

答えて

0

以下は、「Blue Tshirt」をカートに入れてチェックアウトするためのコードです。

@Test 
public void testNewCheckout() throws Exception { 
    driver.get(baseUrl + "/index.php?route=common/home"); 
    driver.findElement(By.linkText("Home")).click(); 
    driver.findElement(By.linkText("Login")).click(); 
    driver.findElement(By.id("input-email")).clear(); 
    driver.findElement(By.id("input-email")).sendKeys("[email protected]"); 
    driver.findElement(By.id("input-password")).clear(); 
    driver.findElement(By.id("input-password")).sendKeys("asdfgh"); 
    //driver.findElement(By.cssSelector("input.btn.btn-primary")).click(); 
    driver.findElement(By.xpath("//input[@value='Login']")).click();; 
    driver.findElement(By.linkText("Store")).click(); 
    driver.findElement(By.xpath("//h4/a[text()='Blue Tshirt']/following::span[text()='Add to Cart'][1]")).click(); 
    //driver.findElement(By.cssSelector("#cart > button.dropdown-toggle")).click(); 
    driver.findElement(By.xpath("//div[@id='cart']/button[1]")).click(); 
    driver.findElement(By.id("button-payment-address")).click(); 
    driver.findElement(By.id("button-shipping-address")).click(); 
    driver.findElement(By.id("button-shipping-method")).click(); 
    driver.findElement(By.name("agree")).click(); 
    driver.findElement(By.id("button-payment-method")).click(); 
    driver.findElement(By.id("button-confirm")).click(); 
    driver.findElement(By.linkText("Continue")).click(); 
    driver.findElement(By.linkText("Logout")).click(); 
} 

私は上記のコードをテストしており、うまく動作します。既存のテスト方法を上記のものに置き換えて、それがあなたのために働く場合は、私に知らせてください。

+0

いいえ、動作しません。私は交換しました 私は2つの問題に直面しています。 1.商品がカートに追加されておらず、2つ目のチェックアウトページで問題が発生している2行を開くことができません.. driver.findElement(By.xpath( "(// button [@ type = 'button'])[14 ]"))。クリック(); driver.findElement(By.cssSelector( "#cart> button.dropdown-toggle"))。クリック(); – Nasir

+0

Mahipalありがとうございます。 カートに追加すると問題なく動作します。 – Nasir

+0

素晴らしい。どういたしまして。あなたが私の答えに満足しているなら、あなたは私の答えを受け入れて、それを有用とマークしてもらえますか? – Mahipal

関連する問題