2016-12-01 1 views
0

Je lance mon premier test automatisé en utilisant sélénium webdriver en eclipse sur un site statique de démonstration. L'objectif principal du test est de montrer qu'une transaction est confirmée dans mon fichier journal, par ex. devrait dire quelque chose comme "confirmation reçue"/ou non? Cela devrait venir après l'étape suivante:Premier test d'authentification automatisé utilisant Selenium Webdriver dans Eclipse

"// Recherche pour confirmer Button et cliquez dessus driver.findElement (By.id (" suivant ")) cliquez sur(); logger.info (" Cliquez Confirmar Bouton");"

Cependant, je ne suis pas sûr du code à utiliser pour obtenir ce résultat. Un message de confirmation apparaît après que ce bouton a été cliqué. Je veux vérifier que la transaction a fonctionné d'une manière ou d'une autre, et si elle n'a pas été reçue, je veux aussi une notification le disant.

Quelqu'un peut-il aider avec cela ??

Code complet ci-dessous:

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"); 

    } 

Répondre

1

Si vous voulez vérifier que la confirmation apparaît, vous devez affirmer que la confirmation existe et que son contenu correspond à ce qui est attendu.

Les étapes doivent être:

  1. Assertion la confirmation existe et est visible
  2. Vérifiez que tous les matches de texte, le texte que vous attendez-vous à voir
  3. Vérifiez que tous les liens attendus sont visibles et conduisent à la page appropriée

En outre, s'il vous plaît considérer les points suivants:

  • Il semble que vous ne devriez pas avoir '.getText()' dans votre cssSelector.
  • Il est considéré comme une mauvaise pratique d'avoir des tests criblés de Thread.sleep(). Vous devriez jeter un oeil ici http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp pour une alternative .
  • Lorsque vous publiez du code sur un site public, vous devez vous assurer de le nettoyer des informations sensibles telles que les informations de connexion.