1

Let me setup my test environment. We run our tests on VM's from the command line. Running the testng.xml from the commandline. Can't pass parameters through that. We have a test.properties with all of our runtime parameters and through that, we set the browser type, version, homepage URL, etc. We are using pageobjects currently.

We have a functionalTest.java that all pageTests inherit from that parses the test.properties and sets up all the parameters for that particular run of 600 tests. I would like to convert to using Arquillian/Graphene/Drone, but I am struggling with getting it setup in my environment.

I can't use arquillian.xml since each run will be different, and there is no way for me to attach a different file for each run. Thus I need to I believe set system properties in my functionalTest.java for everything. I've tried so far with:

// File :FunctionalTest.java package tests;

import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.testng.Arquillian;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.BeforeSuite;

import framework.Log;
import framework.Utility;

/**
 * FunctionalTest class contains the setup methods and these will run before or after the suite or test methods.
 *
 **/
public class FunctionalTest extends Arquillian
{
    @Drone
    public WebDriver wDriver;

    public static Properties pTestProperties = new Properties();
    public static String sBrowser = "";
    public static String sBrowserVersion = "";
    public static String sEnvironment = "";

    @BeforeSuite
    public static void StartSuite()
    {
        pTestProperties = Utility.ReadPropertiesFile("test.properties", pTestProperties);
        pTestProperties = Utility.ReadPropertiesFile("testEnvironment.properties", pTestProperties);
        sEnvironment = (System.getenv("ENVIRONMENT_NAME") != null) ? System.getenv("ENVIRONMENT_NAME") : pTestProperties.getProperty("environment");
        sBrowser = (Utility.GetTestParameterString("browser") != "") ? Utility.GetTestParameterString("browser") : pTestProperties.getProperty("browser");
        sBrowserVersion = (Utility.GetTestParameterString("browserVersion") != "") ? Utility.GetTestParameterString("browserVersion") : pTestProperties.getProperty("browserVersion");
        System.setProperty("webdriver.browser", sBrowser);
        System.setProperty("webdriver.chrome.driver", "\\drivers\\chromedriver_2.38_Win32.exe");
    }
}

// File :HomePageTest.java package tests;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.testng.Arquillian;
import org.testng.Assert;
import org.testng.annotations.Test;

import framework.Log;
import pageobjects.HomePage;

@RunAsClient
public class HomePageTest extends FunctionalTest
{
    @Test(dataProvider = Arquillian.ARQUILLIAN_DATA_PROVIDER)
    public void OpenUrlTest()
    {
        String sUrl = "";
        HomePage oHomePage = null;
        sUrl = pTestProperties.getProperty("testUrl." + sEnvironment + "." + sTestCaseName) != null ? pTestProperties.getProperty("testUrl." + sEnvironment + "." + sTestCaseName) : pTestProperties.getProperty("testUrl." + sEnvironment + "." + sCountry);
        System.setProperty("webdriver.remoteAddress", sUrl);
        oHomePage = new HomePage(wDriver);
        wDriver.get(sUrl);
        Assert.assertTrue(oHomePage.IsLoaded());
        Log.Info("Passed");
    }

}

// File :HomePage.java package pageobjects;

import java.util.concurrent.TimeUnit;

import org.jboss.arquillian.graphene.Graphene;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

import framework.Log;

public class HomePage
{
    private final WebDriver driver;

    public HomePage(WebDriver driver)
    {
        this.driver = driver;
    }

    @FindBy(id = "hero-carousel")
    private WebElement homepageCarousel;

    public boolean IsLoaded()
    {
        Log.Info("Entering method HomePage::IsLoaded()");
        boolean bFlag = false;
        try
        {
            Graphene.waitGui().withMessage("Carousel not shown on HomePage").ignoring(StaleElementReferenceException.class)
                    .pollingEvery(1, TimeUnit.SECONDS).until().element(homepageCarousel).is().visible();
            bFlag = true;
        }
        catch (Exception e)
        {
            Log.Info("Execption thrown: " + e.getMessage());
            bFlag = false;
        }
        Log.Info("Exiting the method HomePage::IsLoaded() with return value: '" + bFlag + "'");
        return bFlag;
    }
}

Running OpenUrlTest produces a "missing arquillian.xml" error. If I put in an arquillian.xml, nothing I do overrides the browsertype. Any assistance?

Greg

GregMa
  • 740
  • 2
  • 10
  • 25

1 Answers1

1

You can use System properties in arquillian.xml.

For ex:

<extension qualifier="webdriver">
    <property name="browser">${browser}</property>
</extension>

Through command line, you can pass -Dbrowser=chrome

Or,

You can ignore arquillian xml property and set arquillian property at run time

System.setProperty("arq.extension.webdriver.browser", "chrome");
vins
  • 15,030
  • 3
  • 36
  • 47
  • Is there any document that details what the actual properties are that can be set with System.setProperty? I've tried System.setProperty("arq.extension.webdriver.browser", "chrome"); Drone still used firefox. – GregMa Jun 06 '18 at 18:02
  • @Gregma. check the arquillian site. they have. but in general it is arq.extension.[qualifier].[propertyname] . so in our case it becomes `arq.extension.webdriver.browser` – vins Jun 13 '18 at 21:32
  • @GregMa I've noticed that Drone/Selenium Server sometimes selects Firefox anyway, despite requesting (say) IE for the browser, if there are certain "moz:xxx" properties listed in arquillian.xml. I notice that by commenting out that property, but changing nothing else, the correct browser launches. I have otherwise been successful in using the arq.extension.webdriver.browser override, but note that I'm setting it on the JVM command line before the execution starts with `-Darq.extension.webdriver.browser=whatever` rather than trying to do it in code. – Scott Dudley Jun 21 '18 at 21:59
  • I would love to be able to do that, but in our world, we use ALM to launch our selenium/testng suites. And our IT department doesn't give us access to change the JVM command line. Thus everything has to be done at runtime. I've checked the arquillian.xml to make sure there was no moz:xxx properties, and even with no arquillian.xml present. It's a shame because this really looked promising. – GregMa Jun 22 '18 at 13:04