0

Selenium Web Driver で継承を実装しようとしました。Countrychoser クラスで、Baseurl クラスから Basic() メソッドを呼び出しました。TestNG で実行しようとすると、Browser が 2 回呼び出されました。しかし、TestNG.xml では、Countrychoser クラスについてのみ言及しました。

Baseurl.java

package MyTestNG;

import org.testng.annotations.BeforeSuite;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.Test;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;


public class Baseurl {
    public static WebDriver driver;
    @Test
    public static void basic()
    {
    driver = new FirefoxDriver();
    driver.manage().deleteAllCookies();
    driver.get("http://www.sears.com/shc/s/CountryChooserView?storeId=10153&catalogId=12605");
    }
    public static void Closebrowser()
    {
        driver.quit();
    }
}

Countrychoser.java

package MyTestNG;

import org.testng.annotations.*;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import com.thoughtworks.selenium.Selenium;
import org.openqa.selenium.support.ui.Select;
import java.util.*;
import java.io.*;

public class Countrychoser extends Baseurl 
{
@Test
    public static void Choser()
    {
    try
    {

    Baseurl.basic();
    //driver.findElement(By.className("box_countryChooser")).click();
    driver.findElement(By.id("intselect")).sendKeys("India");
    driver.findElement(By.xpath(".//*[@id='countryChooser']/a/img")).click();
    //window.onbeforeunload = null;
    System.out.println("---------------------------------------");
    System.out.println("Country choser layer test case-Success");
    System.out.println("---------------------------------------");
        }


    catch(Exception e) 
    {
           Screenshot.pageScreenshot();
           System.out.println(e);
            System.out.println("---------------------------------------");
            System.out.println("Country choser layer test case Failed");
            System.out.println("---------------------------------------");
          }

    finally {

           Screenshot.pageScreenshot();  
           Baseurl.Closebrowser();
          }
    }
}

TestNG.xml

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Suite1" verbose="1" >

  <test name="First" >
    <classes>
       <class name="MyTestNG.Countrychoser" />
    </classes>
  </test> 
  </suite>
4

1 に答える 1

1

あなたのCountrychoserクラスは extendsBaseurlであるため、今ではBaseurlあまりにも多く、正当にbasic()テストメソッドとして注釈が付けられたメソッドを持っています。

したがって、basic()実行リストに入れます。メソッドを再度Choser()呼び出すメソッドも(予想どおり)同様に実行されるため、合計で2回実行されます。basic()basic()

それを避けるには、 の注釈を継承しないかBaseurl、削除します。おそらく、提供する(そしてテスト メソッドを持たない)親クラスを持ち、それを and に継承することができます(これら 2 つは兄弟です)。@Testbasic()driverBaseCountrychoser

于 2013-06-04T23:00:01.550 に答える