2017-04-15 2 views
-1

J'écris un programme pour la multiplication de Booth en tant qu'application Web JAVA dans Netbeans 8.2. J'utilise selenium-server-standalone-2.50.1.jar et Firefox 46.Le test sélénium ne fonctionne pas

Lorsque j'écris mon code et l'exécute, il ouvre juste la page mais aucun test ne se produit. S'il vous plaît aider.

/* 
* To change this license header, choose License Headers in Project Properties. 
* To change this template file, choose Tools | Templates 
* and open the template in the editor. 
*/ 

/** 
* 
* 
*/ 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.firefox.FirefoxDriver; 

public class booth { 
    private WebElement element, element1; 
    public String str; 

    public void Mul_Positive(){ 
     WebDriver driver = new FirefoxDriver(); 
     driver.get("http://localhost:8080/BoothsMul/index.html"); 
     element = driver.findElement(By.xpath("//input[@name='t1']")); 
     element.sendKeys("2"); 
     str = driver.findElement(By.xpath("//input[@name='t1']")).getText(); 

     System.out.println(str); 

     element1 = driver.findElement(By.xpath("//input[@name='t2']")); 
     element1.sendKeys("5"); 
     str = driver.findElement(By.xpath("//input[@name='t2']")).getText(); 

     System.out.println(str); 

     driver.findElement(By.xpath("//input[@name='submit']")).click(); 
     driver.quit(); 
    } 

    public void Mul_Negative(){ 
     WebDriver driver = new FirefoxDriver(); 
     driver.get("http://localhost:8080/BoothsMul/index.html"); 
     element = driver.findElement(By.xpath("//input[@name='t1']")); 
     element.sendKeys("c"); 
     str = driver.findElement(By.xpath("//input[@name='t1']")).getText(); 

     System.out.println(str); 

     element = driver.findElement(By.xpath("//input[@name='t2']")); 
     element.sendKeys("5"); 
     str = driver.findElement(By.xpath("//input[@name='t2']")).getText(); 

     System.out.println(str); 

     driver.findElement(By.xpath("//input[@name='submit']")).click(); 
     driver.quit(); 
    } 

    public static void main(String[] args){ 
     booth b = new booth(); 

     b.Mul_Positive(); 
     b.Mul_Negative(); 

    } 
} 

Mon index.html

<!DOCTYPE html> 
<!-- 
To change this license header, choose License Headers in Project Properties. 
To change this template file, choose Tools | Templates 
and open the template in the editor. 
--> 
<html> 
    <body> 

     <form name='f1' action='http://localhost:8080/BoothsMul/Boothmul' method='get'> 
First No. <input type='text' name='t1'><br> 
Second No. <input type='text' name='t2'><br> 
<input type='submit' name='submit' value='submit'> 
     </form> 
    </body> 
</html> 
+0

Quelles sont vos sélénium, version Java? – kushal

+0

@kushal Selenium 2.50.1 Java 1.8 Firefox 46 – Varun

+0

Si vous utilisez Java 8 alors la version de sélénium doit être 3.0 ou supérieure aussi, vous devrez utiliser geckodriver pour exécuter firefox – kushal

Répondre

-2

MIS À JOUR:

Si vous utilisez selenium 3.0.1 ou plus alors la version JAVA devrait être 1.8 aussi, vous aurez besoin d'utiliser geckodriver pour exécuter Firefox. (Assurez-vous que vous utilisez les dernières versions de tous les composants requis dans ce cas)

Sinon, vous devez mettre à niveau votre version Selenium vers 3.0 or higher.

+0

Son inverse, si vous utilisez la version de sélénium> 3.0 alors la version java devrait être minimum 8 .... ce n'est pas comme si vous utilisez java version 8 vieux jar ne fonctionnerait pas ... ici le problème est la compatibilité de 'Selenium Version' et' FF version'. – Paras