Get parameters using @Parameter

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Get parameters using @Parameter

yueliu
This post has NOT been accepted by the mailing list yet.
Hi,
I want to provide two method "PrepareDB" and "StartSession" parameters using @Parameter. But I kept coming across below problem. Could you please provide some solutions to solve it? Thanks.

On running testng.xml I am getting the below exception:
 org.testng.TestNGException:
 Parameter 'db_url' is required by @Configuration on method PrepareDB but has not been marked @Optional or defined in D:\WorkSpaces\SeleniumTestProject\testng.xml

testng.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="ChromeSuite" parallel="none">
  <parameters name="db_url" value="s1db-master.dev.usher.com:3308"/>
  <parameters name="db_user" value="uvs"/>
  <parameters name="db_pwd" value="IwI5e0+fWOum"/>
  <parameters name="email" value="yuliu@microstrategy.com"/>
  <parameters name="pwd" value="123456"/>
  <parameters name="platform" value="XP"/>
  <parameters name="browser" value="chrome"/>
  <parameters name="version" value="22"/>
  <parameters name="adminPortal" value="https://usherpro:18443/adminportal"/>
  <parameters name="hub" value="http://10.199.46.155:4441/wd/hub"/>
  <test name="LoginTest">
    <classes>
      <class name="com.mstr.usherpro.adminportal.testsuites.PositiveLogin"/>
    </classes>
  </test> 
</suite> 

PositiveLogin.java
@BeforeTest
        @Parameters({"db_url","db_user","db_pwd","email","pwd"})
        public void PrepareDB(String db_url,String db_user,String db_pwd, String email, String pwd) throws MalformedURLException {
                u = new User(email, pwd);
                try {
                        Class.forName("com.mysql.jdbc.Driver");
                        con = (Connection) DriverManager.getConnection(db_url, db_user, db_pwd);
                        stmt = (Statement) con.createStatement();
                } catch (ClassNotFoundException e) {
                        System.out.println("Can't find load class");
                        e.printStackTrace();
                } catch (SQLException e) {
                        System.out.println("Can't establish connection");
                        e.printStackTrace();
                }

        }
       
       
        @BeforeTest
        @Parameters({"platform","browser","version","adminPortal","hub"})
        protected void StartSession(Platform platform, String browser, String version,String adminPortal, String hub){
                DesiredCapabilities capability = new DesiredCapabilities();
                capability.setBrowserName(browser);
                capability.setVersion(version);
                try {
                        driver = new MyRemoteWebDriver(new URL(hub),capability);
                } catch (MalformedURLException e) {
                        e.printStackTrace();
                }
                driver.get(adminPortal);
        }