Hot answers tagged

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, ...
user avatar
20 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 ...
user avatar
  • 6,749
15 votes

TestNG vs Robot Framework - pros and cons

TestNG has been created as an alternative to JUnit in unit testing. While, RobotFramework has been created for acceptance testing. Each has remarkable features: TestNG TestNG is easily integrated ...
user avatar
  • 4,540
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:...
user avatar
  • 6,749
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 ...
user avatar
  • 1,573
9 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[...
user avatar
  • 1,290
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 &...
user avatar
8 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 ...
user avatar
6 votes

TestNG.java.lang.NullPointerException running second @Test

There are two issues with your code. The first: It seems like you never apply the PageFactory on this class. Therefore, when trying the line profile.click() the variable is null (because never ...
user avatar
  • 5,834
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(); ...
user avatar
  • 3,212
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 ...
user avatar
  • 1,795
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' ...
user avatar
  • 6,749
5 votes

How to Pause your script in selenium untill your Autoit script gets 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()...
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 ...
user avatar
  • 30.8k
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, ...
user avatar
  • 9,720
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 ...
user avatar
  • 4,440
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(&...
user avatar
  • 2,112
5 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 ...
user avatar
4 votes

How to make the opening of browser(all test in one browser) static in testng for selenium

You mean to say in one class multiple methods you want to run, then use below code and try. @BeforeTest public static void beforeMethod() { driver= new FirefoxDriver(); } @Test ...
user avatar
  • 510
4 votes
Accepted

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(...
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") ...
user avatar
  • 6,749
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 ...
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,...
user avatar
  • 285
4 votes
Accepted

what does this mean ? : Cannot inject @Test annotated Method [f] with [interface org.openqa.selenium.WebDriver]

Methods annotated with @Test cannot have parameters. Try something like this: public class NewTest { @Test public void f() { WebDriver driver; System.setProperty("webdriver....
user avatar
  • 23k
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....
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 ...
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-...
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...
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 ...
user avatar
  • 11.4k
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....
user avatar
  • 584

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