2016-07-18 1 views
1

私はSelenium WebDriverとtestNGを学ぶのが初めてです。私はいくつかのtestNGアノテーションを以下のテストケースを介して学習しようとしていましたが、1つのテストケースが常に失敗し、エラーの内容を把握できませんでした。1つのtestNGテストケースが一連のテストケースから失敗していますが、問題の内容を特定できませんでしたか?

また、既存の質問で検索しようとしましたが、問題と一致するものが見つかりませんでした。だからここに私は私が達成しようとしているものを説明します:

  1. 私はtestNG注釈のテストケースが含まれている3つのクラスが作成されました。クラス名は、testingNG,testingNG1およびtestingNG2です。

  2. 次に、これらのテストケースをスーツとして実行できるように、testNg xmlファイルを作成しました。

  3. またtest2testingNGクラスで使用したいいくつかのxpathを保存する1つのプロパティファイル(paths.properties)を作成しました。

  4. test2testingNGのxmlファイルを実行しているときに、eclipseは構文エラーを表示せず、問題の内容を理解できませんでした。

ファーストクラス:testigNG

import java.io.FileInputStream; 
import java.io.FileNotFoundException; 
import java.io.IOException; 
import java.util.Properties; 

import org.openqa.selenium.By; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.BeforeTest; 
import org.testng.annotations.Test; 

public class testingNG { 

    @Test 
    public void test1() 
    { 
     System.out.println("first NG test case"); 
    } 

    @Test 
    public void test2() throws IOException, InterruptedException 
    { 
     Properties pro=new Properties(); 
     FileInputStream fis= new FileInputStream (System.getProperty("C:\\Users\\SumitKumar.Dubey\\workspace\\My_testNG\\src\\paths.properties")); 
     pro.load(fis); 
     System.out.println("Login link xpath: "+pro.getProperty("DLJ_Login_Button")); 
     FirefoxDriver driver=new FirefoxDriver(); 
     driver.get("http://www.dsij.in/"); 

     driver.findElement(By.xpath(pro.getProperty("DLJ_Login_Button"))).click(); 
     Thread.sleep(3000); 
     driver.findElement(By.xpath(pro.getProperty("DLJ_Login_Username"))).sendKeys("dubey_sumit"); 
     driver.findElement(By.xpath(pro.getProperty("DLJ_Login_Pwd"))).sendKeys("0VUoUEMGpiC"); 
     driver.findElement(By.xpath(pro.getProperty("DLJ_click_login"))).click(); 
    } 
} 


Second class: testingNG1 
========================= 

import org.testng.annotations.Test; 

public class testingNG1 { 

    @Test 
    public void test4() 
    { 
     System.out.println("fourth NG test case from testNG1 class"); 
    } 
} 

サードクラス:testingNG2

import java.io.Console; 

import org.openqa.selenium.By; 
import org.openqa.selenium.firefox.FirefoxDriver; 
import org.testng.annotations.AfterTest; 
import org.testng.annotations.Test; 


public class testingNG2 { 
    FirefoxDriver driver=new FirefoxDriver(); 

    @Test (priority=1) 
    public void site_navigate() 
    { 

     driver.get("http://demoqa.com/"); 
     System.out.println("print when ulr is entered!"); 


    } 
    @Test (priority=2) 
    public void click_about_us() 
    { 
     driver.findElement(By.xpath("//a[@href='http://demoqa.com/about-us/']")).click(); 
     System.out.println("print when ulr is entered!"); 
     //driver.getPageSource().contains("About us"); 
     if(driver.getPageSource().contains("About us")) 
     { 
     System.out.println("Text is Present"); 
     } 
     else 
     { 
     System.out.println("Text is not Present"); 
     } 
    } 
    @AfterTest 
    public void close_browser() 
    { 
     driver.close(); 
     driver.quit(); 
    } 

} 

TestNGのxmlファイル:

<?xml version="1.0" encoding="UTF-8"?> 
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"> 
<suite name="Suite"> 

    <test name="Test1"> 
    <classes> 
     <class name="testingNG1"/> 
    </classes> 
    </test> 

    <test name="Test2"> 
    <classes> 
     <class name="testingNG2"/> 
    </classes> 
    </test> 

    <test name="Test3"> 
    <classes> 
     <class name="testingNG"/> 
    </classes> 
    </test> 

</suite> <!-- Suite --> 

paths.propertiesファイル:

#Dalal Street Login 
DLJ_Login_Button=//a[@id='dnn_dnnLogin_enhancedLoginLink'] 
DLJ_Login_Username=//input[@id='dnn_ctr5070_Login_Login_DNN_txtUsername'] 
DLJ_Login_Pwd=//input[@id='dnn_ctr5070_Login_Login_DNN_txtPassword'] 
DLJ_click_login=//input[@id='dnn_ctr5070_Login_Login_DNN_cmdLogin'] 

ここでtest2testingNGクラスが失敗しました。これはプロパティファイルを使用しています。

+0

の可能性が重複して[デバッガで、どのようにそれは私が問題の診断に役立つことができますか?](http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can -it-help-me-diagnose-problems) – Raedwald

答えて

1

私は性質があるため、この行のロードされていないと思う:

FileInputStream fis= new FileInputStream (System.getProperty("C:\\Users\\SumitKumar.Dubey\\workspace\\My_testNG\\src\\paths.properties")); 

この行からはSystem.getProperty()を削除し、以下に示すようにFileオブジェクトのパスを指定してください。

FileInputStream fis= new FileInputStream (new File("C:\\Users\\SumitKumar.Dubey\\workspace\\My_testNG\\src\\paths.properties")); 
+0

Jaganathanありがとうございます。私は試して、それは働いた。可能であれば、コンセプトビットをもっと詳しく教えてください。実際に私はいくつかのチュートリアルを読んで、これを試してみました。 –

+0

プロパティファイルへのパスを** testng.properties.file.path **のようなSystemプロパティに保存すると、 'System.getProperty(" testng.properties.file.path ");' In私はあなたがシステムプロパティを持っていないと思うが、プロパティファイルへのパスだけです。したがって、ファイルパスから直接プロパティをロードするだけです。 –

+0

これは正解です。プロパティファイルのパスです。迅速な対応のためにありがとうございました:) –

関連する問題