I am trying to create a single method to verify multiple items from a single widget.
I am using selenium webdriver with TestNG
e.g A single widget (contains which is using amcharts) could have multiple elements with in a single widget (using this website as an example of what I am trying to explain http://ift.tt/Wv3o3R it will be the bar chart with the trend line)
As you can see there are multiple bars but within a widget.
Steps:
- Verify the SVG Item Exist
- Verify colours of the SVG item
- Verify Values of SVG (Only available when hovered over
So I have managed to work everything how to implement all of the above but I would like to verify multiple elements (as listed above) in a single method instead of repeating myself.
Code:
public Widget barChartWidgetUOMWithHelpTextWithOUTSelectionPanel(final String widgetName, final String svgID, String expected, final String zeroPercentOffSet, final String hundredPercentOffSet, final int decimalPlaces, final BigDecimal unit) {
WebElement element = driver.findElement(By.xpath(widgetName+"/div[2]//*[@transform='translate("+svgID+")']"));
Actions builder = new Actions(driver);
builder.moveToElement(element)
.build().perform();
String actual = driver.findElement(By.xpath(widgetName+"/div[2]//*[@class='amcharts-balloon-div']")).getText();
actual = StringUtils.remove(actual, ",");
actual = StringUtils.remove(actual, " ");
actual = StringUtils.substring(actual, StringUtils.indexOf(actual, ":")+1);
actual = StringUtils.substring(actual, StringUtils.indexOf(actual, ":")+1);
expected = StringUtils.remove(expected, ",");
expected = StringUtils.remove(expected, " ");
expected = StringUtils.substring(expected, StringUtils.indexOf(expected, ":")+1);
expected = StringUtils.substring(expected, StringUtils.indexOf(expected, ":")+1);
BigDecimal expectedRounded = new BigDecimal(expected).multiply(unit).setScale(decimalPlaces, RoundingMode.HALF_EVEN);
Assert.assertTrue(new BigDecimal(actual).subtract(expectedRounded).abs().doubleValue() <= 0.05, "actual and expected must be equal within 0.05");
String actualGradiantColour1 = driver.findElement(By.xpath(widgetName+"/div[2]//*[@offset='0%']")).getAttribute("stop-color");
String actualGradiantColour2 = driver.findElement(By.xpath(widgetName+"/div[2]//*[@offset='100%']")).getAttribute("stop-color");
Assert.assertEquals(actualGradiantColour1, zeroPercentOffSet);
Assert.assertEquals(actualGradiantColour2, hundredPercentOffSet);
return waitForPage();
}
So currently when I write this I have to put this
public static void test() {
Widget widget = new Widget(Driver.driver);
RightHandSideFilter rightHandFilter = new RightHandSideFilter(Driver.driver);
SpaceSummaryPage spaceSummary = HomePage.get(Driver.driver).navBar().navigateToReportsSpaceSummary();
boolean iselementpresent = Methods.isElementPresent(By.xpath("//*[@transform='translate("+SVGPath.spaceSummaryRegionReportableAreabyLocationEurope+")']"));
if (!iselementpresent) {
Actions actions = new Actions(Driver.driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
}
widget.assertTitle(SVGPath.spaceSummaryRegionReportableAreabyLocationEurope, "Europe:2,045.73", "#ab0000", "#d75813", 2, AdminFinancialCurrencyPage.sqm
}
but I would like to write something like this
public static void test() {
Widget widget = new Widget(Driver.driver);
RightHandSideFilter rightHandFilter = new RightHandSideFilter(Driver.driver);
SpaceSummaryPage spaceSummary = HomePage.get(Driver.driver).navBar().navigateToReportsSpaceSummary();
boolean iselementpresent = Methods.isElementPresent(By.xpath("//*[@transform='translate("+SVGPath.spaceSummaryRegionReportableAreabyLocationEurope+")']"));
if (!iselementpresent) {
Actions actions = new Actions(Driver.driver);
actions.keyDown(Keys.CONTROL).sendKeys(Keys.END).perform();
}
widget.assertTitle(SVGPath.spaceSummaryRegionReportableAreabyLocationEurope, "Europe:2,045.73", "#ab0000", "#d75813", 2, AdminFinancialCurrencyPage.sqm,
SVGPath.spaceSummaryRegionReportableAreabyLocationAfrica,"Africa:603.13", "#ab0000", "#d75813", 2, AdminFinancialCurrencyPage.sqm,
SVGPath.spaceSummaryRegionReportableAreabyLocationAsiaAndAustrailia,"Asia and Australia:1,393.45", "#ab0000", "#d75813", 2 ,AdminFinancialCurrencyPage.sqm,
SVGPath.spaceSummaryRegionReportableAreabyLocationAmericanAndCaribbean,"America and Caribbean:887.13", "#ab0000", "#d75813", 2, AdminFinancialCurrencyPage.sqm);
}
Any help would be much appreciated.
Aucun commentaire:
Enregistrer un commentaire