2016-12-01 9 views
0

デモの静的サイトでEclipseのselenium webdriverを使用して私の最初の自動テストを実行しています。このテストの主な目的は、ログファイルにトランザクションが確認されたことを示すことです。 "確認を受け取った"のようなものか、そうでないか?これは、次のステップの後に来る必要があります:EclipseでSelenium Webdriverを使用した最初の自動認証テスト

"//ボタンを確認し、それに driver.findElement(By.id(クリックして下さい" 次を、Confirmarをクリックして "))をクリックします() logger.info(。"ボタン");"

しかし、私はこの結果を得るためにどのようなコードを使用するのかよく分かりません。このボタンをクリックすると確認メッセージがポップアップします。取引が何らかの形で行われていることを確認したいのですが、それが届かない場合は、その旨も通知したいと思います。

誰もがこれを助けることができますか?以下

完全なコード:

package com.scotia.test; 
import org.apache.log4j.Logger; 
import org.apache.log4j.PropertyConfigurator; 
import org.apache.log4j.xml.DOMConfigurator; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.support.ui.Select; 
import org.testng.annotations.Optional; 
import org.testng.annotations.Parameters; 
import org.testng.annotations.Test; 



public class ScotiaTest1 { 


@Test 
@Parameters("test1") 
public void beforeTest(@Optional("optional") String type) 
{ 
    System.out.println("Type in Before Test is="+type); 
} 

    public static void main(String[] args) throws InterruptedException { 
     System.setProperty("webdriver.chrome.driver","/Users/theone/Downloads/chromedriver-new"); 

     Logger logger=Logger.getLogger("Test1"); 

     DOMConfigurator.configure("log4j.xml"); 

     // Create a new instance of the Chrome driver 
     WebDriver driver = new ChromeDriver(); 
     logger.info("Chrome opened"); 


     //Login using Username and Password 
     driver.get("https://username:[email protected]/_Prototype/desktop/html/Chile_index.html#"); 
     logger.info("Application Launched"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Find Proximity Serie A link and click on it 
     driver.findElement(By.cssSelector("#investing_tab tr:nth-child(7) a.acct-name")).click(); 
     logger.info("Click Proximidad Serie A"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second");  

     //Find New Funds Button and click on it 
     driver.findElement(By.cssSelector(".pad-top-10.txt-right .btn.action-btn")).click(); 
     logger.info("Click Button Nuevo Fondo"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Select Field Rescue investment and choose Rescue 
     Select dropdown = new Select(driver.findElement(By.id("mf_action"))); 
     dropdown.selectByVisibleText("Inversión"); 
     logger.info("Select Inversión from dropdown"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Select Field Current account and choose current account 
     dropdown = new Select(driver.findElement(By.id("selaccount_drpdown"))); 
     dropdown.selectByVisibleText("Cuenta Corriente *** 0002 USD 10.000,00"); 
     logger.info("Select Cuenta Corriente *** 0002 USD 10.000,00 from dropdown"); 
     //Wait for 1 Sec 

     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Select Field Fund Type and choose medium term 
     dropdown = new Select(driver.findElement(By.id("term"))); 
     dropdown.selectByVisibleText("Deuda de Mediano y Largo Plazo"); 
     logger.info("Select Deuda de Mediano y Largo Plazo from dropdown"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Select Field Mutual Fund Name and choose Proximity Series A 
     dropdown = new Select(driver.findElement(By.id("typefund"))); 
     dropdown.selectByVisibleText("Proximidad Serie A"); 
     logger.info("Select Proximidad Serie A from dropdown"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Select Field Fund account Name and choose 001 
     dropdown = new Select(driver.findElement(By.id("sub_accnt"))); 
     dropdown.selectByVisibleText("001"); 
     logger.info("Select 001 from dropdown"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Select Field Rode and type 222 
     driver.findElement(By.id("amount_field")).sendKeys("222"); 
     logger.info("Type 222 in Monto text feild"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Find to Accept Button and click on it 
     driver.findElement(By.id("next")).click(); 
     logger.info("Click Aceptar button"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //Find to Confirm Button and click on it 
     driver.findElement(By.id("next")).click(); 
     logger.info("Click Confirmar Button"); 

     //Wait for 1 Sec 
     Thread.sleep(1000); 
     logger.info("Pause Execution for 1 second"); 

     //driver.findElement(By.cssSelector("RUIFW-alert-success.getText()"));(does not do anything) 


    // Close browser 

     driver.quit(); 
     logger.info("Close Browser"); 

    } 

答えて

1

あなたは確認メッセージが表示されていることを確認したい場合は、確認が存在することを主張し、その内容が期待されているものを一致する必要があります。

手順は次のようになります。

  1. は確認をアサート存在し、
  2. 表示されているすべてのテキストは、あなたが
  3. は、任意の期待のリンクが表示されていることを確認しにつながる見ることを期待テキストと一致することを確認します適切なページ

はまた、次の点を考慮してください。

  • あなたのcssSelectorに '.getText()'を含めるべきではないようです。
  • Thread.sleep()でテストを行うのは悪い習慣と考えられます。ここをクリックしてください http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp 代替のために。
  • パブリックサイトにコードを投稿するときは、ログイン資格情報などの機密情報を でスクラブしてください。
関連する問題