让我设置我的测试环境。我们从命令行对VM进行测试。从命令行运行testng.xml。无法通过该参数传递参数。我们有一个包含所有运行时参数的test.properties,通过它们,我们设置了浏览器类型,版本,主页URL等。我们当前正在使用页面对象。
我们有一个所有pageTests继承的functionalTest.java,它解析test.properties并为特定的600次测试运行设置所有参数。我想转换为使用Arquillian / Graphene / Drone,但我正在努力在我的环境中设置它。
我无法使用arquillian.xml,因为每次运行都会有所不同,而且我无法为每次运行附加不同的文件。因此,我需要相信在functionalTest.java中为所有内容设置系统属性。到目前为止,我已尝试过:
//文件:FunctionalTest.java 包装测试;
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");
}
}
//文件:HomePageTest.java 包装测试;
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");
}
}
//文件: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;
}
}
运行OpenUrlTest会产生“缺少arquillian.xml”错误。如果我输入arquillian.xml,我所做的一切都不会覆盖browsertype。有什么帮助吗?
格雷格
答案 0 :(得分:1)
您可以在arquillian.xml中使用系统属性。
例如:
<extension qualifier="webdriver">
<property name="browser">${browser}</property>
</extension>
通过命令行,您可以传递-Dbrowser=chrome
或者,
您可以忽略arquillian xml属性并在运行时设置arquillian属性
System.setProperty("arq.extension.webdriver.browser", "chrome");