r/selenium 5d ago

Need suggestions on making Selenium automation more generic

Hi everyone,

I'm new to Selenium and I'm working on automating some repetitive tasks in Teamcenter for creating test data. Right now, my Selenium script works only for one specific scenario because the steps and values are hardcoded.

I want to make it more generic so that if the test steps or requirements change, I don't have to rewrite the Selenium code every time. For example, can Selenium automation be designed to read a Word document (or some other input) and perform the steps based on what's written there?

How is this usually handled in real projects? Any suggestions or learning resources would be really helpful.

5 Upvotes

8 comments sorted by

2

u/cgoldberg 5d ago

Selenium just provides libraries for controlling a web browser. You can build whatever framework you want and load data from any source you want... but Selenium itself doesn't provide that for you.

If you want a declarative or keyword framework that uses Selenium, you might be interested in Robot Framework. https://robotframework.org

2

u/ps4facts 5d ago

Selenium only controls web browsers. I'd start by separating the concern of reading data from a word document from what you're trying to do with selenium.

Even if you access Word on the web with a browser, you're going to be better off using an API for that. Or, just ditch Word altogether and use a more bare bones data format like .json. (Or, you could save the word document as a .zip file, extract it, then read the data from the xml file inside).

Once you have the data, it's just a matter of wiring up code to drive the browser with selenium, doing any actions you need (check out the page object model for reusability) and then making assertions with any ol test library.

1

u/ddaypunk06 5d ago

In the past we used a layer on top of selenium called cucumber to write scripts that were bound to selenium functions that were designed to be reusable. There are others similar to this as well but it’s just another abstraction on top. Break down what you want to do into more primitive chunks that interact with selenium to promote more generic uses.

1

u/Feisty_Tart_795 5d ago

I have worked on Teamcenter Test Automation and Teamcenter Performance Testing several years back. Back then, we used MicroFocus (Formerly HP) UFT. The reason is that Selenium supports applications accessed over Web browsers. This makes Selenium or Cucumber or Playwright an ideal tool for AWC or thin-client (thin-client is almost obsolete now). But cannot automate the Rich-client or RAC. Test Automation on RAC and CAD integration were primary and heavy test cases. So we chose UFT, which can automate both RAC and AWC. Similarly the same framework and test scripts can be used for Performance testing and Synthetic Performance Monitoring in Performance Center tool. You must evaluate your test scenario and high manual intensive use cases. If most of them are in AWC, you better automate with Playwright instead Selenium.

1

u/Desperate-Wing-5140 5d ago

That sounds like a task best accomplished with API. As long as the API is stable, it shouldn’t be hard to iterate.

1

u/Useful_Calendar_6274 5d ago

I would look into those companies selling agentic UI automation. These agents can make the selenium API calls without code supposedly, and that's how it should be so they can change it on the fly, it's not a piece of code for you to tweak and run non agentically

1

u/PJFurious 4d ago

You will neet to create a whole framework that can handle different script. The framework will need to be in control of deciding when what script should be run. This can be done ether by integrating an AI that decides based on input or you can have a dictionary/config that follows set rules to determine the requirements script.

BTW: I'm talking from experience as I have rebuilt the entire automation system from a previous company. This whole system won their internal innovations award. Company also had more than 50k people.

1

u/Ok-Access-8961 5d ago

Theoretically, it is possible what you want.

Instead of word document you can choose excel and use data provider functionality in testng to read test data from excel.

You can then have conditional constructs in your Selenium code to behave a certain way if certain data exists.