Is it possible to transfer parameters from an XML file to the @beforesuite method?

Is it possible to pass parameters from an XML file to the @beforesuite method?

Here is a snippet from the TestNG.xml file:

<suite name="Suite" verbose="1"> 
 <test name="Selenium_TestFF">
 <parameter name="Browser" value="Firefox"/>
   <classes>
      <class name="testcases.TestSuiteOne"/>
    </classes>
  </test>
  <test name="Selenium_TestC">
    <parameter name="Browser" value="Chrome"/>
    <classes>
      <class name="testcases.TestSuiteOne"/>
    </classes>
  </test>
  <test name="Selenium_TestIE">
    <parameter name="Browser" value="InternerExplorer"/>
    <classes>
      <class name="testcases.TestSuiteOne"/>
    </classes>
  </test>
</suite> 

The @BeforeSuite method is designed to receive a parameter named 'Browser' that will be invoked during test setup:

@Parameters({"Browser"})
@BeforeSuite
public void Setup(String Browser){
    System.out.println(Browser);
    driver = getDriver(Browser);    
}

Thank you.

Answer №1

@BeforeSuite may not have access to parameters from the <test> context. However, this can be resolved by setting up <parameter> in the <suite>, even though it may not meet all your requirements.

To achieve the desired outcome, consider replacing @BeforeSuite with @BeforeTest. This will launch a new browser instance for each <test>.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Automating the processes on the Axis Bank website

I need help selecting Accounts under the Products category using Actions. Even though it seems like a simple task, I am experiencing some difficulties with it. Can anyone offer assistance? [Selecting Account under Product Category][1] driver.get ...

Measuring response time in Python using Selenium

I am trying to measure the response time of my home page after logging in, but traditional methods like waiting for a specific element or using sleep functions are not working. Can anyone suggest an effective approach to determine the load time of a home p ...

What should you do to move to the next line or block if a specific element cannot be located?

Hello there, I am Hugo. Currently, I am scraping a website that lacks a 'next page' button. To navigate through the pages, I am manually changing the page number in the URL. I have implemented a loop to cycle through a list of URLs within the cod ...

Access to selenium python through webdriver-manager is denied due to a PermissionError with error number 13

After recently installing webdriver-manager 2.5.2 to utilize chromedriver for selenium in Python, everything was running smoothly. However, I suddenly encountered the following error message - PermissionError: [Errno 13] Permission denied: 'C:\Us ...

Error: Unable to find class org/openqa/selenium/virtualauthenticator/HasVirtualAuthenticator using Gradle, Selenium, and ChromeDriver

As a novice in this field, I am eager to extract HTML content from a URL. To achieve this, I opted to experiment with Selenium and devised a service that resembles the following: package dataox.keithgellmanrestaurantmenuscraping; import lombok.RequiredArg ...

Pressing a button by hand will navigate the browser to a different URL, whereas utilizing webdriver will result in the browser opening a new instance

Whenever I manually click a button, the browser (IE 8) redirects to a new URL; however, when using Webdriver, it opens up a new IE 8 browser. Is there a way to make it navigate to the new URL without launching another browser? driver.get(url); driver.fi ...

Input a code, select a label, and finally, click on a button using Python Selenium

I need to input a code into a search bar, click on a specific label, and then click on a button on a webpage found at . The process involves entering the code in the search bar (where the prompt "Inserisci i dati dell'azienda" appears), clic ...

navigate back to the previous tab using protractor

When I open a new tab (second), I attempt to switch back to the first tab. common.clickOpenNewSession(); //opens a new tab browser.getAllWindowHandles().then(function (handles) { var secondWindowHandle = handles[1]; var firstWindowHandle ...

Ways to determine if text is displayed on a webpage

Is there a reliable way to determine if this text (refer to image) is visible to the user on the webpage? The .is_displayed() method always returns true. Are there any alternatives available? Even when the text is not visible to the user, the following c ...

Guide on transferring a particular XML element to a separate XML document using Python

I have several xml files similar to the example below:- File Name = Updated input.xml <?xml version="1.0"?> <TestSuite Name="A123"> <Group Name="TestRoot" ExecutionPolicy="AnyDeviceAnyOrder"> < ...

Running tests using Selenium and Maven works fine on a local machine, but encounters an issue in Azure Pipeline with the error message "unable to access org.testng.Assert."

Running TestNG or Maven tests locally shows that all test cases are working correctly. However, when running the tests in a pipeline, an error is encountered stating "cannot access org.testng.Assert". Attached below are error screenshots of Azure Pipeline: ...

Extracting the date information from Chrome browser using Selenium

Can anyone help me retrieve the date of each post on web pages when I display content using this code snippet? Here is the code: dateShare = WebDriverWait(post, 100).until(EC.presence_of_element_located((By.XPATH, ".//a[@class='oajrlxb2 g5ia77u1 ...

Trouble Generating Extent Report

Welcome to my Base Test method where all the extent report information is stored. public class BaseTest { // Declaring WebDriver and Extent Reports globally public static WebDriver driver; ExtentReports extent = new ExtentReports(); ...

Could someone provide me with guidance on creating an xpath for selenium using Python?

Having difficulty interacting with elements on a webpage. I am attempting it using: WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "..........']"))).click() I'm curious about the proper way to write xpaths that will work ...

Having trouble getting Selenium webdriver 2.53.0 to work with Firefox 45 ESR?

Is there a way to get Firefox 45 esr to work with selenium webdriver 2.53.0? I keep encountering an exception when trying to instantiate FirefoxDriver(desiredCapabilities): Unable to determine the current version of FireFox using the registry, please make ...

What is the process for transferring the test results report from Sauce Labs to the Jenkins dashboard?

Utilizing Sauce Labs with Jenkins for running Selenium functional test cases has been my current challenge. Imagine having a Jenkins CI/CD pipeline in network-1 that connects to a Git repo for code retrieval and then deploys it in network-2. Following th ...

Encountering error java.lang.ClassNotFoundException: org.openqa.selenium.MutableCapabilities while attempting to initiate browser using Selenium

I encountered the error mentioned above when attempting to launch the Chrome browser in IntelliJ. This issue occurred while executing the code on my Ubuntu 16.04 system, and I've already attempted updating the browser as well as using the appropriate ...

Unable to Establish Connection Between Selenium Grid 2 Node and Hub

My computer has a local IP address of 192.168.1.x running Windows 7. Additionally, I have set up a VM with NAT IP 10.0.2.15 and a host-only IP of 192.168.70.64 also running Windows 7. The setup for my hub is quite simple: java -jar selenium-server-standal ...

The current version of ChromeDriver is only compatible with Chrome version 99. However, the current browser version is at 98.0.4758

My current chrome version : 98.0.4758.102 I am currently using selenium version: 4.1.1, but I am unable to download chrome 99. My chrome 98 is up to date, so how can I obtain chrome 99 assuming it's a beta version? Trace log : ChromeDriver was start ...

Identifying the specific button within an Angular table that is part of a collection of buttons all sharing the same ID

I am currently working on writing a Selenium test using C# for the specific scenario outlined below. The task at hand involves clicking the undo button on selected records within the table based on their transfer type. https://i.stack.imgur.com/CwNMb.jpg ...