Hot answers tagged

10

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 articles on that topic: https://stackoverflow.com/questions/19091526/how-soft-assertions-work https://rameshbaskar.wordpress.com/2013/09/11/soft-assertions-...


8

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 integer equal to a number of elements present in the array list. https://www.java67.com/2016/07/how-to-find-length-size-of-arraylist-in-java.html So the ...


7

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 shopping basket and count them, get their text and validate that with an assert library (JUnit or TestNG). Simple example: WebDriver driver = new ChromeDriver(); // ...


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 ...


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

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 static void main(String[] args) { String[] paths = new String[]{ // Set proper and improper paths as an example of input "//img[@alt='Google'...


3

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 wondering if you want to test this workflow end-2-end, maybe some integration tests would suffice. Checking emails sending gets triggered, not actual testing the ...


3

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(); System.OutPrintln("Additional information is " + (saved ? "" : "NOT ") + "saved."); Assert.AssertTrue(saved); There could be many variations on this theme, ...


3

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 in general. No worries, with time you will develop good judgement. As they say: "To avoid mistakes you need good judgement. Good judgement comes from ...


3

public static void assertEquals(int actual, int expected, java.lang.String message) Asserts that two ints are equal. If they are not, an AssertionFailedError, with the given message, is thrown. Parameters: actual - the actual value expected - the expected value message - the assertion error ...


3

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, that are sent with JavaScript. Click the element you want, e.g., with Selenium Web Driver, and capture the HTTP traffic with HTTP proxy, e.g., BrowserMob Proxy. ...


3

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() call. //Assert false that one equals the other Assert.assertFalse(preRoutlList.size()==aftRoutlList.size()); //Assert True that one doesn't equal the other ...


3

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 that on the unit and/or integration testing level, which would be much easier to do, since you will be free from external dependencies in that case. UI ...


2

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


2

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 code. Pseudo code: result = false if (length == 0 ) { result = true } Assert.assertEquals(result, false)


2

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 Successfully!"; String message = driver.findElement(By.xpath("//div[contains(@class,'callout callout-success')]")).getText(); Assert.assertTrue("Your error message", ...


2

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. public static class SafeAssertExtensions { public static void AreEquals(this IWebElement element, string expectedText) { try { ...


2

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 "common assertions" are. Having said that, my personal opinions are: Verify each page title, header (normally h1). Verify if key elements are present, such as ...


2

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. In your case you could have done the diff along the following (pseudo)lines: List<User> actualUsers = new ArrayList<>(); for (User expectedUser: ...


2

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 (\\d+)c$"​) ​public​ ​void​ theTotalPriceShouldBeC(​int​ total) ​throws​ ​Throwable​ { assertEquals(total, checkout.total()); }


2

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 data is stored. But before that I would suggest talking with your development team (if that is the case here) and see if this check for storing in the ...


1

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


1

Use file extension to handle WorkSheet Type String inputFilename = new File(path).getName(); switch (inputFilename.substring(inputFilename.lastIndexOf(".") + 1, inputFilename.length())) { case "xls": return readXLS(path); case "xlsx": return readXLSX(path); default: Log.e(TAG, "No XLS file chosen"); return "...


1

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(), "Expected Text"); OR Assert.assertEquals(driver.findElement(By.id("your_element_id")).getText(), "Expected Text","Assert failed - ...


1

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: success_message=driver.findElement(By.css(".content-wrapper .callout-success")) along with success_message.contains('the text') This assumes that you don't ...


1

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 a more advanced assertion, i.e. Beanshell Assertion or JSR223 Assertion which have full control of response data, headers, messages, sample labels, log file, ...


1

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. Well we all know how good a tool Selenium is and we expect it should be at least wait for page load out. Unfortunately it is not that simple for Selenium, as ...


1

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 getText() to return the text of the object. The assert should look like this: assertEquals("Risk Assessment Form: Completed", driver.findElement(By....


1

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.scrollIntoView is not a function. Try to experiment with following knowledge of Xpath contained in this answer, but bear in mind, that Xpath in Selenium IDE could ...


1

If the position of the comment is static you can use an Xpath locator. To get the Xpath, inspect the page using Chrome (or Firefox with Firebug), find the element, right-click and select Copy Xpath. Here is an example: Page for Example: http://www.tutorialspoint.com/html/html_comments.htm // Comment to Find: <!-- PRINTING STARTS HERE --> // Use the ...


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