Testing browsers at the same time; reception error

Now I am trying to work on my first test, which will check Chrome, Firefox, IE and Safari browsers in parallel. But the following error I get is this:

CONFIGURATION FAULT: @BeforeMethod beforeMethod org.testng.TestNGException: The 'browser' parameter is required by @Configuration by the beforeMethod method, but> was not checked by @Optional or defined

I use Selenium, TestNG and Maven with the JAVA language. The XML test case file and the java file are in the same folder in the directory. What I could find for the XML test case file on the Internet looks like this (with the class name values ​​set to the correct package and class name):

<?xml version="1.0" encoding="UTF-8"?>
<DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" thread-count="2" parallel="tests">
 <test name="ChromeTest">
  <parameter name="browser" value="chrome" />
    <classes>
        <class name="com.sqa.ts.multiBrowser.BrowserTest">
        </class>
    </classes>
 </test>
 <test name="FirefoxTest">
    <parameter name="browser" value="firefox" />
    <classes>
        <class name="com.sqa.ts.multiBrowser.BrowserTest">
        </class>
    </classes>  
 </test>
 <test name="IETest">
    <parameter name="browser" value="ie" />
     <classes>
        <class name="com.sqa.ts.multiBrowser.BrowserTest">
        </class>
     </classes>
 </test>
 <test name="SafariTest">
    <parameter name="browser" value="safari" />
    <classes>
        <class name="com.sqa.ts.multiBrowser.BrowserTest">
        </class>
    </classes>
 </test>
</suite>

Below is my code to open the browser to make sure it starts and passes:

package com.sqa.ts.multiBrowser;

import java.net.MalformedURLException;

import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.safari.SafariDriver;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Parameters;
import org.testng.annotations.Test;

public class BrowserTest {

  private WebDriver driver;

  @Test
  public void testCaseOne() {
    driver.get("http://www.google.com");
    driver.close();
  } 

  @BeforeMethod
  @Parameters("browser")
  public void beforeMethod(String browser) throws MalformedURLException {
    if (browser.equalsIgnoreCase("chrome")) {
        System.setProperty("webdriver.chrome.driver", "C:/Users/Trevor/workspace/BrowserTest/drivers/chromedriver.exe");
        driver = new ChromeDriver();

    } else if (browser.equalsIgnoreCase("firefox")) {
        driver = new FirefoxDriver();

    } else if (browser.equalsIgnoreCase("ie")) {
        System.setProperty("webdriver.ie.driver", "C:/Users/Trevor/workspace/BrowserTest/drivers/IEDriverServer.exe");
        driver = new InternetExplorerDriver();

    } else if (browser.equalsIgnoreCase("safari")) {
        driver = new SafariDriver();
    }
}

  @AfterMethod
  public void afterMethod() {
    driver.quit();
  }

}

- , , . .

+4
3

, testNG pom.xml

<build>
    <plugins>
        <!-- Following plugin executes the testng tests -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.19</version>
            <configuration>
                <!-- Suite testng xml file to consider for test execution -->
                <suiteXmlFiles>
                    <suiteXmlFile>src/test/java/com/sqa/ts/multiBrowser/testng.xml</suiteXmlFile>
                </suiteXmlFiles>
            </configuration>
        </plugin>
</build>

mvn clean install mvn clean install . , .

0

XML " > Testng Suite". .

0

= Run as > Testng Suite

0

Source: https://habr.com/ru/post/1617668/


All Articles