2012-05-10 18 views
8

मैं सेलेनियम वेबड्राइवर, एक्लिप्स, टेस्टएनजी और सरेफायर प्लगइन का उपयोग कर रहा हूं। मैं pom.xml से testng.xml फ़ाइल चलाने में सक्षम नहीं हूँ। जबकि मैं एमवीएन परीक्षण का उपयोग कर pom.xml चला रहा हूं, यह सीधे src/test/java में फ़ाइल चलाता है।मैवेन में pom.xml से testng.xml फ़ाइल को कैसे कॉल करें

मेरी pom.xml कोड

<groupId>angel</groupId> 
<artifactId>Angel</artifactId> 
<version>1.0-SNAPSHOT</version> 
<packaging>jar</packaging> 

<name>Angel</name> 
<url>http://maven.apache.org</url> 

<properties> 
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> 

<dependencies> 
      <!-- Java API to access the Client Driver Protocols --> 
<dependency> 
    <groupId>org.seleniumhq.selenium</groupId> 
    <artifactId>selenium-java</artifactId> 
    <version>2.21.0</version> 
</dependency> 
    <!-- JExcel API is a java library which provides the ability to read, write, and     modify Microsoft Excel spreadsheets.--> 
    <dependency> 
    <groupId>net.sourceforge.jexcelapi</groupId> 
    <artifactId>jxl</artifactId> 
    <version>2.6.10</version> 
    </dependency> 
    <dependency> 
    <groupId>log4j</groupId> 
    <artifactId>log4j</artifactId> 
    <version>1.2.14</version> 
</dependency> 
<!-- Java API for manipulate the Microsoft Excel Sheets. --> 
<dependency> 
<groupId>org.apache.poi</groupId> 
<artifactId>poi-contrib</artifactId> 
<version>3.5-beta5</version> 
</dependency> 
<!-- Java Mail API used to send Mails. --> <dependency>    <groupId>javax.mail</groupId> 
<artifactId>mail</artifactId> <version>1.4.3</version> 
</dependency> 
<dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.3.1</version> 
    <scope>test</scope> 
</dependency> 
</dependencies> 
    <build> 
<plugins> 
    <plugin> 
     <groupId>org.apache.maven.plugin</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.12</version> 
      <configuration> 
      <suiteXmlFiles> 
       <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
      </suiteXmlFiles> 
       </configuration> 
    </plugin> 
<plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <configuration> 
      <source>1.6</source> 
      <target>1.6</target> 
     </configuration>  </plugin> 

</plugins> 
    </project> 

कृपया मेरी मदद है।

मेरे परियोजना संरचना है

project 
--src/main/java 
--src/main/resources 
--src/test/java 
    | 
    --my testng class file with @Test method. 
--src/test/resources 
    | 
     --testng.xml 
--maven dependencies 
--jre system library 
--src 
    | 
    --main 
    --test 
--target 
pom.xml 

- => फ़ोल्डर नाम | - => उप फ़ोल्डर नाम

मेरे testng.xml फ़ाइल है ...

<?xml version="1.0" encoding="UTF-8"?> 
    <suite name="Suite1" verbose="1" > 

<test name="samplePage Test" > 
    <classes> 
    <class name="TestScripts.SamplePage" > 
     <methods> 
      <include name = "SamplePageTest_Execution"/> 
     </methods> 
    </class> 
</classes> 
</test> 
    <test name="newSamplePage Test" > 
    <classes> 
    <class name="TestScripts.NewSamplePage" > 
     <methods> 
      <include name = "NewSamplePage_Execution02"/> 
     </methods> 
     </class> 
    </classes> 
    </test> 
</suite> 

मैं सिर्फ test.xml फ़ाइल के माध्यम से pom.xml से SamplePage_Execution विधि को कॉल करना चाहता था।

मेरे SamplePage_Execution विधि

public class sample{ 
    @Test 
    public static void SamplePageTest_Execution() throws Exception{ 

String methodName = Thread.currentThread().getStackTrace()[1].getMethodName(); 
boolean testStatus = true; 
     driver = new FirefoxDriver(); 
     driver.get("http://www.google.com"); 

    WebElement searchField = driver.findElement(By.name("q")); 

    searchField.sendKeys(new String [] {"selenium2.0"}); 

    searchField.submit(); 

    driver.close(); 
}} 
+0

कमांड लाइन से testng.xml लागू Maven परीक्षण चला सकते हैं मेरे निम्नलिखित कोड काम नहीं करता: <विन्यास> testng.xml नीचे दिया गया कोड ठीक काम करता है: <विन्यास> **/* ST.java नोट: मेरा सेलेनियम जावा कोड नाम है: Selenium2ExampleST.java –

उत्तर

2

आप के बजाय उदाहरण testng.xml फ़ाइल जो src/परीक्षण/संसाधनों में स्थित है के लिए एक फ़ाइल के लिए एक कक्षा से suiteXmlFile बदलना चाहिए है। इसके अलावा surefire-plugin (वर्तमान संस्करण 2.12) अद्यतन करें। एक और बात यह है कि सेलेनियम परीक्षण आमतौर पर एकीकरण परीक्षण होते हैं न कि यूनिट परीक्षण।

अद्यतन आपको जूनिट निर्भरता के बजाय टेस्टिंग निर्भरता जोड़नी है। तो जूनिट निर्भरता को हटाएं और maven-surefire-plugin के दस्तावेज़ीकरण के अनुसार testng निर्भरता जोड़ें।

+0

मैं दोनों चीजें बदल लेकिन मैं समाधान नहीं मिला । क्या आप इसे अधिक विस्तृत रूप से समझाएंगे। – Manigandan

+0

इसका क्या अर्थ है? क्या आपको एक त्रुटि संदेश मिला? क्या आपने 2.12 पर मेवेन-सिक्योरफायर-प्लगइन अपडेट किया है? आप testng.xml फ़ाइल कहां स्थित है? – khmarbaise

+0

नहीं, मुझे कोई त्रुटि संदेश नहीं मिला। असल में, मेरे पास "src/test/java" निर्देशिका में testng class है। जैसा कि मैंने पहले उल्लेख किया था, जबकि मैं pom.xml फ़ाइल चला रहा हूं, यह सीधे testng क्लास फ़ाइल निष्पादित करता है और यह ठीक चलता है। लेकिन मैं testng.xml फ़ाइल का उपयोग करके उस testng क्लास फ़ाइल को चलाने के लिए चाहता हूं और testng.xml फ़ाइल को pom.xml के माध्यम से बुलाया जाना चाहिए .. और मैंने maven-surfire-plugin को 2.12 पर भी अपडेट किया। – Manigandan

8

pom.xml में मेरे निम्न कोड में अच्छी तरह से काम कर रहा है:

mvn clean test -U -Pselenium-tests 

या,

mvn clean test 
+0

कॉन्फ़िगरेशन के तहत suiteXmlFile लाइन जोड़ना मेरे लिए काम करता है। धन्यवाद। – newuser

+0

बहुत बहुत धन्यवाद, newuser –

0

मैं वहाँ लगता है: निम्न आदेश का उपयोग करके

<profiles> 
    <profile> 
     <id>selenium-tests</id> 
     <build> 
     <plugins> 
      <plugin> 
       <groupId>org.apache.maven.plugins</groupId> 
       <artifactId>maven-surefire-plugin</artifactId> 
       <version>2.12.4</version> 
       <configuration> 
        <suiteXmlFiles> 
        <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
        </suiteXmlFiles> 
       </configuration> 
      </plugin>  
     </plugins> 
     </build> 
    </profile> 
</profiles> 

परीक्षण चलाएं यहां बुनियादी गलतियां हैं .. pom.xml = पैकेज परिभाषा जो बनाए रखती है एड द्वारा मेवेन

और test.xml (कोई भी XML उपयोगकर्ता परिभाषित कर सकता है) टेस्टएनजी परीक्षण परिभाषा के लिए उपयोग किया जाता है। या तो आप एक्सएमएल कॉन्फ़िगरेशन का उपयोग टेस्ट एनजी चलाने के लिए कस्टम रन सेटिंग्स से स्वयं कॉन्फ़िगरेशन कर सकते हैं और, एक्सएमएल फ़ाइल (टेस्ट नाम, श्रोता वर्ग का नाम, सूट नाम या कक्षा का नाम) में प्रदान की गई कॉन्फ़िगरेशन मुझे आपके टेस्ट क्लास से मेल खाना चाहिए । जैसा कि आपने क्लास नाम = testScripts.SamplePage को अस्वीकार कर दिया है, लेकिन आपकी टेस्ट क्लास = नमूना है, इसलिए यह एक्सएमएल कभी भी आपकी टेस्ट क्लास नहीं चलाएगा। छोटा उदाहरण: <class name="com.automation.test.TestA" /> यह मेरे परीक्षण एक्सएमएल में है और मेरी टेस्ट क्लास टेस्टए होगी।

0

आप सीधे बजाय testng.xml src/परीक्षण/संसाधन/testng.xml

मेरे pom.xml ठीक काम कर रहा है दे सकते हैं। इसे अपने POM.xml से बदलें। अपने मैवेन को अपडेट करें और फिर से चलाएं।भाग्य :) के सर्वश्रेष्ठ

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>Automation</groupId> 
    <artifactId>Automation</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.3</version> 
     <configuration> 
      <source>1.8</source> 
      <target>1.8</target> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.18.1</version> 
     <configuration> 
      <forkCount>0</forkCount> 
      <suiteXmlFiles> 
      <suiteXmlFile>testng.xml</suiteXmlFile> 
      </suiteXmlFiles> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    <dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.46.0</version> 
    </dependency> 
    <dependency> 
     <groupId>javax.mail</groupId> 
     <artifactId>mail</artifactId> 
     <version>1.5.0-b01</version> 
    </dependency> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <version>6.9.6</version> 
    </dependency> 
    </dependencies> 
</project> 
0
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 
    <modelVersion>4.0.0</modelVersion> 
    <groupId>com.adiltutorials.facebook</groupId> 
    <artifactId>WebdriverTests</artifactId> 
    <version>0.0.1-SNAPSHOT</version> 
    <build> 
    <plugins> 
     <plugin> 
     <artifactId>maven-compiler-plugin</artifactId> 
     <version>3.3</version> 
     <configuration> 
      <source>1.8</source> 
      <target>1.8</target> 
     </configuration> 
     </plugin> 
     <plugin> 
     <groupId>org.apache.maven.plugins</groupId> 
     <artifactId>maven-surefire-plugin</artifactId> 
     <version>2.19.1</version> 
     <configuration> 
      <forkCount>0</forkCount> 
      <suiteXmlFiles> 
      <suiteXmlFile>src/test/resources/testng.xml</suiteXmlFile> 
      </suiteXmlFiles> 
     </configuration> 
     </plugin> 
    </plugins> 
    </build> 
    <dependencies> 
    <dependency> 
     <groupId>org.seleniumhq.selenium</groupId> 
     <artifactId>selenium-java</artifactId> 
     <version>2.52.0</version> 
    </dependency> 
    <dependency> 
    <groupId>org.testng</groupId> 
    <artifactId>testng</artifactId> 
    <version>6.8</version> 
</dependency> 
</dependencies> 

</project> 
+0

यह इसे हल करेगा –

2

आप के माध्यम से सीधे

mvn test -Dsurefire.suiteXmlFiles=src/test/resources/testng.xml 
+0

सरल और आसान समाधान –

संबंधित मुद्दे