package com.canoo.webtest.extension;
import com.canoo.webtest.engine.StepFailedException;
import com.canoo.webtest.steps.BaseStepTestCase;
import com.canoo.webtest.steps.Step;
public class VerifyTableStepTest extends BaseStepTestCase {
private static final String HTML_PAGE_WITH_TABLE =
" "
+ "
"
+ " Test"
+ " "
+ " "
+ " "
+ " "
+ " Dénomination | Prix unitaire | Qté | Total | "
+ "
"
+ " "
+ " carotte | 1.00 | 5 | 5.00 | "
+ "
"
+ "
"
+ " "
+ "";
public void testOk() throws Exception {
VerifyTableStep myStep = (VerifyTableStep)getStep();
getContext().saveResponseAsCurrent(getDummyPage(HTML_PAGE_WITH_TABLE));
myStep.setHtmlid("tbl");
String expected = " |Dénomination |Prix unitaire |Qté |Total |\n"
+ "|carotte |1.00 |5 |5.00 |";
myStep.addText(expected);
executeStep(myStep);
}
public void test_excludedColumns() throws Exception {
VerifyTableStep myStep = (VerifyTableStep)getStep();
getContext().saveResponseAsCurrent(getDummyPage(HTML_PAGE_WITH_TABLE));
myStep.setHtmlid("tbl");
myStep.setExcludedColumns("0, 2, 3");
String expected = " |Prix unitaire |\n"
+ "|1.00 |";
myStep.addText(expected);
executeStep(myStep);
}
public void test_koWithUnmatchedNumberOfLines() throws Exception {
VerifyTableStep myStep = (VerifyTableStep)getStep();
getContext().saveResponseAsCurrent(getDummyPage(HTML_PAGE_WITH_TABLE));
myStep.setHtmlid("tbl");
String expected = "|carotte |1.00 |5 |5.00 |";
myStep.addText(expected);
try {
executeStep(myStep);
fail();
}
catch (Exception ex) {
assertEquals("Unmatching number of lines 'tbl' : expected : 1, actual : 2",
ex.getMessage());
}
}
public void test_koWithUnmatchedContent() throws Exception {
VerifyTableStep myStep = (VerifyTableStep)getStep();
getContext().saveResponseAsCurrent(getDummyPage(HTML_PAGE_WITH_TABLE));
myStep.setHtmlid("tbl");
String expected = " |Libellé |prix au kg |Quantité |Total |\n"
+ "|carotte |1.00 |5 |5.00 |";
myStep.addText(expected);
try {
executeStep(myStep);
fail();
}
catch (Throwable ex) {
assertEquals(
"Comparison failure for the table 'tbl' line 0 : expected:<[Libellé, prix au kg, Quantité, Total]> but was:<[Dénomination, Prix unitaire, Qté, Total]>",
ex.getMessage());
}
}
public void test_noIdSetShouldThrowsStepFailedException() throws Exception {
VerifyTableStep myStep = (VerifyTableStep)getStep();
try {
executeStep(myStep);
fail();
}
catch (StepFailedException ex) {
assertEquals("'htmlid' attribute of the html table should be set", ex.getMessage());
}
}
@Override
protected Step createStep() {
return new VerifyTableStep();
}
}