Include screenshots in report test steps with playwright - playwright

Friends, does anyone have the code that allows me to include the screenshots in the line I want and make this print be attached to the standard playwright report?
I'm using playwright with javascriptenter image description here
npx plawright show-report

You can use page.screenshot() to capture the screenshot and use attach() to attach the captured screenshto the report like this:
const screenshot = await page.screenshot();
await testInfo.attach('screenshot', { body: screenshot, contentType: 'image/png' });

Related

Ability to prevent/stop loading 'Page load' in Cypress when clicked a hyperlink

In my Cypress test,
I need to test a link which downloads a .txt, .xlsx and a .zip file when clicked, but when I use "click()" to click the hyperlink, it starts a page load and expects a new action to happen as a result of clicking a link.
As an alternative to this I tried using the cy.downloadFile() to download the files directly through the link but the link I am using is dynamically generated hence I am unable to use that as well. Hence I want to store the newly generated link in the variable and then use it in cy.downloadFile() every time I run the test.
Are there any other ways to test a hyperlink or how to store the dynamically generated link every time the test is run?
Hi there i been through this problem before.
I think it is the same scenario where the cypress test runner just keep waiting page load event and not go to the next test command while file are successfully downloaded.
Add custom cy.window event to listen the click event and add timeout to "force" reload current page, you need to tweak the timeout value so it suitable for your test.
it.only('tes button download', ()=> {
// visit url
cy.visit("/spmb/list_nilaiseleksi");
cy.get('#wrap-button > .btn').click()
//download
cy.window().document().then(function (doc) {
doc.addEventListener('click', () => {
setTimeout(function () { doc.location.reload() }, 5000)
})
cy.get(':nth-child(9) > .col-md-12 > .btn').click()
})
})
More details and discussion available here on cypress github issue :
https://github.com/cypress-io/cypress/issues/14857
I found a way to store the link of the element I want to click. Since I am able to store the link, I am able to solve the requirement by using cy.downloadFile().
cy.get('#selector', {timeout: 15000}).then(($input) => {
cy.downloadFile($input.attr('href'),'cypress/downloads','filename.csv')
});
For me, the problem was resolved after I added the download attribute to the link, This is changing the element in the DOM, but it keeps the solution simple:
cy.get('[href="download?type=php"]')
.then((el) => {
el.attr('download', '');
})
.click();

Trying to convert Jupyter Notebook to PDF slides

I'm trying to convert a Jupyter notebook that is using RISE to visualize the slides as a slideshow in the browser into a PDF file. The PDF file should have all pages in landscape mode and resemble the view in the browser. Of course, animations are not possible, but it should be possible to have fragments either combined in a single PDF slide or spread across multiple sort of "accumulating" slides (i.e. building upon their forerunner slides) .
I've been trying to create my own Jinja template that generates a LaTeX document utilizing the beamer document class, with not much success so far.
Do you know if there are any tools or templates or exporters or anything available that can help me with this process? Preferably automatically, like, utilizing nbconvert?
Figured it out myself. Take these steps:
launch jupyter nbconvert --to slides --post serve the_notebook.ipynb; the browser will open the node hosted the_notebook.slides.html
replace the # after the the_notebook.slides.html in the browser URL with ?print-pdf so that the url looks most likely like http://127.0.0.1:8000/the_notebook.slides.html?print-pdf
print to PDF file
Some time ago, I needed to programmatically convert Jupyter Notebook presentations to PDF slides. I did some research and you can use puppeteer to automate the process. You need a simple Python script for this:
import asyncio
import os
import tempfile
from subprocess import PIPE, Popen
from pyppeteer import launch
import concurrent.futures
async def html_to_pdf(html_file, pdf_file, pyppeteer_args=None):
"""Convert a HTML file to a PDF"""
browser = await launch(
handleSIGINT=False,
handleSIGTERM=False,
handleSIGHUP=False,
headless=True,
args=["--no-sandbox"],
)
page = await browser.newPage()
await page.setViewport(dict(width=994, height=768))
await page.emulateMedia("screen")
await page.goto(f"file://{html_file}", {"waitUntil": ["networkidle2"]})
page_margins = {
"left": "20px",
"right": "20px",
"top": "30px",
"bottom": "30px",
}
dimensions = await page.evaluate(
"""() => {
return {
width: document.body.scrollWidth,
height: document.body.scrollHeight,
offsetWidth: document.body.offsetWidth,
offsetHeight: document.body.offsetHeight,
deviceScaleFactor: window.devicePixelRatio,
}
}"""
)
width = dimensions["width"]
height = dimensions["height"]
await page.pdf(
{
"path": pdf_file,
"format": "A4",
"printBackground": True,
"margin": page_margins,
}
)
await browser.close()
if __name__ == "__main__":
html_input_file = "/you/need/full/path/here/presentation.slides.html?print-pdf"
pdf_output_file = "slides.pdf"
pool = concurrent.futures.ThreadPoolExecutor()
pool.submit(
asyncio.run,
html_to_pdf(
html_input_file,
pdf_output_file
),
).result()
The script accepts the HTML slides as input and produces the PDF slides as output. Please note that you need to provide full path for the HTML file. I wrote an article on how to convert notebook presentations to pdf slides. If you would like to apply styling, here is longer version of the script.
I guess jupyter nbconvert --to pdf the_notebook.ipynb should work fine.
You do need to install latex though.

How to add a File Picker plugin in Flutter?

I am creating a Flutter project in which, I have a piece of data (JSON) that I want to Import from and Export to a location the user wants to. In order to achieve this, I require a File Picker plugin in Flutter. Now, I searched the Dart Packages repository for "file picker" but didn't find one.
Is there a way to get a File Picker that looks like this:
or even this...
The first screenshot is preferable for me as it allows file selection from different sources (like Drive).
Also, since I want to Export the data, I might want a Folder Picker too. ;)
But, if there is any other alternative to Folder Picker. I'd be happy to know...
I've created a file_picker plugin some time ago in order to make it possible to pick (both on iOS and Android) absolute paths and then loaded it with Flutter.
You can check it here: https://pub.dev/packages/file_picker
I used file_picker library to pick files. you can use this for pick images as well.
Future getPdfAndUpload(int position) async {
File file = await FilePicker.getFile(
type: FileType.custom,
allowedExtensions: ['pdf','docx'], //here you can add any of extention what you need to pick
);
if(file != null) {
setState(() {
file1 = file; //file1 is a global variable which i created
});
}
}
here file_picker flutter library.
I'm in the exact same boat as you, haha!
I noticed documents_picker 0.0.2. It allows the user to pick multiple files, and it seems to fit the need!
check it out: https://pub.dartlang.org/packages/documents_picker#-readme-tab-
Here's a better document picker. It looks like the native document picker from the Storage Access Framework, which is what you have in your picture.
flutter_document_picker
Just found the FileSelector plugin from flutter.dev. Compatible with MacOS, Windows and Web.
From its pub.dev page:
Open a single file
final typeGroup = XTypeGroup(label: 'images', extensions: ['jpg', 'png']);
final file = await openFile(acceptedTypeGroups: [typeGroup]);
Open multiple files at once
final typeGroup = XTypeGroup(label: 'images', extensions: ['jpg', 'png']);
final files = await openFiles(acceptedTypeGroups: [typeGroup]);
Saving a file
final path = await getSavePath();
final name = "hello_file_selector.txt";
final data = Uint8List.fromList("Hello World!".codeUnits);
final mimeType = "text/plain";
final file = XFile.fromData(data, name: name, mimeType: mimeType);
await file.saveTo(path);
MacOS: Provide file read or/and write privileges
On target MacOS please provide sufficient rights using Xcode:
In case you don't provide file read or/and write permissions, the call to
final XFile? file =
await openFile(acceptedTypeGroups: <XTypeGroup>[typeGroup]);
neither shows anything not returns.

Cordova InAppBrowser PDF- iOS

My code is working but not exactly the way I want. I'm using the plugin cordova-plugin-inappbrowser. I have an anchor tag to click and opens up a pdf. The code is as follows:
$("#lnkTools").click(function(e){
//e.preventDefault();
url = 'someExternalLink.pdf';
var options = {location: 'yes', clearcache: 'no', toolbar:'no', closebuttoncaption: 'DONE?'};
$cordovaInAppBrowser.open(url, '_blank', options);
}
The problem I'm facing is that, the PDF doesn't open if I don't exit the app, I have to exit the app first and get back in for the PDF to open up. What am I missing? When I try to use _system same thing, before it opens up the browser, I still need to exit the app first.
EDIT:
When I try to change the $urlRouterProvider.otherwise('/app/main'); in my app.js to $urlRouterProvider.otherwise('/app/login'); it's working, well. Why is this like this? when I place a $state.go('app.main') in my login controller, it loops. Is there any way I can get through this?

Print to PDF via AirPrint

I'm building an app using Cordova and I used this Plug-in to print the content of an HTML page. I would try to print this to a PDF, not using AirPrint printer.
How can I do it (also by modifying .m and .h files in the Plugin Folder)?
Here's the plugin I've used: https://github.com/phonegap/phonegap-plugins/tree/master/iPhone/PrintPlugin
Thank you!
var html = document.getElementById("printHTML").innerHTML;
window.plugins.printPlugin.print(
html,
function(result) {
alert("Printing successful");
},
function(result) {
if (!result.available){
alert("Printing is not available");
}
else{
//Localised error description
alert(result.error);
}
});
Let me know if you find a better answer as I am looking for the same solution. In the meantime, what I have done is open up a browser in a new window (skip the plugin all together) and run the html-document through pdfcrowd.com. Then I use airprint directly from the browser.

Resources