Jbehave - full page screenshot - selenium

I would like my application to take a screenshot when fail and I want this screenshot to be full screen, I am using this(which is taking the screenshot) however it is not full page.
new WebDriverScreenshotOnFailure(driverProvider, configuration.storyReporterBuilder()));

for full page screen shot you can use the following method
final Screenshot screenshot = new AShot().shootingStrategy(
new ViewportPastingStrategy(500)).takeScreenshot(driver);
final BufferedImage image = screenshot.getImage();
ImageIO.write(image, "PNG", new File(
"D://"
+ "AShot_BBC_Entire.png"));
Maven dependency is here.
Now as far as i know there is no jBehave inbuild function for full page screenshot. Hence you can write this in a method and call it on failures.
Hope this helps.

Related

Cannot read image file in appcelerator titanium

I have an image stored at /assets in my project folder and I am trying to read it using Ti.Filesystem.getFile(). The code prints the blob data in android but it prints undefined in iOS.
Following function is called on Button click event https://pastebin.com/QgqLQPyz
function readImg(e) {
var localPath = '/butterfly.jpg';
var cachedFilename = Ti.Utils.sha1(localPath) + localPath.substr(localPath.lastIndexOf('.'));
console.log("cachedFilename:---"+cachedFilename);
var cachedFile = Ti.Filesystem.getFile(Ti.Filesystem.applicationCacheDirectory, cachedFilename);
if(!cachedFile.exists()){
var blob = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, localPath).read();
console.log("-----------blob in not exists:"+JSON.stringify(blob));
}
}
When the same image path is set in ImageView it gets displayed so the issue is not with path . What am I missing here ? pls help. Thank you.
The best option so you don't have to do anything specific to the images at all (keep in mind, image manipulation is pretty heavy to do on runtime), is to use a module that was made for this purpose, av.imageview. This allows you to configure all kinds of content modes.
An option to get your code to work is to get the blob using the the getAsset method.
var blob = Ti.Filesystem.getAsset('/images/butterfly.jpg');
and then resize where you see fit. But I would advise you, if you do need to do this every time the app runs, then just resize once and store that resized image to be used after that. That way there will only be a single time the image needs resizing.

How to create a better screenshot during the selenium automation in JAVA?

I am creating automated test cases by using selenium 3 & testng. Everything looks good, except the screenshots that are generated. Here is my piece of code to create screenshots PNG files:
file = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(pngfile));
which is pretty standard way to do it, but the quality of the created PNG file is not so good.
As you can see from following PNG file. In the picture, the email value ( "....#yahoo.com"), which should be at the upper-right corner of the web-page and should be as high as the other navigation bar elements on the left side. But in the created PNG file, this item has been squeezed to the lower level, which is not what I am looking for. Any ideas ? Thanks for the help !
Make sure your window is the right size when you're opening the browser. You can do this via visual inspection or using Selenium's getSize method. I assume you're using Java, but here it is in Python as well.
Then, if the window is not of the correct size in order to guarantee that your webpage's CSS doesn't break, use setSize. Here is that method in Python as well.
Afterwards, your screenshot should look like the window does.
Please try this,
public void calltakeScreenShot(String SSName) throws Exception
{
File screen = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);
BufferedImage img = ImageIO.read(screen);
File filetest = Paths.get(".").toAbsolutePath().normalize().toFile();
ImageIO.write(img, "png", new File(filetest + "\\Screenshots\\" + SSName + ".png"));
}
Additionally Here you just need to pre-created Screenshots folder in your Project directory. It will store it by getting absolute path of your project. Also you can manage screenshot name by passing argument.
After several day's research, here is my latest summary.
A). If I was executing the scripts, that is not in the "headless" mode. When the selenium test case is being executed, I will see a new browser session is being popped up and get to that URL, click some buttons, etc, ... till the execution is finished. In this execution, the screenshot page will be saved in good quality.
B). For the same selenium test script, if I am including one extra ChromeOptions setting, which is "--headless", I will not see any browser being brought up during the execution. And once execution is finished, I will get the screenshot with such squeezed web elements.
Comments ?

How to attach screen shot to XCUITest report in Jenkins. Can only see screenshot if running through XCODE

How to attach screen shot to XCUITest report in Jenkins. Can only see screenshot if running through XCODE
Steps
I have a job in Jenkins which builds and runs the XCUITest
But after completing there is no option to see the screenshot of failed cases
I used xcpretty to generate HTML type report, but there also screenshot is not displayed.
it has a -screenshot attribute but that only accepts screenshot with a sepecified name. (like TestcaseName_Classname.jpg)
But xcuitest takes screenshot with name 'screenshot_<>.jpg"
Can anyone throw some information on this
Thanks
Screenshot collection in xcpretty is broken as of now.
https://github.com/supermarin/xcpretty/issues/251
You may use xcsummary as a workaround.
https://github.com/supermarin/xcpretty/issues/251
You need to point attachment.name as here
func takeScreenshot() {
let screenshot = XCUIScreen.main.screenshot()
let attachment = XCTAttachment(screenshot: screenshot)
attachment.lifetime = .deleteOnSuccess
attachment.name = UITest.sharedInstance.testCase.name
add(attachment)
}

Combining Jar File with images in IntelliJ

I have researched this topic on the site, and tried the solutions but nothing that has worked for me so far. I have created a simple program in IntelliJ that compiles just fine, but when I export and make it into a JAR there are errors because of the images. When I take away the images I am able to build and load the JAR file correctly. I keep my image in the SRC file in a sub folder named sample.
public class Main extends Application {
Image image = new Image(String.valueOf(getClass().getResource("/buttona.png")));
Button button1 = new Button("", new ImageView(image));
Button button2 = new Button();
I figured it out and wanted to post the solution for future users. It worked when I used the format shown at the bottom. The key was putting GetClassLoader, and from then finding a path that would work.
np0_up.png is the file
Image Num0 = new Image( getClass().getClassLoader().getResourceAsStream( "sample/np0_up.png"));

Appium Blank Screenshot in Real Devices

When I am taking screenshot using the below code I am getting blank screenshots. I tried putting sleep but that too is not working.
Please advice. It's not that I am getting all blank screens, I am getting few blank screens and few proper screenshots. I dont know what I am doing wrong. I didn't hear appium has any issues in taking screenshots.
Help me in figuring out a solution.
Code:
WebDriver driver1 = new Augmenter().augment(AppiumBaseTest.getAndroidDriver());
File file = ((TakesScreenshot) driver1).getScreenshotAs(OutputType.FILE);
FileUtils.copyFile(file, new File(System.getProperty("test.screenshot.dir") + href));
Code:
FileUtils.copyFile(((TakesScreenshot) AppiumBaseTest.getAndroidDriver()).
getScreenshotAs(OutputType.FILE), new File(System.getProperty("test.screenshot.dir") + href));
I tried taking screenshot using appium driver also and that is also giving me the same issue of blank screenshot. Some are proper and some are blank.
I have tried giving wait for 7 seconds before each screenshot but of no use.
ThankS,
Rajit