assertion

Assert that a WebElement is not present using Selenium WebDriver with java

非 Y 不嫁゛ 提交于 2019-11-27 15:28:18
问题 In tests that I write, if I want to assert a WebElement is present on the page, I can do a simple: driver.findElement(By.linkText("Test Search")); This will pass if it exists and it will bomb out if it does not exist. But now I want to assert that a link does not exist. I am unclear how to do this since the code above does not return a boolean. EDIT This is how I came up with my own fix, I'm wondering if there's a better way out there still. public static void assertLinkNotPresent (WebDriver

CollectionAssert in jUnit?

旧城冷巷雨未停 提交于 2019-11-27 11:31:23
Is there a jUnit parallel to NUnit's CollectionAssert ? Joachim Sauer Using JUnit 4.4 you can use assertThat() together with the Hamcrest code (don't worry, it's shipped with JUnit, no need for an extra .jar ) to produce complex self-describing asserts including ones that operate on collections: import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.*; import static org.hamcrest.CoreMatchers.*; List<String> l = Arrays.asList("foo", "bar"); assertThat(l, hasItems("foo", "bar")); assertThat(l, not(hasItem((String) null))); assertThat(l, not(hasItems("bar",

How do I assert my exception message with JUnit Test annotation?

。_饼干妹妹 提交于 2019-11-27 08:57:26
问题 I have written a few JUnit tests with @Test annotation. If my test method throws a checked exception and if I want to assert the message along with the exception, is there a way to do so with JUnit @Test annotation? AFAIK, JUnit 4.7 doesn't provide this feature but does any future versions provide it? I know in .NET you can assert the message and the exception class. Looking for similar feature in the Java world. This is what I want: @Test (expected = RuntimeException.class, message =

Selenium assertFalse fails with staleelementreferenceexception

自作多情 提交于 2019-11-27 08:42:55
问题 I have a selenium test in Java and I am doing some assertions like that: assertFalse(isElementPresent(By.xpath("//td[2]/div"))); private boolean isElementPresent(By by) { try { driver.findElement(by); return true; } catch (NoSuchElementException e) { return false; } It´s the standard method Selenium is generating when export from IDE to Java Webdriver. (Yes I want to assert that this element is not present) I always get errors when I am testing at this above code line Error: stale element

JMeter how to NOT fail 500 Internal Server Errors

倾然丶 夕夏残阳落幕 提交于 2019-11-27 05:22:11
问题 I am using JMeter as a unit test tool, in parameterised calls where I expect some of the responses to be 500 internal server errors. I am using BeanShell Assertions to check the responses. I want some of the 500 internal server errors to NOT be marked as failures if the response contains a specified text. All 500 server errors are marked as failures. Is it possible to change the behavior? Below is an extract from the BeanShell Assertion. if (ResponseCode.equals("500")) { Failure = false;

AssertEquals 2 Lists ignore order

只谈情不闲聊 提交于 2019-11-27 04:09:20
That should be really simple question I believe. But somehow I can't find answer in Google. Assume that I have 2 Lists of Strings. First contains "String A" and "String B" , second one contains "String B" and "String A" (notice difference in order). I want to test them with JUnit to check whether they contains exactly the same Strings. Is there any assert that checks equality of Strings that ignore order? For given example org.junit.Assert.assertEquals throws AssertionError java.lang.AssertionError: expected:<[String A, String B]> but was:<[String B, String A]> Work around is to sort Lists

golang type assertion using reflect.Typeof()

℡╲_俬逩灬. 提交于 2019-11-27 02:42:19
问题 I've tried to identify a struct with string value(name). reflect.TypeOf returns Type . But type assertion needs a type . How can I casting Type to type ? Or any suggestion to handle it? http://play.golang.org/p/3PJG3YxIyf package main import ( "fmt" "reflect" ) type Article struct { Id int64 `json:"id"` Title string `json:"title",sql:"size:255"` Content string `json:"content"` } func IdentifyItemType(name string) interface{} { var item interface{} switch name { default: item = Article{} }

How to continue execution when Assertion is failed

妖精的绣舞 提交于 2019-11-26 22:58:40
I am using Selenium RC using Java with eclipse and TestNG framework. I have the following code snippet: assertTrue(selenium.isTextPresent("Please enter Email ID")); assertTrue(selenium.isTextPresent("Please enter Password")); First assertion was failed and execution was stopped. But I want to continue the further snippet of code. Selenium IDE uses verify to perform a soft assertion, meaning that the test will continue even if the check fails and either report the failures at the end of the test or on the event of a hard assertion. With TestNG it is possible to have these soft assertions by

When to use an assertion and when to use an exception

一世执手 提交于 2019-11-26 19:15:23
Most of the time I will use an exception to check for a condition in my code, I wonder when it is an appropriate time to use an assertion? For instance, Group group=null; try{ group = service().getGroup("abc"); }catch(Exception e){ //I dont log error because I know whenever error occur mean group not found } if(group !=null) { //do something } Could you indicate how an assertion fits in here? Should I use an assertion? It seems like I never use assertions in production code and only see assertions in unit tests. I do know that in most cases, I can just use exception to do the checking like

CollectionAssert in jUnit?

大城市里の小女人 提交于 2019-11-26 18:02:02
问题 Is there a jUnit parallel to NUnit's CollectionAssert? 回答1: Using JUnit 4.4 you can use assertThat() together with the Hamcrest code (don't worry, it's shipped with JUnit, no need for an extra .jar ) to produce complex self-describing asserts including ones that operate on collections: import static org.junit.Assert.assertThat; import static org.junit.matchers.JUnitMatchers.*; import static org.hamcrest.CoreMatchers.*; List<String> l = Arrays.asList("foo", "bar"); assertThat(l, hasItems("foo"