Need to verify and output similarities and differences of data tables in two excel sheets using testcafe. Is there an approach to do it in testcafe? - testing

Compare data in two excel sheets using testcafe
I need the approach to follow to compare data in two excel sheets using testcafe

Since TestCafe tests are Node.js scripts, you can use any third-party library for reading data from excel files.
This example shows how to compare cell values using the read-excel-file npm module:
import readXlsxFile from 'read-excel-file/node';
fixture`Test Excel Files`
.page`about:blank`;
test('Compare files', async t => {
const rows1 = await readXlsxFile('./excel-files/1.xlsx');
const rows2 = await readXlsxFile('./excel-files/2.xlsx');
await t.expect(rows1[1][1]).eql(rows2[1][1]);
});

Related

Trouble with Cypress Upload files, name repetition

I'm relatively new into Cypress (Java S) so I've created a some code to check on an upload feature of a particular system. Work just fine, the issue I'm facing now is, due the scanning process the system has, when a file with an used name is re-uploaded will give an error (rightfully doing so). My question, having the following code, what is the best approach to add a "name generator" for the files?.
cy.log('File Upload');
const validfile = ('pic.jpg');
cy.get('input[type="file"]').attachFile(validfile);
cy.get('webmarker').click();
Thanks in advance.
Ps: using cypress-file-upload
You can use some random number generator and add in your code. So it will not be same e.g.
const uuid = () => Cypress._.random(0, 1e6)
const id = uuid()
const validfile = (`pic.jpg${id}`)
cy.log('File Upload')
cy.get('input[type="file"]').attachFile(validfile)
cy.get('webmarker').click()
Or create a custom command for that purpose and use it

Read/Write Data in Google Spreadsheet

I am not using MS office in my local machine. So I am using Google Docs.
Now I need to create a script that fetches the data from google spreadsheet in Selenium.
I want to fetch the data[Read/Write] from the Google spreadsheet using selenium web-driver.
Is anyone have an idea about how to do it?
Technologies:
Selenium Web-Driver
JAVA
TestNG
Eclipse IDE
I don't have access to Google Sheets right now, but I'm guessing it would look something like this.
pip install gspread oauth2client
Then...
import gspread
from oauth2client.service_account import ServiceAccountCredentials
# use creds to create a client to interact with the Google Drive API
scope = ['https://spreadsheets.google.com/feeds']
creds = ServiceAccountCredentials.from_json_keyfile_name('client_secret.json', scope)
client = gspread.authorize(creds)
# Find a workbook by name and open the first sheet
# Make sure you use the right name here.
sheet = client.open("Copy of Legislators 2017").sheet1
# Extract and print all of the values
list_of_hashes = sheet.get_all_records()
print(list_of_hashes)
Or, get a list of lists:
sheet.get_all_values()
Finally, you could just pull the data from a single row, column, or cell:
sheet.row_values(1)
sheet.col_values(1)
sheet.cell(1, 1).value
https://www.twilio.com/blog/2017/02/an-easy-way-to-read-and-write-to-a-google-spreadsheet-in-python.html
https://towardsdatascience.com/accessing-google-spreadsheet-data-using-python-90a5bc214fd2

Repeating actions with Selenium with a different value each time

I am new-ish to Selenium, so I use Katalon Automation Recorder through Chrome to quickly draft scripts.
I have a script that makes an account on a website, but I want to make more than one account at a time (using a catchall). Is there a way for Selenium/Katalon to alternate its input from a database of preset emails (CSV sort of thing) or even generate random values in-front of the #domain.com each time the script loops over?
Here is the current state of the script:
Thanks
As #Shivan Mishra mentioned, you have to do some data driven testing. In Katalon you can created test data in object repository (See https://docs.katalon.com/katalon-studio/docs/manage-test-data.html)
You can manage your test data in script like following example:
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
def data = findTestData('path/to/your/testdata/in/object repository')
for(int=0;i<data.getRowNumbers();i++){
def value = data.getValue(1, i)
// do any action with your value
}

Looking for a faster way to batch export pdf:s in InDesign

I'm using this script (below) to batch export pdf:s from several indesign files for a task i do every week. The filenames are always the same, i'm using 8-10 different indd files to create 12-15 different pdf:s.
The script is set up like this:
//Sets variables for print and web presets
var myPDFExportPreset = app.pdfExportPresets.item("my-present-for-print-pdf");
var myPDFExportPreset2 = app.pdfExportPresets.item("my-preset-for-web-pdf");
//sample of one pdf exported first with print, then web pdf preset as two different files
var firstFileIntoPdfs = function(){
var openDocument= app.open(File("MYFILEPATH/firstfile.indd"));
openDocument.exportFile(
ExportFormat.pdfType,
File("MYFILEPATH/print-pdfs/firstfile-print.pdf"),
false,
myPDFExportPreset
);
openDocument.exportFile(
ExportFormat.pdfType,
File("MYFILEPATH/web-pdfs/firstfile-web.pdf"),
false,
myPDFExportPreset2
);
};
I'm defining all exports like the one above as named functions, some using only one of the presets, some two like the one above. I'm calling all these functions at the end of the file
firstFileIntoPdfs();
secondFileIntoPdfs();
thirdFileIntoPdfs();
fourthFileIntoPdfs();
and so on... ยจ
The script is however quite slow, 10 files into 1 or 2 pdfs each, like the function above, can take 10 minutes. I don't think this is a CPU issue, what i noticed is that it seems like the script is waiting for the files in "firstFileIntoPdfs()" to be created, a process that takes some minutes, before proceeding to execute the next function. Then waiting again...
Selecting File -> Export manually you can set new files to be exported while the previous ones are still processing the pdf files, which to me has seemed faster than how this script is working. Manual clicking is however error prone and tedious, of course.
Is there a better way to write this batch export script than how i've done above, that would make all functions executed while pdfs from previous functions still are processed in the system? I'd like to keep them as separate functions in order to be able to comment out some when only needing certain specific pdf:s. (unless the process of exporting all becomes nearly as fast as exporting only 1 pdf).
I hope my question makes sense!
There is an asynch method available, replace exportFile with asynchrousExportFile:
var openDocument= app.open(File("MYFILEPATH/firstfile.indd"));
openDocument.asynchronousExportFile(
ExportFormat.pdfType,
File("MYFILEPATH/print-pdfs/firstfile-print.pdf"),
false,
myPDFExportPreset
);
which use a background task

Is it possible run selenium test with input data in excel?

I use Selenium Web Driver in Eclipse with JUnit. I compose my main test - common for all other, on the begining I set my input data (which is different for each test):
String update_f="//*[#id='columnTitle2']/input";
String update_u="dscr";
String name_p="Test";
String[] link=new String [] {"001","01"};
String[] lov_name= new String [] {"Work","Machine"};
Is it possible to set this data in excel file and than just change this file if I want execute specific test (actually set specific data)?
It is possible my friend,with the help some external jars to handle Excel spread sheets.
U can choose
a. JXL Jar ( which is easy to use and is sufficient for normal functionalities like read and write) - http://www.andykhan.com/jexcelapi/tutorial.html
b. Apache poi jar - http://onjava.com/pub/a/onjava/2003/04/16/poi_excel.html
Add these external jars into eclipse.
create an excel file with different input values.
Read and pass these values from excel through the jars.
currently im working with JXL it is good.