私はSelenium WebDriverとtestNGを学ぶのが初めてです。私はいくつかのtestNGアノテーションを以下のテストケースを介して学習しようとしていましたが、1つのテストケースが常に失敗し、エラーの内容を把握できませんでした。1つのtestNGテストケースが一連のテストケースから失敗していますが、問題の内容を特定できませんでしたか?
また、既存の質問で検索しようとしましたが、問題と一致するものが見つかりませんでした。だからここに私は私が達成しようとしているものを説明します:
私は
testNG
注釈のテストケースが含まれている3つのクラスが作成されました。クラス名は、testingNG
,testingNG1
およびtestingNG2
です。次に、これらのテストケースをスーツとして実行できるように、testNg xmlファイルを作成しました。
また
test2
のtestingNG
クラスで使用したいいくつかのxpathを保存する1つのプロパティファイル(paths.properties
)を作成しました。test2
がtestingNG
の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']
ここでtest2
のtestingNG
クラスが失敗しました。これはプロパティファイルを使用しています。
の可能性が重複して[デバッガで、どのようにそれは私が問題の診断に役立つことができますか?](http://stackoverflow.com/questions/25385173/what-is-a-debugger-and-how-can -it-help-me-diagnose-problems) – Raedwald