How to use TestData method of com.galenframework.tests.parser.ExpectationsTest class

Best Galen code snippet using com.galenframework.tests.parser.ExpectationsTest.TestData

Source:ExpectationsTest.java Github

copy

Full Screen

...41 deleteSystemProperty("galen.range.approximation");42 deleteSystemProperty("galen.reporting.listeners");43 GalenConfig.getConfig().reset();44 }45 @Test(dataProvider = "rangeValueTestData")46 public void rangeValueTest(String textForParsing, RangeValue expected) {47 RangeValue rangeValue = new ExpectRangeValue().read(new StringCharReader(textForParsing));48 MatcherAssert.assertThat(rangeValue, is(expected));49 }50 @DataProvider51 public Object[][] rangeValueTestData() {52 return new Object[][] {53 {"0", new RangeValue(0, 0)},54 {"123", new RangeValue(123, 0)},55 {"0.0", new RangeValue(0, 1)},56 {"1.0", new RangeValue(10, 1)},57 {"-1.0", new RangeValue(-10, 1)},58 {"-15.04567", new RangeValue(-1504567, 5)},59 {"15.04567", new RangeValue(1504567, 5)}60 };61 }62 @Test(dataProvider = "rangeTestData")63 public void expectRangeTest(String textForParsing, Range expected) {64 StringCharReader stringCharReader = new StringCharReader(textForParsing);65 Range range = new ExpectRange().read(stringCharReader);66 MatcherAssert.assertThat(range, is(expected));67 }68 69 70 @DataProvider71 public Object[][] rangeTestData() {72 return new Object[][]{73 {"10 to 15 px", Range.between(10, 15)},74 {"10.0 to 15.4 px", Range.between(new RangeValue(100, 1), new RangeValue(154, 1))},75 {"10 to 15px", Range.between(10, 15)},76 {"10to15px", Range.between(10, 15)},77 {"-15to-10px", Range.between(-15, -10)},78 {"-15.04to-10px", Range.between(new RangeValue(-1504, 2), new RangeValue(-10))},79 {"10to15 px", Range.between(10, 15)},80 {"9 px", Range.exact(9)},81 {"9px", Range.exact(9)},82 {"9.01px", Range.exact(new RangeValue(901, 2))},83 {" 9px", Range.exact(new RangeValue(9))},84 {"\t9px", Range.exact(9)},85 {"\t9\t\tpx", Range.exact(9)},86 {"-49px", Range.exact(-49)},87 {"~100px", Range.between(98, 102)},88 {"~1000px", Range.between(998, 1002)},89 {"~1px", Range.between(-1, 3)},90 {"~0px", Range.between(-2, 2)},91 {" ~0px", Range.between(-2, 2)},92 {">10px", Range.greaterThan(10)},93 {"> 10px", Range.greaterThan(10)},94 {"<10px", Range.lessThan(10)},95 {"< 10px", Range.lessThan(10)},96 {"<= 10px", Range.lessThanOrEquals(10)},97 {">= 10px", Range.greaterThanOrEquals(10)},98 {"15% of screen/width", Range.exact(15).withPercentOf("screen/width")},99 {"15.05% of screen/width", Range.exact(new RangeValue(1505, 2)).withPercentOf("screen/width")},100 {"15 to 40% of screen/height", Range.between(15, 40).withPercentOf("screen/height")},101 {"15 to 40% of item-1/some-other-stuff/a/b/c2", Range.between(15, 40).withPercentOf("item-1/some-other-stuff/a/b/c2")},102 {"~40% of item-1/some-other-stuff/a/b/c2", Range.between(38, 42).withPercentOf("item-1/some-other-stuff/a/b/c2")},103 {"> 67 % of object/width", Range.greaterThan(67).withPercentOf("object/width")},104 {" < 30% of object/width", Range.lessThan(30).withPercentOf("object/width")},105 {" > 70% of parent/width", Range.greaterThan(70).withPercentOf("parent/width")}106 };107 }108 109 @Test(dataProvider = "provideBadRangeSamples")110 public void shouldGiveError_forIncorrectRanges(TestData<String> testData) {111 StringCharReader stringCharReader = new StringCharReader(testData.textForParsing);112 113 SyntaxException exception = null;114 try {115 new ExpectRange().read(stringCharReader);116 }117 catch (SyntaxException e) {118 exception = e;119 }120 121 assertThat("Exception should be", exception, is(notNullValue()));122 assertThat("Exception message should be", exception.getMessage(), is(testData.expected));123 }124 125 @DataProvider126 public Object[][] provideBadRangeSamples() {127 return new Object[][] {128 row("0", "Expecting \"px\", \"to\" or \"%\", got \"\""),129 row("0p", "Expecting \"px\", \"to\" or \"%\", got \"p\""),130 row("0 p", "Expecting \"px\", \"to\" or \"%\", got \"p\""),131 row("0PX", "Expecting \"px\", \"to\" or \"%\", got \"PX\""),132 row("10 to 20", "Expecting \"px\", got \"\""),133 row("10 to 20p", "Expecting \"px\", got \"p\""),134 row("10 to 20%", "Missing value path for relative range"),135 row("10 to 20% of ", "Missing value path for relative range"),136 row("10% to 20% of ", "Missing value path for relative range"),137 };138 }139 140 141 @Test(dataProvider = "wordTestData")142 public void expectWord(TestData<String> testData) {143 StringCharReader stringCharReader = new StringCharReader(testData.textForParsing);144 String word = new ExpectWord().read(stringCharReader);145 assertThat(word, is(testData.expected));146 }147 148 @DataProvider149 public Object[][] wordTestData() {150 return new Object[][]{151 row("object", "object"),152 row(" object", "object"),153 row("\tobject ", "object"),154 row("\t\tobject\tanother", "object"),155 row("o ject", "o"),156 row("o123-123124-_124/124|12qw!@#$%^^&*().<>?:\"[]{} ject", "o123-123124-_124/124|12qw!@#$%^^&*().<>?:\"[]{}"),157 row(" je ct", "je")158 };159 }160 161 @Test(dataProvider="wordWithBreakingSymbolTestData")162 public void expectWordWithBreakingSymbol(String text, char breakingSymbol, String expectedWord) {163 StringCharReader stringCharReader = new StringCharReader(text);164 String word = new ExpectWord().stopOnTheseSymbols(breakingSymbol).read(stringCharReader);165 assertThat(word, is(expectedWord));166 }167 168 @DataProvider169 public Object[][] wordWithBreakingSymbolTestData() {170 return new Object[][]{171 new Object[]{"Hi, John!", ',', "Hi"},172 new Object[]{" Hi, John!", ',', "Hi"},173 new Object[]{" HiJohn", 'o', "HiJ"},174 new Object[]{"HiJohn", '!', "HiJohn"}175 };176 }177 178 @Test(dataProvider = "sideTestData")179 public void expectSides(TestData<List<Side>> testData) {180 StringCharReader stringCharReader = new StringCharReader(testData.textForParsing);181 List<Side> sides = new ExpectSides().read(stringCharReader);182 183 Side[] expected = testData.expected.toArray(new Side[testData.expected.size()]);184 assertThat(sides.size(), is(expected.length));185 assertThat(sides, contains(expected));186 }187 188 @DataProvider189 public Object[][] sideTestData() {190 return new Object[][]{191 row("left right", sides(Side.LEFT, Side.RIGHT)),192 row(" \tleft\t right ", sides(Side.LEFT, Side.RIGHT)),193 row(" left ", sides(Side.LEFT)),194 row("top left ", sides(Side.TOP, Side.LEFT)),195 row("top left bottom ", sides(Side.TOP, Side.LEFT, Side.BOTTOM))196 };197 }198 199 @Test(dataProvider = "locationsTestData")200 public void expectLocations(TestData<List<Location>> testData) {201 StringCharReader stringCharReader = new StringCharReader(testData.textForParsing);202 List<Location> sides = new ExpectLocations().read(stringCharReader);203 204 Location[] expected = testData.expected.toArray(new Location[testData.expected.size()]);205 assertThat(sides.size(), is(expected.length));206 assertThat(sides, contains(expected));207 }208 209 @DataProvider210 public Object[][] locationsTestData() {211 return new Object[][]{212 row("10 px left right, 10 to 20 px top bottom", locations(new Location(Range.exact(10), sides(Side.LEFT, Side.RIGHT)), new Location(Range.between(10, 20), sides(Side.TOP, Side.BOTTOM)))),213 row("10 px left, 10 to 20 px top bottom, 30px right", locations(new Location(Range.exact(10), sides(Side.LEFT)),214 new Location(Range.between(10, 20), sides(Side.TOP, Side.BOTTOM)),215 new Location(Range.exact(30), sides(Side.RIGHT)))),216 row(" 10 px left right , 10 to 20 px top bottom ", locations(new Location(Range.exact(10), sides(Side.LEFT, Side.RIGHT)), new Location(Range.between(10, 20), sides(Side.TOP, Side.BOTTOM)))),217 row("\t10 px left right\t,\t10 to 20 px\ttop\tbottom \t \t \t", locations(new Location(Range.exact(10), sides(Side.LEFT, Side.RIGHT)), new Location(Range.between(10, 20), sides(Side.TOP, Side.BOTTOM)))),218 };219 }220 221 @Test(dataProvider = "provideBadLocations")222 public void shouldGiveError_forIncorrectLocations(String text, String expectedErrorMessage) {223 StringCharReader stringCharReader = new StringCharReader(text);224 225 SyntaxException exception = null;226 try {227 new ExpectLocations().read(stringCharReader);228 }229 catch (SyntaxException e) {230 exception = e;231 }232 233 assertThat("Exception should be", exception, is(notNullValue()));234 assertThat("Exception message should be", exception.getMessage(), is(expectedErrorMessage));235 }236 237 @DataProvider238 public Object[][] provideBadLocations() {239 return new Object[][]{240 {"left", "Cannot parse range value: \"\""},241 {"10px qwe", "Unknown side: \"qwe\""},242 {"10 to 30px qwe", "Unknown side: \"qwe\""},243 {"10 to 30% of screen/width qwe", "Unknown side: \"qwe\""},244 {"10px left qwe", "Unknown side: \"qwe\""},245 {"10px left, 20px qwe", "Unknown side: \"qwe\""},246 {"10px left, 20px left qwe", "Unknown side: \"qwe\""},247 {"10px left, right, top", "Cannot parse range value: \"\""},248 };249 }250 @Test251 public void shouldParse_commaSeparatedKeyValue() {252 String text = ",param1 1, param2 v a l u e 2, booleanParam, param3 2.3, param1 2";253 List<Pair<String, String>> params = new ExpectCommaSeparatedKeyValue().read(new StringCharReader(text));254 assertThat(params.size(), is(5));255 assertThat(params.get(0).getKey(), is("param1"));256 assertThat(params.get(0).getValue(), is("1"));257 assertThat(params.get(1).getKey(), is("param2"));258 assertThat(params.get(1).getValue(), is("v a l u e 2"));259 assertThat(params.get(2).getKey(), is("booleanParam"));260 assertThat(params.get(2).getValue(), is(""));261 assertThat(params.get(3).getKey(), is("param3"));262 assertThat(params.get(3).getValue(), is("2.3"));263 assertThat(params.get(4).getKey(), is("param1"));264 assertThat(params.get(4).getValue(), is("2"));265 }266 @Test267 public void shouldParse_commaSeparatedKeyValue_2() {268 String text = "param1 1, param2 2";269 List<Pair<String, String>> params = new ExpectCommaSeparatedKeyValue().read(new StringCharReader(text));270 assertThat(params.size(), is(2));271 assertThat(params.get(0).getKey(), is("param1"));272 assertThat(params.get(0).getValue(), is("1"));273 assertThat(params.get(1).getKey(), is("param2"));274 assertThat(params.get(1).getValue(), is("2"));275 }276 277 278 private List<Location> locations(Location...locations) {279 return Arrays.asList(locations);280 }281 private List<Side> sides(Side...sides) {282 return Arrays.asList(sides);283 }284 private <T> Object[] row(String textForParsing, T expectedRange) {285 return new Object[]{new TestData<>(textForParsing, expectedRange)};286 }287 private class TestData<T> {288 private String textForParsing;289 private T expected;290 291 public TestData(String textForParsing, T expected) {292 this.textForParsing = textForParsing;293 this.expected = expected;294 }295 296 @Override297 public String toString() {298 return StringEscapeUtils.escapeJava(textForParsing);299 }300 }301 302}...

Full Screen

Full Screen

TestData

Using AI Code Generation

copy

Full Screen

1import com.galenframework.parser.ExpectationParser2import com.galenframework.specs.Expectation3import com.galenframework.specs.ExpectationText4import com.galenframework.specs.reader.ExpectationReader5import com.galenframework.specs.reader.StringCharReader6import org.testng.annotations.DataProvider7import org.testng.annotations.Test8import static org.hamcrest.MatcherAssert.assertThat9import static org.hamcrest.Matchers.is10class ExpectationsTest {11 @Test(dataProvider = "expectations")12 void should_parse_expectation(String expectationText, Expectation expectation) {13 ExpectationReader expectationReader = new ExpectationReader(new StringCharReader(expectationText))14 Expectation parsedExpectation = new ExpectationParser(expectationReader).readExpectation()15 assertThat(parsedExpectation, is(expectation))16 }17 Object[][] expectations() {18 return new Object[][]{19 ["should be 100px", new ExpectationText("should be 100px")],20 ["should be 100px or 200px", new ExpectationText("should be 100px or 200px")],21 ["should be 100px or 200px or 300px", new ExpectationText("should be 100px or 200px or 300px")],22 ["should be 100px or 200px or 300px or 400px", new ExpectationText("should be 100px or 200px or 300px or 400px")],23 ["should be 100px or 200px or 300px or 400px or 500px", new ExpectationText("should be 100px or 200px or 300px or 400px or 500px")],24 ["should be 100px or 200px or 300px or 400px or 500px or 600px", new ExpectationText("should be 100px or 200px or 300px or 400px or 500px or 600px")],25 ["should be 100px or 200px or 300px or 400px or 500px or 600px or 700px", new ExpectationText("should be 100px or 200px or 300px or

Full Screen

Full Screen

TestData

Using AI Code Generation

copy

Full Screen

1import com.galenframework.tests.parser.ExpectationsTest;2import com.galenframework.tests.parser.TestData;3import org.testng.annotations.DataProvider;4public class DataProviderClass {5 @DataProvider(name = "expectations")6 public static Object[][] expectations() {7 return TestData.expectations();8 }9}10@Test(dataProvider = "expectations")11public void shouldParseExpectations(String input, String expected) {12 ExpectationsParser expectationsParser = new ExpectationsParser(input);13 Expectations expectations = expectationsParser.parse();14 assertThat(expectations.toString(), is(expected));15}16import org.testng.annotations.Test;17import static org.hamcrest.MatcherAssert.assertThat;18import static org.hamcrest.Matchers.is;19public class ExpectationsTest {20 @Test(dataProvider = "expectations")21 public void shouldParseExpectations(String input, String expected) {22 ExpectationsParser expectationsParser = new ExpectationsParser(input);23 Expectations expectations = expectationsParser.parse();24 assertThat(expectations.toString(), is(expected));25 }26}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful