Hot answers tagged

11 votes
Accepted

Is there any way to continue selenium web driver script after assert fails?

Yes, use soft assertions org.testng.asserts.SoftAssert. Soft assertions are assertions that do not terminate the test when they fail but their results are included in the test execution report. More ...
  • 10.4k
8 votes

Exception in thread "main" java.lang.AssertionError: expected [3] but found [3]

Hi size() returns integer and you are comparing with string You can use the size() method of java. util. ArrayList to find the length or size of ArrayList in Java. The size() method returns an ...
  • 10.9k
7 votes

How to verify data is saved or not using selenium?

How do users verify the data is saved? I would make the test take the same path. In your case placing an order might result into an item in the checkout shopping-basket. Find elements in the ...
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(&...
  • 2,112
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 ...
  • 11.4k
4 votes

JUnit Assert's message equivalent implementation using Selenium Webdriver's wait method

As it seems to me, the most close equivalent to JUnit assertion messages is withMessage() method introduced in FluentWait class. Below is the example of how I use it: public class Test { public ...
  • 11.4k
3 votes

How to test forgot password link?

If you want to test it end-2-end you can use a service like https://mailtrap.io/ Here you can use an API to retrieve the email and extract the link and open the link with Selenium. Still I am ...
3 votes
Accepted

Assertion message with TestNG

I don't know that there's necessarily a better or cleaner way than your example, but I can offer at least one alternative: Boolean saved = webDriver.findElement(By.name("CreatePostbox")).isDisplayed()...
3 votes
Accepted

[Selenium]getAttribute using "textContent" - assertion fails when 'equals' is used but works when 'contains' is used

Obviously, label contains some extra characters beyond "Login ID". Could be spaces. Print it out to find out what it is. Your problem is (IMHO) not being new to Selenium but being new to programming ...
3 votes

Assert in TestNG (Actual int value, Expected int value)

public static void assertEquals(int actual, int expected, java.lang.String message) Asserts that two ints are equal. If they are not, ...
  • 6,749
3 votes

How do I verify a Link URL using Selenium Webdriver / TestNG?

I can see multiple solutions: Parse HTML page you test, e.g., with some XML+XPath+JSoup libraries, and check whether element you selected has a right link. This will not work with XHR/AJAX requests, ...
  • 10.4k
3 votes

How to use assertion to compare both different size of the rows?

There are a few different ways to achieve that depending on how you prefer to do things: As another person has commented you don't appear to need those int declarations, so can just use the .size() ...
  • 534
3 votes

Assertion on static value or calculated one

I would consider the whole idea of verifying such logic from the UI perspective as a bad practice. See info on test pyramid. If you need to test the calculation logic of your service - you can do ...
2 votes
Accepted

Assertion about size of an XML tag

Regexp is your friend matches(//ns:XPathToIt/ns:password,'\w{7,}') The \w{7,} will match a string with 7 characters. In the Expected Result put "true". SoapUI Assertions
  • 3,222
2 votes

Assert in TestNG (Actual int value, Expected int value)

The TestNG Assert documentation describes a function assertNotEquals Assert.assertNotEquals(length, 0); This does what you want I guess, if not you can also check with assertEquals with some extra ...
2 votes

How to verify a success message using selenium webdriver?

First two points: I cannot see any "Dear admin" in the message and instead of "assertEquals" try "assertTrue" and "contains". Then try: String expectedMessage = "The Institution is deleted ...
  • 181
2 votes

Is there any way to continue selenium web driver script after assert fails?

You can create extension methods for directly asserting elements. There you can wrap the assert statements with a try catch. In the catch, you can add the exception message to a log if you have one. ...
2 votes
Accepted

What elements should I assert for automation of my eCommerce application?

It depends on your testing objectives, the number of verifications you can do to a website is infinite. We have no background knowledge about your project so it is hard for us to understand what "...
  • 9,740
2 votes

Efficient way to test data quality of database through java?

You might want to take look at the DataTable of cucumber-jvm since you've been using it anyway. The idea is to use one of its diff methods to compare the expected to the actual state of the database. ...
2 votes
Accepted

How to write Assertion in Selenium Cucumber BDD?

You need to import Junit.Assert in your Step Definition file and then you can use them as normal assert statements inside the Step Implementation. For example, @Then(​"^the total price should be (\...
  • 3,540
2 votes

How to verify data is saved or not using selenium?

I agree with Niels` suggestion of checking the database. An alternative could be refreshing the page, or navigating back and forth and asserting that you still see the value. That would imply that the ...
2 votes
Accepted

Is it necessary to Assert web page title in every case?

NO, don't litter tests with loads of asserts. Have one test that you have reached the correct page. Other tests should navigate to the page and then perform additional actions which are tested. If ...
1 vote

How to convert a String to int on assert

To get the string value of an int, you can use: String.valueOf(int)
  • 356
1 vote

Unable to open an .xlsx file with script in Selenium WebDriver - getting InvalidFormatException

Use file extension to handle WorkSheet Type String inputFilename = new File(path).getName(); switch (inputFilename.substring(inputFilename.lastIndexOf(".") + 1, inputFilename.length())) { ...
  • 516
1 vote

How to verify the body context using Assert command

Assert : Reminder : If Assert get failed the execution or program get terminated there itself. It can be used as follows: Assert.assertEquals(driver.findElement(By.id("your_element_id")).getText(), ...
1 vote

How to verify a success message using selenium webdriver?

I look to use css first and for the elements and attributes I try to be as specific as needed without being overly specific and tying myself into page structure. In this case I would consider using: ...
1 vote

Is it possible to display the assertion results in the View Results Tree listener itself in Jmeter?

View Results Tree Listener displays failed assertions: If you're doing some functional testing with low number of virtual users (threads) and need to see verbose assertion results you need to choose ...
  • 12.7k
1 vote

What is the use of waitForPageLoad() method in Framework when our test scripts don't execute unless the page is loaded by default

But why to write this method as the selenium scripts doesn't execute when we navigate to next page and the page isn't loaded completely. Ok I totally get why you feel that piece of code is trivial. ...
1 vote

Assertion error when comparing the text of an element

driver.findElement(By.cssSelector("div.container-fluid > h3")) The findElement returns a WebElement and not its text and thus you cannot compare them like that. WebElements have a function ...
1 vote

Selenium IDE assertion, text in commented body tag

It looks like it could be possible to reach comment element iside oyu body tag with //body::comment(), but unfortunatelly it is not possible in Selenium IDE as it results in error = TypeError: e....
  • 1,344

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