Issue
I am using Chrome. While clicking on a button, it's downloading a file in the "Downloads" folder (without any Download window pop-up, otherwise I can try with the AutoIT tool also). Now I need to verify that file is downloaded successfully or not. Later I need to verify the content of that file. Content of file should match what appears on the GUI.
Solution
The below line of code returns true or false if program.txt file exists:
File f = new File("F:\\program.txt");
f.exists();
you can use this inside custom expected condition:## to wait till the file is downloaded and present
using:
import java.io.File;
define the method inside any pageobject class
public ExpectedCondition<Boolean> filepresent() {
return new ExpectedCondition<Boolean>() {
@Override
public Boolean apply(WebDriver driver) {
File f = new File("F:\\program.txt");
return f.exists();
}
@Override
public String toString() {
return String.format("file to be present within the time specified");
}
};
}
we ceated a custom expected condition method now use it as:
and in test code wait like:
wait.until(pageobject.filepresent());
Output:
Failed:
Passed
Answered By - PDHide
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.