How can I check if some text exist or not in the page using Selenium?

With XPath, it’s not that hard. Simply search for all elements containing the given text: List<WebElement> list = driver.findElements(By.xpath(“//*[contains(text(),'” + text + “‘)]”)); Assert.assertTrue(“Text not found!”, list.size() > 0); The official documentation is not very supportive with tasks like this, but it is the basic tool nonetheless. The JavaDocs are greater, but it takes some … Read more

Making Python’s `assert` throw an exception that I choose

This will work. But it’s kind of crazy. try: assert False, “A Message” except AssertionError, e: raise Exception( e.args ) Why not the following? This is less crazy. if not someAssertion: raise Exception( “Some Message” ) It’s only a little wordier than the assert statement, but doesn’t violate our expectation that assert failures raise AssertionError. … Read more

xUnit Equivalent of MSTest’s Assert.Inconclusive

Best thing one can do until something is implemented in the library is to use Xunit.SkippableFact: [SkippableFact] public void SomeTest() { var canRunTest = CheckSomething(); Skip.IfNot(canRunTest); // Normal test code } This will at least make it show up as a yellow ignored test case in the list. Credit goes to https://stackoverflow.com/a/35871507/537842

Assert a good practice or not?

In principle, assertions are not that different from many other run-time checkings. For example, Java bound-checks all array accesses at run-time. Does this make things a bit slower? Yes. Is it beneficial? Absolutely! As soon as out-of-bound violation occurs, an exception is thrown and the programmer is alerted to any possible bug! The behavior in … Read more

NSAssert vs. assert: Which do you use, and when?

To answer your two questions: There should be very little performance hit for leaving in an assertion, unless the actual action in the assertion is time consuming (e.g. assert([obj calculateMeaningOfLife] == 42)). An assertion should be no different than an extra if statement, performance-wise. The reason for stripping out assertions in release builds is that … Read more

Will an assertion error be caught by in a catch block for java exception?

You have almost answered your own question. Your catch block will not catch the AssertionError that the Assert throws if it fails, because it is an Error (or, more specifically, it extends java.lang.Error). See the docs for more information on this. Your catch block only catches Throwable objects that extend java.lang.Exception If you really want … Read more

Java/ JUnit – AssertTrue vs AssertFalse

assertTrue will fail if the second parameter evaluates to false (in other words, it ensures that the value is true). assertFalse does the opposite. assertTrue(“This will succeed.”, true); assertTrue(“This will fail!”, false); assertFalse(“This will succeed.”, false); assertFalse(“This will fail!”, true); As with many other things, the best way to become familiar with these methods is … Read more

Rails ActiveSupport: How to assert that an error is raised?

So unit testing isn’t really in activesupport. Ruby comes with a typical xunit framework in the standard libs (Test::Unit in ruby 1.8.x, MiniTest in ruby 1.9), and the stuff in activesupport just adds some stuff to it. If you are using Test::Unit/MiniTest assert_raise(Exception) { whatever.merge } if you are using rspec (unfortunately poorly documented, but … Read more

What’s the difference between Assert.AreNotEqual and Assert.AreNotSame?

Almost all the answers given here are correct, but it’s probably worth giving an example: public static string GetSecondWord(string text) { // Yes, an appalling implementation… return text.Split(‘ ‘)[1]; } string expected = “world”; string actual = GetSecondWord(“hello world”); // Good: the two strings should be *equal* as they have the same contents Assert.AreEqual(expected, actual); … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)