Posted 22 March 2023, 9:24 am EST
Hi there,
We also use cypress with sjs but we are looking to start using puppeteer. Can we load sjs instance using puppeteer? If so, can you send me an example how to spin sjs using pupeeteer pls?
Thanks
Forums Home / Spread / SpreadJS
Posted by: sadiq.rahim on 22 March 2023, 9:24 am EST
Posted 22 March 2023, 9:24 am EST
Hi there,
We also use cypress with sjs but we are looking to start using puppeteer. Can we load sjs instance using puppeteer? If so, can you send me an example how to spin sjs using pupeeteer pls?
Thanks
Posted 23 March 2023, 11:08 pm EST
Hello Sadiq,
You can use puppeteer to perform testing with the Spread(workbook) instance.
We have attached a sample below. In the sample, we create a browser instance with puppeteer and load a page which has a Spread(workbook) instance. Then we execute the script in the browser’s page context to access the spread instance and return the value from cell A1 of the first sheet in the workbook.
First, you need to unzip the attached zip file and run “npm install” command to install all dependencies. Then you need to run “node index.js” command in the console to run the sample.
Please refer to the attached sample for further understanding.
Please let us know if you face any difficulties and don’t hesitate to ask any doubts.
Regards,
Ankit
Posted 24 March 2023, 8:27 am EST - Updated 24 March 2023, 8:50 am EST
Hi Ankit,
Thanks for coming back to me. I have tried with your code and still no luck. We have exposed window.GC only for our cypress tests. Should we expose this to puppeteer too? If so, can you tell us how to do it pls and how could we call it from the tests too since puppeteer does not have a window object of its own.
We are on sjs v15.2.4 and plan to move to v16.x soon. Please also let us know if the set up to connect with the sjs instance from test differ based on the versions. If they do, then what is the config for 15.x and 16.x pls.
Thanks
Sadiq
Posted 27 March 2023, 1:08 am EST
Hello,
Yes, you would need to expose the GC object on window object as window.GC.
Since puppeteer executes the script in the context of the web page it browses, that is why the web page should have a GC object exposed on window object of the web page. This way puppeteer can access the GC object and workbook(spread) instance with the APIs provided in the GC object.
You can expose the GC object to the window object as window.GC = GC where you are importing the GC object from ‘@grapecity/spread-sheets’ package in your code file.
Please note that there is no difference to access the workbook(spread) instance based on different versions of SpreadJS. The only requirement is that the GC object should be exposed on the window object of the web page.
Regards,
Avinash