Right now, I'm trying to work on my first test that will test browsers Chrome, Firefox, IE, and Safari in parallel. But the following error that I'm getting is this:
FAILED CONFIGURATION: @BeforeMethod beforeMethod org.testng.TestNGException: Parameter 'browser' is required by @Configuration on method beforeMethod but >has not been marked @Optional or defined
I'm using Selenium, TestNG and Maven with the JAVA language. The XML test suite file and the java file are in the same folder in the directory. What I was able to find for the test suite XML file online is as follows (with 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 just open the browser to make sure that it will run and pass:
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(); } }
If anyone can give me an insight as to what is causing this issue, I would greatly appreciate it. Thank you.
No comments:
Post a Comment