Hot answers tagged

14

I suspect this is not a TestNG issue. I would start by trying to produce a minimal set of tests that, when run together, cause failures. After that, I would explore these possibilities: Inter-test interaction changes test-application interaction: It is possible that interaction between your tests changes how your test interactions with your application. ...


14

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, dragover and drop events on the targeted element with the file set in the dataTransfer object. This example drops an image from the file system on a drop area: ...


13

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 into maven cycle and used mostly with Data Driven testing TestNG is pure Java Annotations are easier to understand Test cases can be grouped more easily Parallel ...


12

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 we can write xpath as bellow. //div[@class='post-body entry-content']/div[1]/form[1]/input[1] Option 2 : We can use absolute xpath (full xpath) where you ...


9

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: unit, functional, end-to-end, integration, etc... Additional Features: Annotations. Run your tests in arbitrarily big thread pools with various policies ...


7

I have used Selenium and TestNG in the past to manage a lot of my automation and as Siva mentioned you do have the basics down. While TestNG is one of the most common Frameworks out there, it is not the only one, and you can use whatever one works for you. So long as you can import the Selenium drivers you can use any framework in which you are familiar, I'...


7

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 & ANT/Maven, loggers and more libraries (depending on your need). Robot: Basic programming language is enough in any language. You can train your manual ...


6

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 initialized). Hence your exception. Solution: add the following line like you did for the other classes. analyticsLandingPage landing = PageFactory.initElements(...


6

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(); } @Test (priority=2, dependsOnMethods={"CreateNew"}) public void OpenaFile() throws Exception { Runtime.getRuntime().exec("exeFiles\\OpenaFile....


5

What type of machine are you running it on? Most likely it has nothing to do with TestNG having any type of thread limits (I couldn't find anything saying there were in fact limits) but rather your local box. Thread count limits on Windows or Linux are determined by the stack space. Explanations can be found here and here. On Windows the default stack size ...


5

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[1]/form[1]/input[1]


5

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 of: a higher level selector such as the form name, e.g. //form/input[@type='submit'] a combo of non-unique selectors that together are unique e.g. //form[@class=...


5

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().exec("exeFiles\\CreateNew.exe"); process.waitFor(); Integer result = process.exitValue(); Assert.AssertEquals(0, result) } Now you can add an ...


5

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, what happens someone loses tracks of it. You introduce additional complexities to your code, additional codes being open the external file, read it and close it.


5

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("Not equal"); throw e; } System.out.println("Equal"); A more sophisticated solution would be to use TestNG's extension mechanism for logging: It's very ...


4

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 public void main1() { driver.get("http://indianrail.gov.in/pnr_Enq.html"); driver.findElement(By.id("element")).sendKeys("1234567890"); String ...


4

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' annotation from TestNG which you can easily perform stepwise operations. @Test(priority=1) public void Login() { System.out.println("LogIn Test code."); ...


4

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 takes an hour to run each test case manually, by the time the automation has "earned back" the initial development time, the software is likely to be obsolete. ...


4

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") WebElement u_Name; @FindBy(name="password") WebElement passwd; @FindBy(xpath="//*[@id=\'login-container\']/form/div[3]/div/p/input[1]" ) ...


4

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 should either run it as suite or you have to specify your xml as standard xml template (if you are using eclipse). If you are running the test using maven, add the ...


4

Can you store your 100 different website URLs into an Excel spreadsheet and run your test using data driven tests with each URL as input each time?


4

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, this configuration method will be run even if one or more methods invoked previously failed or was skipped.


4

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.Exception { Integer rowCount = 1; String stringValue = "1"; // Assert.assertEquals(rowCount,stringValue); //this fails Assert....


4

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 variable. This means, that the class-scope variable driver is never set, resulting in NullPointerException when it is referenced. To fix this, change the ...


4

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 method that runs just before the special tests' group.


4

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-method and create a task in your workflow-system might make sense, but this could lead to a lot of waste handling and monitoring these issues. Do make sure you fix ...


4

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 extend TestListenerAdapter class as it is shown below: import org.testng.ITestResult; import org.testng.TestListenerAdapter; public class ...


4

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.BeforeMethod; import org.testng.annotations.Test; public class GoogleTestTestng { WebDriver driver; // This is your first problem. @BeforeMethod public void ...


3

You are comparing values, so better you store each values in the String and compare both the String values.


3

Place this in your test or suite tag: preserve-order="false" If this is not in there, parallel classes will not work.


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