2016-05-27 23 views
0

Selen WebDriver: In diesem Code Mein Testfall ist vorbei für eine Test-E-Mail-Konto, aber für den zweiten Test Mail den Code übersprungen, es geht nicht den zweiten Test E-MailSelen WebDriver TestNG mit

package Packet; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.testng.annotations.AfterMethod; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 

public class NewTest { 
    public WebDriver driver; 
    // = new ChromeDriver(); 
    // System.setProperty("webdriver.chrome.driver","/Users/rohit/Desktop/chromedriver"); 
    public String baseurl = "http://google.com"; 

    @BeforeTest 
    public void launchbrowser() 

    { 
     System.out.println("LaunchBrowser called..."); 
     System.setProperty("webdriver.chrome.driver", "/Users/rohit/Desktop/chromedriver"); 
     driver = new ChromeDriver(); 
     driver.get(baseurl); 
    } 
    // *[@id="gmail-sign-in"]//*[@id="gbw"]/div/div/div[1]/div[1]/a 

    @BeforeMethod 
    public void Beforemethod() { 
     System.out.println("Hello Before Method"); 
    } 

    @Test(priority = 0) 
    public void GmailTap() { 
     System.out.println("Test priority 0 called..."); 
     driver.findElement(By.xpath("//*[@id=\"gbw\"]/div/div/div[1]/div[1]/a")).click(); 
     // driver.findElement(By.xpath("//*[@id=\"gmail-sign-in\"]")).click(); 

     System.out.println("hello"); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.HOURS); 
     // Thread.sleep(8000); 
     // driver.close(); 
     // findElement(By.cssSelector("")) 
     driver.findElement(By.name("signIn")).click(); 
     // CharSequence charSequence = new 
     boolean flag = true; 
     while (flag) { 
      try { 
       driver.findElement(By.name("Passwd")).sendKeys("123456"); 
       System.out.println("Executed"); 
       flag = false; 
      } catch (Exception e) { 
      } 
     } 

     driver.findElement(By.id("signIn")).click(); 

     driver.findElement(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click(); 
     driver.findElement(By.xpath("//*[@id=\"gb_71\"]")).click(); 

    } 
    // _____________ 

    @Test(priority = 1) 
    public void GmailTap2() { 
     System.out.println("Test priority 1 called..."); 
     // driver.findElement(By.xpath("//*[@id=\"gbw\"]/div/div/div[1]/div[1]/a")).click(); 

     System.out.println("hello"); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.HOURS); 

     driver.findElement(By.name("signIn")).click(); 
     boolean flag = true; 
     while (flag) { 
      try { 
       driver.findElement(By.name("Passwd")).sendKeys("123456"); 
       System.out.println("Executed"); 
       flag = false; 
      } catch (Exception e) { 
      } 
     } 

     driver.findElement(By.id("signIn")).click(); 

     driver.findElement(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click(); 
     driver.findElement(By.xpath("//*[@id=\"gb_71\"]")).click(); 

    } 

    // ____________ 

    @AfterMethod 
    public void aftersignout1() { 
     driver.findElement(By.xpath("//*[@id=\"account-chooser-link\"]")).click(); 
     driver.findElement(By.xpath("//*[@id=\"account-chooser-add-account\"]")).click(); 
    } 

    @AfterTest 
    public void aftersignout() { 
     System.out.println("aftersignOut called..."); 
     // New Accnt 
     driver.close(); 
    } 
    // *[@id="account-chooser-add-account"] 

} 

Die Ausgabe wird angezeigt als:

LaunchBrowser called... 
Starting ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b) on port 25912 
Only local connections are allowed. 
Hello Before Method 
Test priority 0 called... 
hello 
Executed 
Hello Before Method 
Test priority 1 called... 
[340.657][SEVERE]: Unable to receive message from renderer 
+0

warum u initiieren und ur WebDriver Instanz für jeden Testfall immer wieder zu zerstören ... versuchen, in der @ BeforeTest-Annotation einmal initiieren und es bei @ AfterTest Annotation – noor

+0

@Noor zerstören, habe ich meinen Code durch Ihre Erklärung aktualisiert, aber es gibt mir einen Fehler, der keine Nachricht von Renderer erhalten kann.Kann bitte einen Blick auf meine Code –

Antwort

0

hi in @AfterMethod statt driver.close(); Bitte benutze driver.quit();

+0

Dieser Lärm Ich habe nicht für mich gearbeitet. Allerdings habe ich meinen Code aktualisiert, aber das hat nicht funktioniert. –

+0

das gleiche Problem oder etw. Erhalten –

+0

Anderes Problem als: LaunchBrowser namens ... Starten von ChromeDriver 2.20.353124 (035346203162d32c80f1dce587c8154a1efa0c3b) auf Port 25912 Nur lokale Verbindungen sind erlaubt. Hallo vor Methode Test Priorität 0 aufgerufen ... Hallo Hello vor Methode ausgeführt Test Priorität 1 aufgerufen ... [340.657] [SEVERE]: Kann keine Nachricht vom Renderer empfangen –

0

der folgende Code funktioniert wie ein Charme für mich

import java.util.concurrent.TimeUnit; 
import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.WebElement; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.openqa.selenium.support.ui.ExpectedConditions; 
import org.openqa.selenium.support.ui.WebDriverWait; 
import org.testng.annotations.AfterMethod; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.Test; 

public class NewTest { 
    public WebDriver driver; 
    public String baseurl = "http://google.com"; 

    @BeforeMethod 
    public void launchbrowser() 

    { 
     System.out.println("LaunchBrowser called..."); 
     System.setProperty("webdriver.chrome.driver", "D:/your/path/to/Driver/chromedriver.exe"); 
     driver = new ChromeDriver(); 
     driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
     driver.get(baseurl); 
    } 

    @Test(priority = 0) 
    public void GmailTap() { 
     System.out.println("Test priority 0 called..."); 
     driver.findElement(By.linkText("Gmail")).click(); 

     System.out.println("hello"); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.findElement(By.id("next")).click(); 

     boolean flag = true; 

     while (flag) { 

      try { 
       driver.findElement(By.name("Passwd")).sendKeys("123456"); 
       System.out.println("Executed"); 
       flag = false; 
      } catch (Exception e) { 
      } 
     } 

     driver.findElement(By.id("signIn")).click(); 

     driver.findElement(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click(); 
     driver.findElement(By.xpath("//*[@id=\"gb_71\"]")).click(); 

    } 

    @Test(priority = 1) 
    public void GmailTap2() { 
     System.out.println("Test priority 1 called..."); 
     System.out.println("Test priority 0 called..."); 
     driver.findElement(By.linkText("Gmail")).click(); 

     System.out.println("hello"); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.findElement(By.id("next")).click(); 

     boolean flag = true; 
     while (flag) { 
      try { 
       driver.findElement(By.name("Passwd")).sendKeys("123456"); 
       System.out.println("Executed"); 
       flag = false; 
      } catch (Exception e) { 
      } 
     } 

     driver.findElement(By.id("signIn")).click(); 

     WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions 
       .presenceOfElementLocated(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span"))); 
     myDynamicElement.click(); // driver.findElement(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click(); 
            // driver.findElement(By.xpath("//*[@id=\"gb_71\"]")).click(); 

    } 

    // ____________ 

    @AfterMethod 
    public void aftersignout() { 
     System.out.println("aftersignOut called..."); // New Accnt 

     WebElement myDynamicElement = (new WebDriverWait(driver, 10)) 
       .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id=\"account-chooser-link\"]"))); 
     myDynamicElement.click(); 

     driver.findElement(By.xpath("//*[@id=\"account-chooser-add-account\"]")).click(); 
     driver.quit(); 
    } // *[@id="account-chooser-add-account"] 

} 
0

bekam schließlich meine Ausgabe

package Packet; 

import java.util.concurrent.TimeUnit; 

import org.openqa.selenium.By; 
import org.openqa.selenium.WebDriver; 
import org.openqa.selenium.chrome.ChromeDriver; 
import org.testng.annotations.AfterMethod; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.BeforeMethod; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 

public class NewTest { 

    boolean flag = true; 
    public WebDriver driver; 
    public String baseurl = "http://google.com"; 



    @BeforeTest 
    public void launchbrowser() 

    { 
     System.out.println("LaunchBrowser called..."); 
     System.setProperty("webdriver.chrome.driver", "/Users/rohit/Desktop/chromedriver"); 
     driver = new ChromeDriver(); 
     driver.get(baseurl); 
    } 


    @BeforeMethod 
    public void Beforemethod() { 
     System.out.println("Hello Before Method"); 
    } 

    @Test(priority = 0) 
    public void GmailTap() { 
     System.out.println("Test priority 0 called..."); 
     driver.findElement(By.xpath("//*[@id=\"gbw\"]/div/div/div[1]/div[1]/a")).click(); 
     System.out.println("hello"); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.HOURS); 
     driver.findElement(By.name("signIn")).click(); 
     boolean flag = true; 
     while (flag) { 
      try { 
       driver.findElement(By.name("Passwd")).sendKeys("123456"); 
       System.out.println("Executed"); 
       flag = false; 
      } catch (Exception e) { 
      } 
     } 

     driver.findElement(By.id("signIn")).click(); 
     driver.findElement(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click(); 
     driver.findElement(By.xpath("//*[@id=\"gb_71\"]")).click(); 

    } 





    @Test(priority = 1) 
    public void GmailTap2() { 
     System.out.println("Test priority 1 called..."); 
     System.out.println("hello"); 
     driver.findElement(By.id("Email")).sendKeys("[email protected]"); 
     driver.manage().timeouts().implicitlyWait(10, TimeUnit.HOURS); 
     driver.findElement(By.name("signIn")).click(); 
     boolean flag = true; 
     while (flag) { 
      try { 
       driver.findElement(By.name("Passwd")).sendKeys("123456"); 
       System.out.println("Executed"); 
       flag = false; 
      } catch (Exception e) { 
      } 
     } 

     driver.findElement(By.id("signIn")).click(); 

     driver.findElement(By.xpath("//*[@id=\"gb\"]/div[1]/div[1]/div[2]/div[4]/div[1]/a/span")).click(); 
     driver.findElement(By.xpath("//*[@id=\"gb_71\"]")).click(); 

    } 


    @AfterMethod 
    public void aftersignout1() { 

     if (flag) 
     { 
      driver.findElement(By.xpath("//*[@id=\"account-chooser-link\"]")).click(); 
     flag = false; 
     } 
     driver.findElement(By.xpath("//*[@id=\"account-chooser-add-account\"]")).click(); 
    } 
    //*[@id="account-chooser-add-account"] 
    @AfterTest 
    public void aftersignout() { 
     System.out.println("aftersignOut called..."); 
     // New Accnt`enter code here` 
     driver.close(); 
    } 
    }