小编Vik*_*kas的帖子

webdriver页面工厂中@FindAll和@FindBys注释之间的区别

请解释webdriver页面工厂概念中@FindAll和@FindBys注释之间的区别.

java selenium-webdriver

17
推荐指数
4
解决办法
4万
查看次数

如何将新数据附加到属性文件中的现有数据?

我使用以下代码将数据写入属性文件

public void WritePropertiesFile(String key, String data)
{
Properties configProperty = new Properties();
configProperty.setProperty(key, data);
File file = new File("D:\\Helper.properties");
FileOutputStream fileOut = new FileOutputStream(file,true);
configProperty.store(fileOut, "sample properties");
fileOut.close();
}

I am calling the above method 3 times as follows:
help.WritePropertiesFile("appwrite1","write1");
help.WritePropertiesFile("appwrite2","write2");
help.WritePropertiesFile("appwrite3","write3");
Run Code Online (Sandbox Code Playgroud)

但是,Helper.properties文件中的数据显示如下:

#sample properties
#Mon Jul 01 15:01:45 IST 2013
appwrite1=write1
#sample properties
#Mon Jul 01 15:01:45 IST 2013
appwrite2=write2
appwrite1=write1
#sample properties
#Mon Jul 01 15:01:45 IST 2013
appwrite3=write3
appwrite2=write2
appwrite1=write1
Run Code Online (Sandbox Code Playgroud)

我希望数据附加到现有数据,并且不需要重复数据,如下所示:

appwrite3=write3
appwrite2=write2
appwrite1=write1
Run Code Online (Sandbox Code Playgroud)

请建议怎么做?

java properties-file

7
推荐指数
1
解决办法
2万
查看次数

从自定义TestNG侦听器获取Allure报告的屏幕截图-TestListenerAdapter

我在项目中实现了名为TestListenerAdapter的自定义测试侦听器,并且编写了捕获侦听器类的onTestFailure方法中的屏幕截图的代码。我还创建了以下方法,并在OnTestFailure方法中进行调用:

@Attachment(type = "image/png")
private byte[] createAttachment() {
    return ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES);
}

public void onTestFailure(ITestResult result)
{
  createAttachment();
}
Run Code Online (Sandbox Code Playgroud)

上述方法未将屏幕截图附加到“魅力”报告中。

如果我们在@Test方法中调用createAttachment()方法,则仅将屏幕截图添加到吸引力报告中。在每个@Test中添加屏幕截图方法是一项繁重的任务,因此我已经在TestNG侦听器中实现了此方法,以便在测试用例失败时捕获屏幕截图。

请让我知道是否有一种方法可以使用TestListenerAdapter侦听器的onTestFailure()方法中的上述createAttachment()方法。

testng selenium-webdriver allure

5
推荐指数
1
解决办法
2468
查看次数

将数据附加到属性文件,注释消失并且数据顺序发生变化

在将数据附加到属性文件时,现有注释将消失,并且数据顺序正在更改.请建议如何避免它?

属性文件中的数据(在附加数据之前)和注释如下:

# Setting the following parameters 
# Set URL to test the scripts against
App.URL = https://www.gmail.com
# Enter username and password values for the above Test URL
App.Username = XXXX
App.Password = XXXX
Run Code Online (Sandbox Code Playgroud)

我正在向上面的属性文件添加更多数据,如下所示:

 public void WritePropertiesFile(String key, String data) throws Exception
{       
    try 
    {
        loadProperties();  
        configProperty.setProperty(key, data);
        File file = new File("D:\\Helper.properties");
        FileOutputStream fileOut = new FileOutputStream(file);
        configProperty.store(fileOut, null);
        fileOut.close();
    } 
    catch (Exception e) 
    {
        e.printStackTrace();
    }
}
Run Code Online (Sandbox Code Playgroud)

将上述功能称为:

help.WritePropertiesFile("appwrite1","write1");
help.WritePropertiesFile("appwrite2","write2");
help.WritePropertiesFile("appwrite3","write3");
Run Code Online (Sandbox Code Playgroud)

数据添加成功,但先前输入的注释消失,数据顺序也发生变化,属性文件(追加数据后)显示如下

#Tue Jul 02 11:04:29 …
Run Code Online (Sandbox Code Playgroud)

java properties-file

4
推荐指数
1
解决办法
7633
查看次数

比较java中的日期会给出错误的结果

我正在使用以下代码比较日期

String sCreatedDate = "30.07.201514:57:03";
String sModifiedDate = "30.07.201515:40:34";            
SimpleDateFormat parser = new SimpleDateFormat("dd.MM.yyyyHH:MM:SS");

Date d1 = parser.parse(sCreatedDate);
Date d2 = parser.parse(sModifiedDate);         
System.out.println(d1.before(d2));
Run Code Online (Sandbox Code Playgroud)

它打印false,但我希望它打印true.

你可以解释一下我在这段代码中做错了什么吗?

但是,上面的代码适用于以下日期并打印真实值:

String sCreatedDate = "23.07.201507:25:35";
String sModifiedDate = "23.07.201507:26:07";
Run Code Online (Sandbox Code Playgroud)

java datetime

3
推荐指数
1
解决办法
629
查看次数

从黄瓜stepdef中的Testng.xml文件中读取参数值

我可以在与黄瓜集成时运行testng脚本.我已按照http://automatictester.co.uk/2015/06/11/basic-cucumberjvm-selenium-webdriver-test-automation-framework/ link中定义的确切步骤进行操作.

现在我还有一个要求.你能解释一下如何从testng.xml的参数标签读取值.见下面的例子:

<test name="ascentis.LoginDemo.Firefox">
    <parameter name="BrowserName" value="Firefox" />
    <parameter name="Environment" value="local" />  
    <packages>
        <package name="runnerFiles.*"/>
    </packages>
</test>
Run Code Online (Sandbox Code Playgroud)

我将从parameters标签中读取BrowserName和Environment值.我已经尝试将@parameters用于黄瓜的@Before方法,但它没有成功并且给出了异常,即@Before钩子只接受一个类型场景的参数.你能解释一下如何从参数标签中读取值,以便在黄瓜的stepDefinations中访问.

testng cucumber cucumber-jvm selenium-webdriver cucumber-java

3
推荐指数
1
解决办法
3650
查看次数