문제

나는 온라인으로 많은 가이드와 포럼 게시물을 따랐지만 TestNG 에서이 작업을 수행하는 데 운이 좋지 않았습니다. 일식으로 프로그래밍 된 셀레늄 그리드 기반 테스트입니다. 문제가 있었기 때문에이 포럼 게시물의 제안에 나열된 도서관을 사용했습니다. http://clearspace.openqa.org/message/66867

Eclipse (org.testng.eclipse) 용 TestNG 테스트 플러그인에서 스위트를 실행하려고합니다. 또한 셀레늄 그리드를 통해 명령 줄에서 항아리를 실행하려고 시도했습니다.

나는 Java 개발자가 아니기 때문에 솔직히 말해서 무엇을 찾아야하는지 확실하지 않습니다. 처리 환경 덕분에 Java에 대해 친숙하지만,이 작업을 위해 Java/Eclipse에 던져졌으며 약간의 손실이 있습니다. 어쨌든, 모든 도움이 감사하며 미리 감사드립니다.

내 코드는 다음과 같습니다.

Suite.java :

    package seleniumRC;
//import com.thoughtworks.selenium.*;
//import junit.framework.*;
//import java.util.regex.Pattern; 

//import static org.testng.AssertJUnit.assertTrue;
 //import org.testng.annotations.AfterMethod;
//import org.testng.annotations.BeforeMethod;
//import org.testng.annotations.Parameters;
import org.testng.annotations.Test;


public class suite extends Testcase1 {

@Test(groups = {"example", "firefox", "default"}, description = "test1")
    public void user1() throws Throwable {   
     testCase1();
    }

@Test(groups = {"example", "firefox", "default"}, description = "test2")
    public void user2() throws Throwable {

     testCase1();
    }

} 

실제 테스트 케이스

    package seleniumRC;

//import com.thoughtworks.selenium.*;
//import org.testng.annotations.*;
//import static org.testng.Assert.*;
//import com.thoughtworks.selenium.grid.demo.*;
//import junit.framework.*;
//import com.ibm.icu.*;
//import java.util.regex.Pattern; 

//import static org.testng.AssertJUnit.assertTrue;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;


public class Testcase1 extends SeleneseTestNgHelper {

 private static int $itter = 10;

 public static void main(String args[]) {
  //junit.textui.TestRunner.run(Suite());
 } 

//public static Test Suite() {
 // return new TestSuite(Testcase1.class);
 //}

// public void setUp() throws Exception {
//  setUp("http://localhost:8080/test", "*firefox");
 //}
 @BeforeMethod(groups = {"default", "example"}, alwaysRun = true)
     @Parameters({"seleniumHost", "seleniumPort", "browser", "webSite"})
     protected void startSession(String seleniumHost, int seleniumPort, String browser, String webSite) throws Exception {
         startSession(seleniumHost, seleniumPort, browser, webSite);
         selenium.setTimeout("120000");
     }

@AfterMethod(groups = {"default", "example"}, alwaysRun = true)
     protected void closeSession() throws Exception {
         closeSession();
     }


 public void testCase1() throws Exception {
  selenium.open("/login.action#login");
  selenium.type("userName", "foo");
  selenium.type("password", "bar");
  selenium.click("login");
  selenium.waitForPageToLoad("30000");
  selenium.click("link=test");
  Thread.sleep(4000);
  selenium.click("//tr[4]/td[1]/a");

  if(selenium.isElementPresent("//input[@id='nextButton']") != false){
  selenium.click("//div[2]/input");
  }
  Thread.sleep(2000);

  for(int i=0; i < $itter; i++) {
  if(selenium.isElementPresent("//label") != false){

    selenium.click("//label");
    selenium.click("submitButton");
    Thread.sleep(1500);
  }
  else{ Thread.sleep(1500);}
  }

   selenium.click("//body/div[2]/div[1]/div/a");
   Thread.sleep(1500);
   selenium.click("//a[contains(text(),'Finish Now')]");


  Thread.sleep(2000);
  selenium.click("link=View Results");
  Thread.sleep(30000);
  selenium.click("showAllImgCaption");
  Thread.sleep(12000);
  selenium.click("generateTimeButton");
  Thread.sleep(2000);
  selenium.click("link=Logout");
  selenium.waitForPageToLoad("15000");
 }
 }

그리고 Selenesetestnghelper 클래스

   package seleniumRC;

import java.lang.reflect.Method;
//import java.net.BindException;

import com.thoughtworks.selenium.*;

//import org.openqa.selenium.SeleniumTestEnvironment;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebDriverBackedSelenium;
//import org.openqa.selenium.environment.GlobalTestEnvironment;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Optional;
import org.testng.annotations.Parameters;

public class SeleneseTestNgHelper extends SeleneseTestCase
{
    private static Selenium staticSelenium;

    @BeforeTest
    @Override
    @Parameters({"selenium.url", "selenium.browser"})
    public void setUp(@Optional String url, @Optional String browserString) throws Exception {
        if (browserString == null) browserString = runtimeBrowserString();

        WebDriver driver = null;
        if (browserString.contains("firefox") || browserString.contains("chrome")) {
          System.setProperty("webdriver.firefox.development", "true");
          driver = new FirefoxDriver();
        } else if (browserString.contains("ie") || browserString.contains("hta")) {
          driver = new InternetExplorerDriver();
        } else {
          fail("Cannot determine which browser to load: " + browserString);
        }

        if (url == null)
          url = "http://localhost:4444/selenium-server";
        selenium = new WebDriverBackedSelenium(driver, url);

        staticSelenium = selenium;
    }

    @BeforeClass
    @Parameters({"selenium.restartSession"})
    public void getSelenium(@Optional("false") boolean restartSession) {
        selenium = staticSelenium;
        if (restartSession) {
            selenium.stop();
            selenium.start();
        }
    }

    @BeforeMethod
    public void setTestContext(Method method) {
        selenium.setContext(method.getDeclaringClass().getSimpleName() + "." + method.getName());

    }

    @AfterMethod
    @Override
    public void checkForVerificationErrors() {
        super.checkForVerificationErrors();
    }

    @AfterMethod(alwaysRun=true)
    public void selectDefaultWindow() {
        if (selenium != null) selenium.selectWindow("null");
    }

    @AfterTest(alwaysRun=true)
    @Override
    public void tearDown() throws Exception {
//        super.tearDown();
    }

    //@Override static method of super class (which assumes JUnit conventions)
    public static void assertEquals(Object actual, Object expected) {
        SeleneseTestBase.assertEquals(expected, actual);
    }

    //@Override static method of super class (which assumes JUnit conventions)
    public static void assertEquals(String actual, String expected) {
        SeleneseTestBase.assertEquals(expected, actual);
    }

    //@Override static method of super class (which assumes JUnit conventions)
    public static void assertEquals(String actual, String[] expected) {
        SeleneseTestBase.assertEquals(expected, actual);
    }

    //@Override static method of super class (which assumes JUnit conventions)
    public static void assertEquals(String[] actual, String[] expected) {
        SeleneseTestBase.assertEquals(expected, actual);
    }

    //@Override static method of super class (which assumes JUnit conventions)
    public static boolean seleniumEquals(Object actual, Object expected) {
        return SeleneseTestBase.seleniumEquals(expected, actual);
    }

    //@Override static method of super class (which assumes JUnit conventions)
    public static boolean seleniumEquals(String actual, String expected) {
        return SeleneseTestBase.seleniumEquals(expected, actual);
    }

    @Override
    public void verifyEquals(Object actual, Object expected) {
        super.verifyEquals(expected, actual);
    }

    @Override
    public void verifyEquals(String[] actual, String[] expected) {
        super.verifyEquals(expected, actual);
    }
}
도움이 되었습니까?

해결책

그래서 나는 seleniumtestnghelper 클래스를 떨어 뜨리고 개미 파일을 통해 클래스 경로를 재 작업함으로써 이것을 해결했습니다. 스위트/원본 테스트 케이스를 완전히 작동시켜야했지만 그리드 내에서 잘 작동했습니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top