簡體   English   中英

測試確實在本地工作的硒網格上正確運行)

[英]Test does run on the selenium grid in local works correctly)

我正在嘗試在硒GRID中運行以下代碼(執行“本地”代碼,可以正常工作),並遵循以下代碼段:

SuiteTest.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="SuiteTest" verbose="1" thread-count="2" parallel="tests"> 
        <test name="FIREFOX Test">
        <parameter name="browser" value="FIREFOX" />
        <classes>
            <class name="test.CN01_CT01_IncluirConteudoMP3" />
            <class name="test.CN01_CT02_IncluirConteudoMP4" />
        </classes>
    </test>

        <test name="CHROME Test">
        <parameter name="browser" value="CHROME" />
        <classes>
            <class name="test.CN01_CT01_IncluirConteudoMP3" />
            <class name="test.CN01_CT02_IncluirConteudoMP4" />
        </classes>
    </test>         
</suite>

基本測試:

public class BaseTest {

    protected static ExtentReports extent;
    public static String testName;

    @Parameters({ "browser" })
    @BeforeMethod
    public void BeforeTest(Method method, Browsers browser) throws IOException, BiffException {

        Propriedades.browser = browser;
        String browserStr = browser.toString();         
        System.out.println("Before ........" + method.getName());       
        //Recuperar nome do Teste
        testName = method.getName() + "-" + browserStr;     
        // Realizando Login
        LoginPage.realizarLogin();    
        //Iniciar o relatorio
        extent = ExtentReport.StartReport(testName);

    }

    @AfterMethod
    public void finaliza(ITestResult result) throws IOException {
        System.out.println("After ........");

        //Validar Resultado dos Testes
        ExtentReport.ResultTest(result, testName);

        // Realizar Logout
        LoginPage.realizarLogout();

        // Fechando Browser
        if (Propriedades.FECHAR_BROWSER) {
            killDriver();
        }
    }

    @AfterSuite
    public static void finalizaTudo(){
        DriverFactory.killDriver();
        extent.flush();
        System.out.println("AfterSuite........");
        System.out.println(ExtentReport.diretorioReport);
        //DriverFactory.executeChrome(ExtentReport.diretorioReport);
    }

}

基本頁:

public class BasePage {

    protected static DSL dsl;

    static List<String> result = Ambiente.dadosAmbiente();
    static String url = result.get(0);
    protected static String user = result.get(1);
    protected static String pass = result.get(2);

    public BasePage() {
        dsl = new DSL();
    }

}

DSL:

public class DSL {

    public void clicarRadio(By by) {
        getDriver().findElement(by).click();
    }   

Other methods to access the screen elements (Text, Click, Button, Radio, Combo and etc.)

(...)

}

DriveFactory:

public class DriverFactory {

    static WebDriver driver;

    private DriverFactory() {
    }

    public static WebDriver getDriver() {           

        if(Propriedades.tipoExecucao == TipoExecucao.LOCAL){

                if (driver == null) {
                    switch (Propriedades.browser) {
                    case CHROME:
                        executeChrome(BasePage.url);
                        break;
                    case FIREFOX:
                        executeFirefox(BasePage.url);
                        break;
                    case IE:
                        executeIE(BasePage.url);
                        break;
                    case EDGE:
                        executeEgde(BasePage.url);
                        break;
                    }
                    driver.manage().window().maximize();
                }
        }

        if(Propriedades.tipoExecucao == TipoExecucao.GRID) {

            DesiredCapabilities cap = null;
                switch (Propriedades.browser) {
                case CHROME:
                    cap = DesiredCapabilities.chrome();
                    break;
                case FIREFOX:
                    cap = DesiredCapabilities.firefox();
                    break;
                case IE:
                    cap = DesiredCapabilities.internetExplorer();
                    break;
                case EDGE:
                    cap = DesiredCapabilities.edge();
                    break;
                }

                try {
                    driver = new RemoteWebDriver(new URL("http://192.168.0.72:4444/wd/hub"), cap);
                } catch (MalformedURLException e) {
                    System.err.println("Falha ao conectar ao GRID");
                }
                driver.manage().window().maximize();
                driver.get(BasePage.url);
                System.out.println("Abriu Browser Grid");
    }

        return driver;
}

    public static void killDriver() {
        if (driver != null) {
            driver.close();
            driver.quit();          
            driver = null;
        }
    }
}

測試-班級:

測試類,僅用於檢查執行是否正在登錄和注銷。

@Test
public void CN01_CT02_IncluirConteudoMp4(){

assertEquals("123", "123");
}

@Test

public void CN01_CT01_IncluirConteudoMp3() throws InterruptedException, AWTException{

assertEquals("123", "123456");
}

配置網格

Config(Json)-集線器:

{
  "port": 4444,
  "newSessionWaitTimeout": -1,
  "servlets" : [],
  "withoutServlets": [],
  "custom": {},
  "capabilityMatcher": "org.openqa.grid.internal.utils.DefaultCapabilityMatcher",
  "registry": "org.openqa.grid.internal.DefaultGridRegistry",
  "throwOnCapabilityNotPresent": true,
  "cleanUpCycle": 5000,
  "role": "hub",
  "debug": false,
  "browserTimeout": 0,
  "timeout": 1800
}

NodeChrome:

{
    "capabilities": [
        {
            "browserName": "chrome",
            "maxInstances": 1,
            "webdriver.chrome.driver": "C:/Program Files (x86)/Google/Chrome/Application/chrome.exe"
        }
    ],
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 1,
    "port": 5555,
    "register": true,
    "registerCycle": 5000,
    "hub": "http://192.168.0.72:4444",
    "nodeStatusCheckTimeout": 5000,
    "nodePolling": 5000,
    "role": "node",
    "unregisterIfStillDownAfter": 60000,
    "downPollingLimit": 1,
    "debug": false,
    "servlets": [
    ],
    "withoutServlets": [

    ],
    "custom": {
    }
}

NodeFirefox:

{
    "capabilities": [
        {
            "browserName": "firefox",
            "maxInstances": 1,
            "webdriver.gecko.driver": "C:/Program Files/Mozilla Firefox/firefox.exe"
        }
    ],
    "proxy": "org.openqa.grid.selenium.proxy.DefaultRemoteProxy",
    "maxSession": 1,
    "port": 5556,
    "register": true,
    "registerCycle": 5000,
    "hub": "http://192.168.0.72:4444",
    "nodeStatusCheckTimeout": 5000,
    "nodePolling": 5000,
    "role": "node",
    "unregisterIfStillDownAfter": 60000,
    "downPollingLimit": 1,
    "debug": false,
    "servlets": [

    ],
    "withoutServlets": [

    ],
    "custom": {
    }
}

使用Selenium GRID執行代碼時,系統打開兩個瀏覽器,但沒有登錄,就會出現問題(顯然是同步問題)。

例:

登錄字段填寫“兩次”,並返回“無效登錄”。

使用Eclipse IDE執行代碼。 運行(SuiteTest.xml)-使用TestNG運行

問題出在您的測試代碼上。 DriverFactory是在初始化靜態數據成員driver 現在,當您通過套件xml文件並行運行測試時,您的測試之間確實存在競爭,最終覆蓋了靜態數據成員。 您需要重構測試代碼。 在這里,Selenium Grid或TestNG都沒有問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM