1

So I am trying to automate the process of filling out a webform on https://www.business.att.com/disconnects/.

I am using the Playwright test tool to automate this process using JavaScript

I have the steps outlined in Playwright:

const { test, expect } = require('@playwright/test');

test('filling out ATT disconnect webform', async ({ page }) => {

  await page.goto('https://www.business.att.com/disconnects/');

  await page.click('select[name="region"]');
  await page.selectOption('select[name="region"]', "ES");

  await page.selectOption('select[name="service"]', 'ZH:E2');

  await page.click('text=Desired Disconnect Date');
   // This RequestedDisconnectDate is one of the values I want to pull from a local csv. I have it hard coded for now

  await page.fill('input[name="RequestedDisconnectDate"]', '01/12/2022');
  await page.click('a:has-text("12")');



  // For "Disconnect Reason", ALWAYS select = "Other"
  await page.click('select[name="ReasonForDisconnect"]');
  await page.selectOption('select[name="ReasonForDisconnect"]', '31');


  // For "Reason Other", ALWAYS fill = "Other"
  await page.click('input[name="ReasonForDisconnectOther"]');
  await page.fill('input[name="ReasonForDisconnectOther"]', 'Other');

  // ... 

  await page.click('input[alt="Submit"]');

});

Some of the values I am trying to pass in are constant but others are variable. For example, the RequestedDisconnectDate is stored in a csv. Those values I want to pull from a csv I have saved on my computer locally. But I am not sure how to go about that process. I have been looking at js library solutions and npm packages like csv-parser, and jquery. But I am not sure how to work it out.

If someone could give me an idea on how to approach this that would be much appreciated. thanks

FTM.ELR
  • 11
  • 2
  • Your question is not so much related with playwright it is same as question answered here https://stackoverflow.com/questions/1293147/example-javascript-code-to-parse-csv-data – Gaj Julije Jan 13 '22 at 21:37

1 Answers1

0

I dont know much about csv files. I had something similar with .json files, at the time, I imported the json file as followed:

import * as whatever from 'path;

const firstVariable = whatever.myvariables[1] // depends on the file structure.

and then I would access the elements as an array. so you have to figure out if you can do the same with csv or just use json file instead which as I understood have a very similar structure to csv file.

another option would be using .env variable. It's not meant to be used for things like that but that would definitly work. In the .env file:

VARIABLE=variable content

in the test:

page.fill('selector', process.evn.VARIABLE);

Make sure to use env-cmd when executing the test files, so the env variable would be available: env-cmd npm run test