Skip to main content
Share Your Experience: Take the 2024 Developer Survey
24 votes
Accepted

Is it possible to automate drag and drop from a file in system to a website in selenium using TestNG

Yes it's possible to drop a file with Selenium via a script injection. The script needs to create an <input> web element to receive the file sent by SendKeys. Then simulate the dragenter, ...
Florent B.'s user avatar
21 votes

How to handle dynamic changing ID's In XPath?

At this situation, We have lots of options- Option 1: Look for any other attribute which Is not changing every time In that div node like name, class etc. So If this div node has class attribute then ...
Bharat Mane's user avatar
  • 6,775
12 votes

How to handle dynamic changing ID's In XPath?

Use contains() or starts-with() function in XPath: Solution: With contains(): //div[contains(@id,'post-body')]/div[1]/form[1]/input[1] With starts-with(): //div[starts-with(@id,'post-body')]/div[...
Sagar007's user avatar
  • 1,340
10 votes
Accepted

What is the difference between jUnit & TestNG?

TestNG is a testing framework inspired from JUnit and NUnit but introducing some new functionalities that make it more powerful and easier to use. TestNG is designed to cover all categories of tests:...
Bharat Mane's user avatar
  • 6,775
10 votes
Accepted

Order of execution for Tests in TestNg, If Priority set only for few Test Methods

Here you have to consider 2 points : If you are not using any priority in your test method then TestNG assign by default priority=0 to the Test Method If there is same priority assign to test methods ...
NarendraR's user avatar
  • 1,573
9 votes

How to handle dynamic changing ID's In XPath?

Use other elements and attributes for partial and combination matches Generally in these cases of database backed and changing ID's in web element selectors your options are to look for one or more ...
Michael Durrant's user avatar
8 votes

TestNG vs Robot Framework - pros and cons

I think the question should be: Java WebDriver + TestNG Vs Robot. I have worked on both Java + TestNG and RobotFramework. Here is my analysis by points. Ease of use TestNG: You need to know Java &...
Vinaykumar Patel's user avatar
7 votes
Accepted

How to find a button using both xpath and button text?

Use below command for finding the button via text: driver.findElementsByXPath("//button[contains(text(),'Text in your webpage')]"); This will work to capture all the 3 buttons with the same class ...
Prasanna venkatesh's user avatar
6 votes
Accepted

How to implement a lock in Selenium with Java?

My answer borrows from NarendraC's answers. @Test (priority=1) public void CreateNew() throws Exception { Process p = Runtime.getRuntime().exec("exeFiles\\CreateNew.exe"); p.waitFor(); ...
Paul Muir's user avatar
  • 3,282
6 votes

What is the difference between BeforeClass and BeforeTest in TestNG - Selenium WebDriver

@BeforeTest method runs before the test method, belonging to the classes inside the tag. It is called once for each test tag. It is used to initialize common objects between different test classes ...
JAINAM's user avatar
  • 1,835
5 votes
Accepted

What is the difference between Priority and Depends on Method in TestNG?

Yes, definitely we can write multiple methods with same priority but disadvantage of using this-There is no guarantee which method will run first, So- Instead of this,you can use 'dependsOnGroups' ...
Bharat Mane's user avatar
  • 6,775
5 votes

How to pause your script in Selenium untill your AutoIt script is completed?

Simpler solution is try a waitFor() on your process, this waits until the process exits. @Test (priority=1) public void CreateNew() throws Exception { Process process = Runtime.getRuntime()...
Niels van Reijmersdal's user avatar
5 votes

How much time it takes to automate 10 test cases of an module using selenium

In addition to the existing answers, another factor in ROI is how often the test cases need to be run. If automating the test cases will take you 500 hours, they need to be run once a year, and it ...
Kate Paulk's user avatar
  • 31.5k
5 votes

Reading locators for Testing suite from an external file

My personal opinion is against it. What difference does it make by storing all xpath in a seperate excel sheet? It does not make the number smaller. Having an external file reduces maintainability, ...
Yu Zhang's user avatar
  • 9,942
5 votes

How to create test data/pre-requisites if it is required for only few of test cases of a test class?

Suggestion 3 (following FDM's 2): Extract the tests that need the extra setup into a separate class. Suggestion 4: Put the special tests into a group. Put the special setup into its own @BeforeGroups ...
Dale Emery's user avatar
  • 4,485
5 votes

How to print a message after checking through TestNG's Assert.assertEquals method?

The easiest way is to wrap the assertion within a try-catch block, something like: try { Assert.assertEquals(actualString, expectedString); } catch (AssertionError e) { System.out.println(&...
beatngu13's user avatar
  • 2,132
5 votes

How to find a button using both xpath and button text?

Using contains in xpath, for me is tricky. Tests are flaky with this approach. The better way is to use: //button[text()='Some text'] Now, you compare/test the text of the button with expected text.
Zhivko.Kostadinov's user avatar
4 votes

Unable to locate element throwing a org.openqa.selenium.NoSuchElementException in TestNG

You should wait for page load after click on button,so for that write below code : WebElement element; Webdriver driver; WebDriverWait wait = new WebDriverWait(driver, 100); element= wait.until(...
Rutvi Soni's user avatar
4 votes

TestNG cannot find parameter for test

You may try with following changes: package pageobjects; import org.openqa.selenium.WebElement; import org.openqa.selenium.support.FindBy; public class HomePage { @FindBy(name="username") ...
Bharat Mane's user avatar
  • 6,775
4 votes

TestNG cannot find parameter for test

When you select a single test and run it TestNG creates a custom testng file (temp-testng-customsuite.xml in your case, see the exception). If you want to pass parameters to test from testng you ...
stackoverflow's user avatar
4 votes
Accepted

How to close all the browser instances and chromeDriver.exe even if my test cases fails?

If you set @AfterTest(alwaysRun=true) then the method will be called even if a test is failing. From the documentation: alwaysRun -> For after methods (afterSuite, afterClass, ...): If set to true,...
juherr's user avatar
  • 285
4 votes

TestNG--java.lang.AssertionError: expected [5] but found [5]

You are comparing an int to a string. Try converting the type before comparing the values. import org.testng.Assert; public class Test { public static void main (String[] args) throws java.lang....
jpjwolli's user avatar
  • 487
4 votes

Selenium Testng, getting error Null Pointer exception

The problem seems to be in the declaration and usage of the variable driver. Although there is a class-scope variable driver, the Login() method stores the created WebDriver object in a method-scope ...
Edvins's user avatar
  • 246
4 votes
Accepted

How should I handle failing tests caused by external dependencies?

should it represent a defect in the Application under test? No, it might be working, but you cannot verify. You do need to monitor and follow it up somehow. Therefore ignoring/skipping the test-...
Niels van Reijmersdal's user avatar
4 votes

Cannot get a STRING value from a NUMERIC cell. How can I resolve this issue in selenium webdriver using POI?

This may be helpful to you.. Open the Excel sheet and select all (Ctrl+a) then right click and click Format cells then in number tab change the category to Text and click Ok...
Sachintha's user avatar
  • 380
4 votes

How to print a message after checking through TestNG's Assert.assertEquals method?

The best practice of TestNg behavior overriding is using so called listeners. For example you can override the dafault behavior of what is happenning when your assert fails. To do that you need to ...
Alexey R.'s user avatar
  • 11.6k
4 votes

Getting Nullpointer Exception

import java.util.concurrent.TimeUnit; import org.openqa.selenium.WebDriver; import org.openqa.selenium.chrome.ChromeDriver; import org.testng.annotations.AfterMethod; import org.testng.annotations....
Brian's user avatar
  • 584
4 votes
Accepted

Run appium scripts without using Eclipse or any IDE

Convert your project to Maven project and use the surefire plugin. Inside the plugin mention the testng.xml file as the test suite. Now you can run your scripts in any environment using below commands....
PDHide's user avatar
  • 11.1k
3 votes

TestNg not executes @BeforeGroup if the method is in another class

Please try the below case, it executes both @BeforeGroups and @BeforeClass. First create a base class name ="TestNGBase" add all @after/@Before methods here (including @BeforeClass,@BeforeGroups etc.....
Bhinge Santosh's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible