Невозможно запустить тест на селен параллельно из виртуально созданного testng.xml с использованием сетки селена

Я использовал веб-драйвер Selenium + TestNG для параллельного запуска тестов на селен. Я использовал три класса

Первый класс (основной класс):

С этого класса я собираюсь начать тест. Отправная точка моей казни.

 public class MainClass {

public WebDriver driver = null;

public void gid() {

    try {
        CreateTestngXml.gridHubLaunching();
        Thread.sleep(10000);
    } catch (IOException | InterruptedException e) {
        e.printStackTrace();
    }

    CreateTestngXml.grid("firefox", "chrome");
    driver.close();
}

public static void main(String a[]) {
    MainClass ts = new MainClass();
    try{
    ts.gid();
    }catch(Exception e){
        e.printStackTrace();
    }
}
}

Второй класс (CreateTestngXml):

public class CreateTestngXml {

/**
 * 
 * @param Brow
 * @param Brows
 * @code = To create a TestNg XML suite file and run it.
 */
public static void grid(String Brow, String Brows) {

    XmlSuite suite = new XmlSuite();
    suite.setName("Compatability");
    suite.setVerbose(1);
    suite.setPreserveOrder("true");
    suite.setThreadCount(4);
    suite.setParallel("tests");
    suite.setTimeOut("5000");

    // Test
    XmlTest test = new XmlTest(suite);
    test.setName("Browser One");
    test.addParameter("Browser", Brow);

    XmlTest testOne = new XmlTest(suite);
    testOne.setName("Browser Two");
    testOne.addParameter("Browser", Brows);

    List<XmlTest> tests = new ArrayList<XmlTest>();
    tests.add(test);
    tests.add(testOne);

    // Class
    List<XmlClass> classes = new ArrayList<XmlClass>();
    classes.add(new XmlClass("Grid.CheckGridOne"));
    test.setXmlClasses(classes);
    testOne.setXmlClasses(classes);

    suite.setTests(tests);

    // Suite
    List<XmlSuite> suites = new ArrayList<XmlSuite>();
    suites.add(suite);
    TestNG tng = new TestNG();
    tng.setXmlSuites(suites);
    try {
        // Running the Suite file.
        tng.run();
    } catch (Exception e) {
        e.printStackTrace();
    }

}

/**
 * 
 * @throws IOException
 * @throws InterruptedException
 * @code = To launch the Grid Hub and Nodes
 */
public static void gridHubLaunching() throws IOException,
        InterruptedException {

    // Launching nodes for each browser.
    String[] hub = new String[] { "C:\\Windows\\System32\\cmd.exe", "/c",
            "Start", "Grid-BatchFiles\\hub.bat" };
    String[] firefox = new String[] { "C:\\Windows\\System32\\cmd.exe",
            "/c", "Start", "Grid-BatchFiles\\firefox.bat" };
    String[] chrome = new String[] { "C:\\Windows\\System32\\cmd.exe",
            "/c", "Start", "Grid-BatchFiles\\chrome.bat" };
    String[] ie = new String[] { "C:\\Windows\\System32\\cmd.exe", "/c",
            "Start", "Grid-BatchFiles\\IE.bat" };
    Runtime.getRuntime().exec(hub);
    Thread.sleep(3000);
    Runtime.getRuntime().exec(firefox);
    Runtime.getRuntime().exec(chrome);
    Runtime.getRuntime().exec(ie);
}

  }

gridHubLaunching() используется для запуска концентратора и соответствующих узлов браузера. Нет проблем с созданием узлов. Я обеспечил создание, используя http://localhost:4444/grid/console

Третий класс (Grid.CheckGridOne):

    public class CheckGridOne {

MainClass ts = new MainClass();
WebDriver driver = ts.driver;

DesiredCapabilities capability = null;

/**
 * 
 * @param Browser
 * @throws Exception
 * @code = To launch a Browser for Compatibility Testing purpose.
 */

@Test
@Parameters({ "Browser" })
public void browserLaunch(String Browser) throws Exception {

    // Checking condition for a Firefox.
    if (Browser.equalsIgnoreCase("firefox")) {
        System.out.println("Firefox");

        capability = DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);

        URL url = new URL(`http://lo***st:4444/wd/hub`);
        System.out.println("testing");
        driver = new RemoteWebDriver(url, capability);

        System.out.println("test");
    }

    // Checking condition for a iexplorer.
    if (Browser.equalsIgnoreCase("iexplorer")) {
        System.out.println("IE");

        System.setProperty(
                "webdriver.ie.driver",
                "E:\\FW\\Test-2.28.0(Feb-18)\\IEDriverServer\\64-Bit\\IEDriverServer.exe");

        capability = DesiredCapabilities.internetExplorer();
        capability.setBrowserName("internet explorer");
        capability.setPlatform(org.openqa.selenium.Platform.ANY);
        System.out.println("testing");
        driver = new RemoteWebDriver(new URL(
                    `http://lo***st:4444/wd/hub`), capability);
        System.out.println("test");
    }

    // Checking condition for a chrome.
    if (Browser.equalsIgnoreCase("chrome")) {
        System.out.println("chrome");

    }   
}
   }

Используя три вышеуказанных класса, я попытался запустить тесты на селен параллельно. Моя проблема в том, что он работает нормально, прежде чем достигнет driver = new RemoteWebDriver(url, capability); в третьем классе. Как только он достигает линии, он завершает TestNG suite file. Я не знаю, в чем проблема с моим кодом?

Вывод:

  [TestNG] Running:
  Command line suite

 Firefox
 IE
 testing
 testing

 ===============================================
 Compatability
 Total tests run: 0, Failures: 0, Skips: 0
 ===============================================

 test
 test

Выходные данные показывают общий тестовый запуск как 0. Я не знаю, почему это так.

Selenium Server - 2.28.0
TestNG - 6.1.1 и 6.8
IEDriverServer - 2.28.0

Я знаю, что вопрос непростой. Я подумал, что это правильный способ ясно объяснить. Любая помощь будет оценена.


person Manigandan    schedule 21.02.2013    source источник
comment
ты уверен, что эта часть работает? classes.add(new XmlClass("Grid.CheckGridOne")); т.е. добавление тестовых классов в testng xml, вы можете опубликовать свой вывод testng xml   -  person StaleElementException    schedule 25.02.2013
comment
Ага. Вышеупомянутый работает нормально. Он может вызывать метод @Test внутри класса. XML-файл создается во время выполнения. Таким образом, невозможно увидеть XML-файл извне. Если вам нужно, я могу опубликовать, как он может создать файл XML.   -  person Manigandan    schedule 26.02.2013
comment
Я думаю, вы можете увидеть созданный XML-файл в папке / test-output   -  person StaleElementException    schedule 26.02.2013
comment
@Stale: я не видел там никаких файлов пакета XML.   -  person Manigandan    schedule 26.02.2013
comment
вы видите папку test-output \ old \ Compatability?   -  person StaleElementException    schedule 26.02.2013


Ответы (1)


€ DIT: Почему вы снова звоните из 3-го класса обратно в первый? Это похоже на петлю.

Просто определите свой WebDriver в своем 3-м классе.

public class CheckGridOne {

@Test
@Parameters({ "Browser" })
public void browserLaunch(String Browser) throws Exception {

WebDriver driver = null;

    // Checking condition for a Firefox.
    if (Browser.equalsIgnoreCase("firefox")) {
        System.out.println("Firefox");

        capability = DesiredCapabilities.firefox();
        capability.setBrowserName("firefox");
        capability.setPlatform(org.openqa.selenium.Platform.WINDOWS);

        URL url = new URL(`http://lo***st:4444/wd/hub`);
        System.out.println("testing");
        driver = new RemoteWebDriver(url, capability);

        System.out.println("test");
    }

    // Checking condition for a iexplorer.
    if (Browser.equalsIgnoreCase("iexplorer")) {
        System.out.println("IE");

        System.setProperty(
                "webdriver.ie.driver",
                "E:\\EproNewFW\\SWIFTest-2.28.0(Feb-18)\\IEDriverServer\\64-Bit\\IEDriverServer.exe");

        capability = DesiredCapabilities.internetExplorer();
        capability.setBrowserName("internet explorer");
        capability.setPlatform(org.openqa.selenium.Platform.ANY);
        System.out.println("testing");
        driver = new RemoteWebDriver(new URL(
                    `http://lo***st:4444/wd/hub`), capability);
        System.out.println("test");
    }

    // Checking condition for a chrome.
    if (Browser.equalsIgnoreCase("chrome")) {
        System.out.println("chrome");

    }   
}
   }
person arket    schedule 04.03.2013