0

Want to open a browser from concordion.
Trying to open browser from System.java class. But observed that WebDriver driver = new FirefoxDriver(); is not executed.

Here is structure of my project ;-

enter image description here

System.java class :-

package com.tutorialspoint;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;

public class System { 
   public String initization(String browserName){
       String url = null;
       if (browserName=="firefox")
       {
           WebDriver driver = new FirefoxDriver();
           driver.get("http://www.google.com");
          url = driver.getCurrentUrl();

       }
    return url;

   }
}

This is my BrowserFixture.java class :-

package specs.tutorialspoint;
@RunWith(ConcordionRunner.class)
public class BrowserFixture {
   System system = new System();
   public String initization(String browserName){

       return system.initization(browserName);

   }  
}

Here is my .html input :-

<html xmlns:concordion="http://www.concordion.org/2007/concordion">
<head>
   <link href="../concordion.css" rel="stylesheet" type="text/css" />
</head>
<body>
   <h1>Browser Initilization</h1>
      <div class="example">
      <h3>Example</h3>
      <table>
      <tr>
         <th>browserName</th>
         <th>initization</th>
      </tr>
      <tr concordion:execute="#result = initization(#browserName)">
         <td concordion:set="#browserName">firefox</td>

      </tr>

   </table>
   </div>
</body>
</html>
Rama
  • 815
  • 2
  • 17
  • 37
  • You might wish to download a working example using Concordion 2.x from https://github.com/concordion/concordion-scope-examples/tree/per_spec_parallel. This contains a suite of browser-based tests, with one browser opened per spec, and runs the specs in parallel. Other branches of the repository contain different scopes for opening/closing the browser. See https://github.com/concordion/concordion-scope-examples/blob/master/README.md for details. – Nigel Charman Apr 30 '16 at 09:58
  • Normally the browser initialisation would be "hidden" in the fixture class, so that the specification references what the user is trying to achieve, not how they are doing it. See http://concordion.org/technique/java/markdown/ for more details. – Nigel Charman Apr 30 '16 at 10:04
  • Also, Concordion 2.x allows you to write your specification in Markdown, which are easier to read and write than HTML. These are demonstrated in the working example referenced above, and documented at http://concordion.org/. – Nigel Charman Apr 30 '16 at 10:08

1 Answers1

0

You need to use the string.equals(Object other) function to compare strings, not the == operator.

The browser opens OK if you replace:

if (browserName=="firefox")

with:

if (browserName.equals("firefox"))

See How do I compare Strings in Java for more details.

See also my comment to this question for some general observations about this example.

Community
  • 1
  • 1
Nigel Charman
  • 733
  • 5
  • 9