Filter by tags:
July 6, 2020
Tip : formatter function example for high chart advanced properties
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Visualization : Column / Vertical bar chart
Problem statement : How to write highcharts function in Jasperreport expression ?
Add a $ sign to Y axis labels
Add a $ sign to Y axis labels
Navigation : YAxis > labels > formatter > Select for expression
NOTE : Ensure to add the below property in jasperreports.properties file
com.jaspersoft.jasperreports.highcharts.function.properties.allowed=true
Path : C:\Jaspersoft\jasperreports-server-7.5.0\apache-tomcat\webapps\jasperserver-pro\WEB-INF\classes
Sample screenshot:
Sample output:
References:
JRXML (works on 7.2 studio professional)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Stop Loss Plan Performance" pageWidth="620" pageHeight="470" whenNoDataType="AllSectionsNoDetail" columnWidth="620" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="f5ee6cd9-fdbd-4655-a337-ef2568c81a56">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="ireport.jasperserver.url" value="http://localhost:8080/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser"/>
<property name="ireport.jasperserver.report.resource" value="/LOCKTON_2020_21/S8_Stop_Loss_Plan_Performance_files/main_jrxml"/>
<property name="ireport.jasperserver.reportUnit" value="/LOCKTON_2020_21/S8_Stop_Loss_Plan_Performance"/>
<property name="com.jaspersoft.studio.report.unit.description" value="001_RP_Stop Loss Marketing Analysis"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<property name="com.jaspersoft.jasperreports.highcharts.interactive" value="false"/>
<subDataset name="Dataset1-Claims Vs Premium" uuid="ba6bd55c-4dcd-431c-aa4b-587d99dd0b60">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="foodmart"/>
<queryString language="SQL">
<![CDATA[SELECT '2018' AS year, 400000 AS value, 'Premium' AS PremiumClaim
UNION ALL
SELECT '2018' AS year, 850000 AS value, 'Claim' AS PremiumClaim
UNION ALL
SELECT '2019' AS year, 450000 AS value, 'Premium' AS PremiumClaim
UNION ALL
SELECT '2019' AS year, 60000 AS value, 'Claim' AS PremiumClaim
UNION ALL
SELECT '2020' AS year, 210000 AS value, 'Premium' AS PremiumClaim
UNION ALL
SELECT '2020' AS year, 5000 AS value, 'Claim' AS PremiumClaim]]>
</queryString>
<field name="year" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="year"/>
</field>
<field name="value" class="java.lang.Integer">
<property name="com.jaspersoft.studio.field.label" value="value"/>
</field>
<field name="premiumclaim" class="java.lang.String">
<property name="com.jaspersoft.studio.field.label" value="premiumclaim"/>
</field>
</subDataset>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<summary>
<band height="460" splitType="Stretch">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<image>
<reportElement x="0" y="70" width="330" height="4" uuid="6c9ee3ac-3d60-4c0e-a2d3-8d09a4777b01">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
<printWhenExpression><![CDATA[1==0]]></printWhenExpression>
</reportElement>
<imageExpression><![CDATA["repo:/Test/Images/test/horizontal_heading_bar.png"]]></imageExpression>
</image>
<textField>
<reportElement x="50" y="25" width="530" height="40" uuid="c43bf219-e07c-4286-afcd-c8136a487828"/>
<textElement verticalAlignment="Bottom">
<font fontName="Garamond" size="30"/>
</textElement>
<textFieldExpression><![CDATA["Test"]]></textFieldExpression>
</textField>
<componentElement>
<reportElement x="70" y="120" width="550" height="280" uuid="fc2b6ea6-7033-4af9-aa74-9efda7096ec8"/>
<hc:chart xmlns:hc="http://jaspersoft.com/highcharts" xsi:schemaLocation="http://jaspersoft.com/highcharts http://jaspersoft.com/schema/highcharts.xsd" type="Column">
<hc:chartSetting name="default">
<hc:chartProperty name="title.text" value=""/>
<hc:chartProperty name="credits.enabled" value="false"/>
<hc:chartProperty name="credits.href" value=""/>
<hc:chartProperty name="credits.text" value=""/>
<hc:chartProperty name="yAxis.title.text" value=""/>
<hc:chartProperty name="chart.zoomType" value="xy"/>
<hc:chartProperty name="legend.itemStyle.fontSize" value="8px"/>
<hc:chartProperty name="yAxis.labels.formatter">
<hc:propertyExpression><![CDATA["function() {return '$' + this.axis.defaultLabelFormatter.call(this);}"]]></hc:propertyExpression>
</hc:chartProperty>
<hc:chartProperty name="yAxis.tickInterval_customSimpleMode" value="true"/>
<hc:chartProperty name="yAxis.tickInterval">
<hc:propertyExpression><![CDATA[200000]]></hc:propertyExpression>
</hc:chartProperty>
</hc:chartSetting>
<multiAxisData>
<multiAxisDataset>
<dataset>
<datasetRun subDataset="Dataset1-Claims Vs Premium" uuid="e9b1c867-29a5-4cd7-abd7-76b0d846367f"/>
</dataset>
</multiAxisDataset>
<dataAxis axis="Rows">
<axisLevel name="Level1">
<labelExpression><![CDATA["Level Label expression"]]></labelExpression>
<axisLevelBucket order="None" class="java.lang.Comparable">
<bucketExpression><![CDATA[$F{year}]]></bucketExpression>
</axisLevelBucket>
</axisLevel>
</dataAxis>
<dataAxis axis="Columns">
<axisLevel name="Series1">
<labelExpression><![CDATA[]]></labelExpression>
<axisLevelBucket order="None" class="java.lang.Comparable">
<bucketExpression><![CDATA[$F{premiumclaim}]]></bucketExpression>
</axisLevelBucket>
</axisLevel>
</dataAxis>
<multiAxisMeasure name="Measure1" class="java.lang.Number" calculation="Nothing">
<labelExpression><![CDATA["Value:"]]></labelExpression>
<valueExpression><![CDATA[$F{value}]]></valueExpression>
</multiAxisMeasure>
</multiAxisData>
<hc:series name="Measure1"/>
</hc:chart>
</componentElement>
</band>
</summary>
</jasperReport>
July 6, 2020
July 1, 2020
Tip : Square bullets example in Jaspersoft Reports - Unicode square bullets example in Jaspersoft D…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Sample Design
Sample Output
Text field expression
"\u25AA\u0020This is small square bullet\n\n\u25fc\u0020This is medium square bullet\n\n\u25fe\u0020This is square bullet\n\n\u25a1\u0020This is square bullet\n\n\u25fd\u0020This is square bullet"
References:
JRXML: (Version 7.2 pro)
<?xml version="1.0" encoding="UTF-8"?>
<!-- Created with Jaspersoft Studio version 7.2.0.final using JasperReports Library version 6.6.0 -->
<jasperReport xmlns="http://jasperreports.sourceforge.net/jasperreports" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreports http://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="Renewal Packet Outline" pageWidth="620" pageHeight="470" whenNoDataType="AllSectionsNoDetail" columnWidth="620" leftMargin="0" rightMargin="0" topMargin="0" bottomMargin="0" uuid="f5ee6cd9-fdbd-4655-a337-ef2568c81a56">
<property name="com.jaspersoft.studio.data.sql.tables" value=""/>
<property name="com.jaspersoft.studio.data.defaultdataadapter" value="Sample DB"/>
<property name="ireport.jasperserver.url" value="https://dev-lockton-cms.seventablets.com/jasperserver-pro/"/>
<property name="ireport.jasperserver.user" value="superuser"/>
<property name="ireport.jasperserver.report.resource" value="/organizations/organization_1/Lockton_Reports_1/Sub_Reports/Stoploss_Renewal_Packet_Sub_Reports/Renewal_Packet_Outline_files/main_jrxml"/>
<property name="ireport.jasperserver.reportUnit" value="/organizations/organization_1/Lockton_Reports_1/Sub_Reports/Stoploss_Renewal_Packet_Sub_Reports/Renewal_Packet_Outline"/>
<property name="com.jaspersoft.studio.report.unit.description" value="001_RP_Stop Loss Marketing Analysis"/>
<property name="com.jaspersoft.studio.unit." value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageHeight" value="pixel"/>
<property name="com.jaspersoft.studio.unit.pageWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.topMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.bottomMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.leftMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.rightMargin" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnWidth" value="pixel"/>
<property name="com.jaspersoft.studio.unit.columnSpacing" value="pixel"/>
<queryString language="SQL">
<![CDATA[]]>
</queryString>
<summary>
<band height="460" splitType="Stretch">
<image>
<reportElement x="0" y="70" width="330" height="4" uuid="6c9ee3ac-3d60-4c0e-a2d3-8d09a4777b01">
<property name="com.jaspersoft.studio.unit.height" value="px"/>
<property name="com.jaspersoft.studio.unit.x" value="px"/>
<property name="com.jaspersoft.studio.unit.width" value="px"/>
</reportElement>
<imageExpression><![CDATA["repo:/Lockton_Reports_1/Images/Renewal_Packet_Images/horizontal_heading_bar.png"]]></imageExpression>
</image>
<textField>
<reportElement x="50" y="26" width="350" height="44" uuid="c43bf219-e07c-4286-afcd-c8136a487828"/>
<textElement verticalAlignment="Bottom">
<font fontName="Garamond" size="30"/>
</textElement>
<textFieldExpression><![CDATA["Unicode Square Bullets Demo"]]></textFieldExpression>
</textField>
<textField>
<reportElement mode="Opaque" x="121" y="150" width="419" height="100" forecolor="#FFFFFF" backcolor="#3C6280" uuid="68d10f97-69cf-4fae-85b0-f2b5fdb33e73"/>
<box leftPadding="5"/>
<textElement markup="none">
<font fontName="Segoe UI" size="12"/>
</textElement>
<textFieldExpression><![CDATA["\u25AA\u0020This is small square bullet\n\n\u25fc\u0020This is medium square bullet\n\n\u25fe\u0020This is square bullet\n\n\u25a1\u0020This is square bullet\n\n\u25fd\u0020This is square bullet"]]></textFieldExpression>
</textField>
</band>
</summary>
</jasperReport>
July 1, 2020
June 5, 2020
In java-selenium, how to navigate through web data table using pagination buttons and verify the di…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
In this blog, we'll discuss below real time use cases of data tables automation in selenium.
1) How to navigate through a data table buttons till the last page ?
2) How to calculate the actual row count of data table ?
3) Compare the actual row count to the displayed row count.
Below is the flow..
1) Declare and initiate the web driver.
2) Navigate to the data table on web page.
3) Create a list and store the "names" column data values for the first page (i.e., for first 10 values)
4) Logic : Traverse through the table until Next button get disabled (use while loop).
5) Logic : add the elements during the looping to the list (use for loop to add the list created in #3)
6) Calculate the size of the list i.e., actual count of data table.
7) Extract the displayed count i..e, displayed count of data table on web page.
8) Compare the actual count with displayed count.
Take a look at the lines highlighted in light green color in the following code that has the above flow.
Please watch this space for video tutorial to walk through the code
In this blog, we'll discuss below real time use cases of data tables automation in selenium.
1) How to navigate through a data table buttons till the last page ?
2) How to calculate the actual row count of data table ?
3) Compare the actual row count to the displayed row count.
Below is the flow..
1) Declare and initiate the web driver.
2) Navigate to the data table on web page.
3) Create a list and store the "names" column data values for the first page (i.e., for first 10 values)
4) Logic : Traverse through the table until Next button get disabled (use while loop).
5) Logic : add the elements during the looping to the list (use for loop to add the list created in #3)
6) Calculate the size of the list i.e., actual count of data table.
7) Extract the displayed count i..e, displayed count of data table on web page.
8) Compare the actual count with displayed count.
Take a look at the lines highlighted in light green color in the following code that has the above flow.
Please watch this space for video tutorial to walk through the code
DataTableButtonsNavigationActualVsDisplayedRowCount.java
package selenium.datatables;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
@SuppressWarnings("unused")
public class DataTableButtonsNavigationActualVsDisplayedRowCount {
public static WebDriver driver;
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver_83.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
driver = new ChromeDriver();
driver.get("https://datatables.net/examples/basic_init/zero_configuration.html");
driver.manage().window().maximize();
compareDispalyedRowCountToActualRowCount();
}
public static void compareDispalyedRowCountToActualRowCount() throws Exception {
try {
Thread.sleep(5000);
List<WebElement> namesElements = driver.findElements(By.cssSelector("#example>tbody>tr>td:nth-child(1)"));
System.out.println("size of names elements : " + namesElements.size());
List<String> names = new ArrayList<String>();
//Adding column1 elements to the list
for (WebElement nameEle : namesElements) {
names.add(nameEle.getText());
}
//Displaying the list elements on console
for (WebElement s : namesElements) {
System.out.println(s.getText());
}
//locating next button
String nextButtonClass = driver.findElement(By.id("example_next")).getAttribute("class");
//traversing through the table until the last button and adding names to the list defined about
while (!nextButtonClass.contains("disabled")) {
driver.findElement(By.id("example_next")).click();
Thread.sleep(1000);
namesElements = driver.findElements(By.cssSelector("#example>tbody>tr>td:nth-child(1)"));
for (WebElement nameEle : namesElements) {
names.add(nameEle.getText());
}
nextButtonClass = driver.findElement(By.id("example_next")).getAttribute("class");
}
//printing the whole list elements
for (String name : names) {
System.out.println(name);
}
//counting the size of the list
int actualCount = names.size();
System.out.println("Total number of names :" + actualCount);
//locating displayed count
String displayedCountString = driver.findElement(By.id("example_info")).getText().split(" ")[5];
int displayedCount = Integer.parseInt(displayedCountString);
System.out.println("Total Number of Displayed Names count:" + displayedCount);
Thread.sleep(1000);
// Actual count calculated Vs Dispalyed Count
if (actualCount == displayedCount) {
System.out.println("Actual row count = Displayed row Count");
} else {
System.out.println("Actual row count != Displayed row Count");
throw new Exception("Actual row count != Displayed row Count");
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
References:
1) https://www.youtube.com/watch?v=jD5eWhNsaRk
Hope you find this is useful, stay tuned for more automation.!
June 5, 2020
June 4, 2020
Tip : How to fix --> DEBUG cache:45 - Couldn't find template in cache for "index.ftl&q…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi,
When you receive the following DEBUG for Maven based cucumber java selenium project that is configured with extent reports, it can be fixed in log4j.properties by adding the following property.
Fix : in log4j.properties
Issue:
When you receive the following DEBUG for Maven based cucumber java selenium project that is configured with extent reports, it can be fixed in log4j.properties by adding the following property.
Fix : in log4j.properties
log4j.logger.freemarker.cache = INFO, CONSOLE
Issue:
2020-06-05 09:13:30 DEBUG cache:45 - Couldn't find template in cache for "index.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:30 DEBUG cache:45 - TemplateLoader.findTemplateSource("index_en.ftl"): Not found
2020-06-05 09:13:30 DEBUG cache:45 - TemplateLoader.findTemplateSource("index.ftl"): Found
2020-06-05 09:13:30 DEBUG cache:45 - Loading template for "index.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/index.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "head.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("head_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("head.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "head.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/head.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "nav.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("nav_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("nav.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "nav.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/nav.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "test-view/test-view.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("test-view/test-view_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("test-view/test-view.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "test-view/test-view.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/test-view/test-view.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "test-view/test-view-charts.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("test-view/test-view-charts_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("test-view/test-view-charts.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "test-view/test-view-charts.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/test-view/test-view-charts.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "test-view/bdd.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("test-view/bdd_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("test-view/bdd.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "test-view/bdd.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/test-view/bdd.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - "test-view/bdd.ftl"("en", UTF-8, parsed) cached copy not yet stale; using cached.
2020-06-05 09:13:31 DEBUG cache:45 - "test-view/bdd.ftl"("en", UTF-8, parsed) cached copy not yet stale; using cached.
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "category-view/category-view.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("category-view/category-view_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("category-view/category-view.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "category-view/category-view.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/category-view/category-view.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "author-view/author-view.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("author-view/author-view_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("author-view/author-view.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "author-view/author-view.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/author-view/author-view.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "exception-view/exception-view.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("exception-view/exception-view_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("exception-view/exception-view.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "exception-view/exception-view.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/exception-view/exception-view.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "dashboard-view/dashboard-view.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("dashboard-view/dashboard-view_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("dashboard-view/dashboard-view.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "dashboard-view/dashboard-view.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/dashboard-view/dashboard-view.ftl"
2020-06-05 09:13:31 DEBUG cache:45 - Couldn't find template in cache for "logs-view/testrunner-logs-view.ftl"("en", UTF-8, parsed); will try to load it.
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("logs-view/testrunner-logs-view_en.ftl"): Not found
2020-06-05 09:13:31 DEBUG cache:45 - TemplateLoader.findTemplateSource("logs-view/testrunner-logs-view.ftl"): Found
2020-06-05 09:13:31 DEBUG cache:45 - Loading template for "logs-view/testrunner-logs-view.ftl"("en", UTF-8, parsed) from "jar:file:/C:/Users/sadakarp/.m2/repository/E1SmapiUiAutomation/E1SmapiUiAutomation/0.0.1-SNAPSHOT/E1SmapiUiAutomation-0.0.1-SNAPSHOT-jar-with-dependencies.jar!/com/aventstack/extentreports/view/html-report/logs-view/testrunner-logs-view.ftl"
June 4, 2020
May 28, 2020
How to compare displayed drop down select values(actual values displayed) are matching with user ex…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi, in this post, we will learn about how to auto compare the displayed drop down select values to the user expected drop down values.
i.e , compare "actual values displayed" to the "user expected values" for the drop down select for a web data table.
Zoom-In by tapping the image:
The approach is as follows:
1) Declare a list for user expected values of an integer(later in the code convert to sting)
or String type.
2) Locate the drop down select element on the web using xpath locator technique.
3) Create an object of "Select" class with the argument of drop down select element. (from #2)
4) Store the values of actual values displayed in another list of type WebElement
5) Compare the two lists and confirm the equality.
user expected values
actual values displayed
Compare the two lists
Console Log:
I hope you find this post is useful, stay tuned for more automation.!
i.e , compare "actual values displayed" to the "user expected values" for the drop down select for a web data table.
Zoom-In by tapping the image:
The approach is as follows:
1) Declare a list for user expected values of an integer(later in the code convert to sting)
or String type.
2) Locate the drop down select element on the web using xpath locator technique.
3) Create an object of "Select" class with the argument of drop down select element. (from #2)
4) Store the values of actual values displayed in another list of type WebElement
5) Compare the two lists and confirm the equality.
user expected values
List<Integer> expectedDropDownValues = new ArrayList<Integer>()
{
{
add(10);
add(25);
add(50);
add(100);
}
};
actual values displayed
WebElement entriesDropDownLocator = driver.findElement(By.xpath("//select[@name='example_length']"));
Select entriesDropDown = new Select(entriesDropDownLocator);
List<WebElement> actualDropDownValues = entriesDropDown.getOptions();
Compare the two lists
for(int i=0;i<actualDropDownValues.size();i++) {
if(actualDropDownValues.get(i).getText().equals(expectedDropDownValues.get(i).toString())) {
System.out.println("Value Matching :"+"Actual List Value="+actualDropDownValues.get(i).getText()+" And Expected Value="+expectedDropDownValues.get(i));
}else {
System.out.println("Value Not Matching :"+"Actual List Value="+actualDropDownValues.get(i).getText()+" And Expected Value="+expectedDropDownValues.get(i));
}
}
CompareDisplayedDropdownSelectValuesWithActualValues.java
package selenium.datatables;
import java.util.ArrayList;
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class CompareDisplayedDropdownSelectValuesWithActualValues {
public static WebDriver driver;
public void compareDispalyedRowCountToActualRowCount() throws Exception {
@SuppressWarnings("serial")
List<Integer> expectedDropDownValues = new ArrayList<Integer>()
{
{
add(10);
add(25);
add(50);
add(100);
}
};
System.out.println("Expected dropdown values for accounts table");
for (Integer expectedOptions : expectedDropDownValues) {
System.out.println(expectedOptions.toString());
}
WebElement entriesDropDownLocator = driver.findElement(By.xpath("//select[@name='example_length']"));
Select entriesDropDown = new Select(entriesDropDownLocator);
List<WebElement> actualDropDownValues = entriesDropDown.getOptions();
System.out.println("Actual dropdown values from accounts table");
for (WebElement actualValues : actualDropDownValues) {
System.out.println(actualValues.getText());
}
System.out.println("Compare the actual values with the expected values for dropdown");
for(int i=0;i<actualDropDownValues.size();i++) {
if(actualDropDownValues.get(i).getText().equals(expectedDropDownValues.get(i).toString())) {
System.out.println("Value Matching :"+"Actual List Value="+actualDropDownValues.get(i).getText()+" And Expected Value="+expectedDropDownValues.get(i));
}else {
System.out.println("Value Not Matching :"+"Actual List Value="+actualDropDownValues.get(i).getText()+" And Expected Value="+expectedDropDownValues.get(i));
}
}
}
public void closeDriver() {
driver.close();
}
public void quitDriver() {
driver.quit();
}
public static void main(String[] args) throws Exception {
CompareDisplayedDropdownSelectValuesWithActualValues c = new CompareDisplayedDropdownSelectValuesWithActualValues();
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver.exe");
System.setProperty("webdriver.chrome.silentOutput","true" );
driver = new ChromeDriver();
driver.get("https://datatables.net/examples/basic_init/zero_configuration.html");
driver.manage().window().maximize();
c.compareDispalyedRowCountToActualRowCount();
c.closeDriver();
c.quitDriver();
}
}
Console Log:
Expected dropdown values for accounts table
10
25
50
100
Actual dropdown values from accounts table
10
25
50
100
Compare the actual values with the expected values for dropdown
Value Matching :Actual List Value=10 And Expected Value=10
Value Matching :Actual List Value=25 And Expected Value=25
Value Matching :Actual List Value=50 And Expected Value=50
Value Matching :Actual List Value=100 And Expected Value=100
I hope you find this post is useful, stay tuned for more automation.!
May 28, 2020
How to compare displayed row count on web page is equals to data table calculated row count in java…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi , In this tutorial, we'll learn about how to compare displayed row count on page is equals to data table row count in java selenium.
There are several ways to accomplish this, by the time I write this article, I've come across two ways.
They are
1) Calculate the no. of rows in data table by navigating through the pagination buttons.
2) Calculate the no. of rows in data table by using jQuery "length" function.
We will see the latter implementation in this post.
Tap on to the image to get better visibility of content :
The approach is as follows.
1. Wait for sometime to load the page for which data table is present.
2. Take an integer variable say "dataTableActualRowCount" with 0 as the default value.
3. Create JavascriptExecutor object for the driver.
4. Use jQuery "length" function technique within java-selenium code.
5. jQuery stores the value in Object so convert it into integer and store the jquery returned length in
dataTableActualRowCount
6. Find the displayed count from bottom of the page using WebElement finder technique and store it
in another integer variable say "displayedCountOfRowsOnPage".
7. Now, Compare the values of "dataTableActualRowCount" and
"displayedCountOfRowsOnPage".
8. If dataTableActualRowCount == displayedCountOfRowsOnPage then "displayed row count
on page is equals to data table row count " else "displayed row count on page is NOT equals
to data table row count".
dataTableActualRowCount - calculating using jQuery "length" function
displayedCountOfRowsOnPage - finding through WebElement
CompareDisplayedRowCountToDataTableRowCount.java
I hope you find this tutorial is useful, stay tuned for more automation.!
- Sadakar Pochampalli
There are several ways to accomplish this, by the time I write this article, I've come across two ways.
They are
1) Calculate the no. of rows in data table by navigating through the pagination buttons.
2) Calculate the no. of rows in data table by using jQuery "length" function.
We will see the latter implementation in this post.
Tap on to the image to get better visibility of content :
The approach is as follows.
1. Wait for sometime to load the page for which data table is present.
2. Take an integer variable say "dataTableActualRowCount" with 0 as the default value.
3. Create JavascriptExecutor object for the driver.
4. Use jQuery "length" function technique within java-selenium code.
5. jQuery stores the value in Object so convert it into integer and store the jquery returned length in
dataTableActualRowCount
6. Find the displayed count from bottom of the page using WebElement finder technique and store it
in another integer variable say "displayedCountOfRowsOnPage".
7. Now, Compare the values of "dataTableActualRowCount" and
"displayedCountOfRowsOnPage".
8. If dataTableActualRowCount == displayedCountOfRowsOnPage then "displayed row count
on page is equals to data table row count " else "displayed row count on page is NOT equals
to data table row count".
dataTableActualRowCount - calculating using jQuery "length" function
int dataTableActualRowCount=0;
JavascriptExecutor js=(JavascriptExecutor)driver;
dataTableActualRowCount = ((Number)js.executeScript("return $('#example').DataTable().rows().data().toArray().length;")).intValue();
System.out.println("Data table row count="+dataTableActualRowCount);
displayedCountOfRowsOnPage - finding through WebElement
String displayedCount = driver.findElement(By.id("example_info")).getText().split(" ")[5];
int displayedCountOfRowsOnPage = Integer.parseInt(displayedCount);
System.out.println("Data table display count on page ="+displayedCountOfRowsOnPage);
CompareDisplayedRowCountToDataTableRowCount.java
package selenium.datatables;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class CompareDisplayedRowCountToDataTableRowCount {
public static WebDriver driver;
public static void main(String[] args) throws Exception {
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver.exe");
System.setProperty("webdriver.chrome.silentOutput","true" );
driver = new ChromeDriver();
driver.get("https://datatables.net/examples/basic_init/zero_configuration.html");
driver.manage().window().maximize();
compareDispalyedRowCountToActualRowCount();
}
public static void compareDispalyedRowCountToActualRowCount() throws Exception {
Thread.sleep(10000);
int dataTableActualRowCount=0;
JavascriptExecutor js=(JavascriptExecutor)driver;
dataTableActualRowCount = ((Number)js.executeScript("return $('#example').DataTable().rows().data().toArray().length;")).intValue();
System.out.println("Data table row count="+dataTableActualRowCount);
String displayedCount = driver.findElement(By.id("example_info")).getText().split(" ")[5];
int displayedCountOfRowsOnPage = Integer.parseInt(displayedCount);
System.out.println("Data table display count on page ="+displayedCountOfRowsOnPage);
if(Integer.compare(dataTableActualRowCount, displayedCountOfRowsOnPage)==0) {
System.out.println("Displayed count on page is equals to the data table row count ");
}else {
System.out.println("Displayed count on page is NOT equals to the data table row count");
throw new Exception("Displayed count on page is NOT equals to the data table row count");
}
}
}
I hope you find this tutorial is useful, stay tuned for more automation.!
- Sadakar Pochampalli
May 28, 2020
May 26, 2020
WebElement interface methods examples in selenium - part 3 | Understanding of method isEnabled()
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi, in this post, we will walk through the usage and live example of isEnabled() method. isEnabled() method, we apply in special scenarios where in we select a check box and get the status of a button i.e., enabled or disabled. Let's take a look into the following example.
isEnabled()
Sign up button before enabled i.e., before selecting check box "I have read...."
Tap on the image to get better visibility:
Sign up button after enabled i.e., after selecting check box "I have read...."
Tap on the image to get better visibility:
The below piece of selenium script does
a) verifies the status of "Sign up" button before enabled.
b) selects the check box "I have read..." and
c) verifies the status of "Sign up" button after selecting the check box.
Watch this ~ 6 min video tutorial for the demo :
To know more about isDisplayed() or isSelected() methods, please visit this post @
isDisplayed()
isEnabled()
- To verify if an element is enabled or disabled on web-page.
- Returns "ture" if element is enabled and returns "false" if an element is disabled.
- Examples: Mostly used with button elements, locked/disabled text input elements.
Problem Statement :
Display the status of "Sign up" button - The below two images gives an idea on how the button looks before enabled and after enabled after selecting a check box.Tap on the image to get better visibility:
Sign up button after enabled i.e., after selecting check box "I have read...."
Tap on the image to get better visibility:
The below piece of selenium script does
a) verifies the status of "Sign up" button before enabled.
b) selects the check box "I have read..." and
c) verifies the status of "Sign up" button after selecting the check box.
//isEnabled() example - before selecting the check box
//display the enable or disable status of "Sign Up" button before selecting the check box
WebElement signUp = driver.findElement(By.xpath("//button[@id='signup']"));
boolean b1 = signUp.isEnabled();//false
System.out.println("Sign Up button enable/disable before selecting \"I have read and accpet...\" check box = "+b1);
//select the "I have read and accept check box
WebElement element=driver.findElement(By.xpath("//input[@id='termsAndPrivacy']"));
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOf(element));
new Actions(driver).moveToElement(element, 1, 1).click().perform();
//isEnabled() example - check box
//display the enable or disable status of "Sign Up" button after selecting the check box
boolean b2 = signUp.isEnabled();//true
System.out.println("Sign Up button enable/disable after selecting \"I have read and accpet...\" check box = "+b2);
Watch this ~ 6 min video tutorial for the demo :
WebElementInterfaceMethod_isEnabledDemo.java
package selenium.webelement.methods;
/* button isEnabled() demo */
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class WebElementInterfaceMethod_isEnabledDemo {
public static void main(String[] args) {
WebDriver driver;
//loading Chrome driver from physical drive
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
//System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
//launch the browser
driver = new ChromeDriver();
//navigate to site
driver.navigate().to("https://us.megabus.com/account-management/login");
//maximize the browser
driver.manage().window().maximize();
//close the message on site
driver.findElement(By.xpath("//i[@class='close mb-close']")).click();
// Sign Up form
WebElement signUpFromTab = driver.findElement(By.xpath("//a[@class='btn btn-link btn-block'][contains(text(),'Sign up')]"));
signUpFromTab.click();
WebElement email = driver.findElement(By.xpath("//input[@id='email']"));
email.sendKeys("java.selenium2023@gmail.com");
//Confirm Email
WebElement confirmEmail = driver.findElement(By.xpath("//input[@id='confirmEmail']"));
confirmEmail.sendKeys("java.selenium2023@gmail.com");
//Choose a Password
WebElement chooseAPassword = driver.findElement(By.xpath("//input[@id='choosePassword']"));
chooseAPassword.sendKeys("JavaSelenium2023");
//Confirm Password
WebElement confirmPassword = driver.findElement(By.xpath("//input[@id='confirmPassword']"));
confirmPassword.sendKeys("JavaSelenium2023");
//isEnabled() example - before selecting the check box
//display the enable or disable status of "Sign Up" button before selecting the check box
WebElement signUp = driver.findElement(By.xpath("//button[@id='signup']"));
boolean b1 = signUp.isEnabled();
System.out.println("Sign Up button enable/disable before selecting \"I have read and accpet...\" check box = "+b1);
//select the "I have read and accept check box
WebElement element=driver.findElement(By.xpath("//input[@id='termsAndPrivacy']"));
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOf(element));
new Actions(driver).moveToElement(element, 1, 1).click().perform();
//isEnabled() example - check box
//display the enable or disable status of "Sign Up" button after selecting the check box
boolean b2 = signUp.isEnabled();
System.out.println("Sign Up button enable/disable after selecting \"I have read and accpet...\" check box = "+b2);
signUp.click();
//close the browser
//driver.close();
//close all the browsers opened by WebDriver during execution and quit the session
//driver.quit();
}
}
To know more about isDisplayed() or isSelected() methods, please visit this post @
WebElement interface methods examples in selenium - part 2 | Understanding of methods isDisplayed() Vs isEnabled() Vs isSelected()
isDisplayed()
- To verify presence of a web-element with in the web page.
- This method returns either true or false boolean values.
- If the element is present it returns "true" otherwise it returns "false".
- This method avoids the problem of having to parse an element's "style" attribute.
- Example : This method can be applicable for all the elements on web-page.
- Returns whether an element say check box or radio button is selected or not.
- If selected returns "true", if not selected returns "false".
- Examples: Check boxes, drop downs , radio buttons
May 26, 2020
May 23, 2020
Actions(class) and Action(interface) in selenium | demonstration of keyboard events in selenium | u…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi, in this page, we will discuss about Actions(class) and Action(interface) and keyboard events example in selenium with some key take away notes.
For, mouse events tutorial, click this link.
Actions
keyUp --> for instance, Releasing a pressed Shift key
sendKeys --> used to send series of characters as text
The code snippet below holds shifts key and converts the text into capital letters using "keyDown" event and then releases the shift key using "keyUp" event.
For, mouse events tutorial, click this link.
Actions
- It is a class and the package is org.openqa.selenium.interactions.Actions
- It represents collection of individual Action that you want to perform.
- Using this class we can handle keyboard and mouse events. i.e.,
- Keyboard interface methods
- Mouse interface methods
Action
- Action is an interface
- It represents single user interaction.
- Using this interface, on the Actions object we perform series of actions.
- Most widely and must use method is perform() after creating series of actions and storing in Action
Keyboard events examples
keyDown --> for instance, Pressing a Shift keykeyUp --> for instance, Releasing a pressed Shift key
sendKeys --> used to send series of characters as text
Use case : Search text "Actions(class) and Action(interface) in selenium" in this site @ https://jasper-bi-suite.blogspot.com/ by sending the text in Capital letters.
- Locate the "search box" element and store it in WebElement variable.
- Create object "actionsBuilder" for Actions class and pass "driver" in its constructor.
- Build the series of actions on "actionBuilder" object and store it in "Action" interface variable "seriesOfKeyBoardActions" and apply build() method once the series of actions are done.
- Perform the series actions using "perform()" method on the above created Action variable say "seriesOfKeyBoardActions"
The code snippet below holds shifts key and converts the text into capital letters using "keyDown" event and then releases the shift key using "keyUp" event.
//Search box element locator
WebElement searchBox = driver.findElement(By.xpath("//input[@name='q']"));
//Actions object
Actions actionsBuilder = new Actions(driver);
//Building the series of actions
Action seriesOfKeyBoardActions = actionsBuilder
.moveToElement(searchBox) //Moves the mouse pointer to the center of the element
.click() //perform click on the serach box
.keyDown(searchBox,Keys.SHIFT) // Pressing shift key
.sendKeys(searchBox,"Actions(class) and Action(interface) in selenium") //sending search text
.keyUp(searchBox,Keys.SHIFT) // Releasing shift key
.build(); // building all the above 5 actions
//Performing the built actions
seriesOfKeyBoardActions.perform();
Watch this space for walk through video tutorial for below use-case:
KeyboardEventsSendCaptialLettersForSearchingActionsArcticle.java
/* Keyboard events demo */
package keyboard.events.examples;
import org.openqa.selenium.By;
import org.openqa.selenium.Keys;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Action;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class KeyboardEventsSendCaptialLettersForSearchingActionsArcticle {
public static void main(String[] args) {
WebDriver driver;
//loading Chrome driver from physical drive
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver_83.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
//launch the browser
driver = new ChromeDriver();
//navigate to site
driver.navigate().to("https://jasper-bi-suite.blogspot.com/");
//maximize the browser
driver.manage().window().maximize();
//Search box element locator
WebElement searchBox = driver.findElement(By.xpath("//input[@name='q']"));
//Actions object
Actions actionsBuilder = new Actions(driver);
//Building the series of actions
Action seriesOfKeyBoardActions = actionsBuilder
.moveToElement(searchBox) //Moves the mouse pointer to the center of the element
.click() //perform click on the serach box
.keyDown(searchBox,Keys.SHIFT) // Pressing shift key
.sendKeys(searchBox,"Actions(class) and Action(interface) in selenium") //sending search text
.keyUp(searchBox,Keys.SHIFT) // Releasing shift key
.build(); // building all the above 5 actions
//Performing the built actions
seriesOfKeyBoardActions.perform();
//click on Search button
WebElement searchButton = driver.findElement(By.xpath("//input[@class='gsc-search-button']"));
searchButton.click();
//close the browser
//driver.close();
//close all the browsers opened by WebDriver during execution and quit the session
//driver.quit();
}
}
Stay tuned for more automation!
- Sadakar Pochampalli
May 23, 2020
Actions(class) and Action(interface) in selenium | demonstration of mouse events in selenium| dra…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi, in this page, we will discuss about Actions(class) and Action(interface) and mouse events example in selenium with some key take away notes.
For, keyboard events tutorial, click this link.
clickAndHold(),
clickAndHold(WebElement target),
moveToElement(WebElement target),
moveToElement(WebElement target, int xOffset, int yOffset),
release() ,
release(WebElement target) and etc.
by the method calls
ready to be performed (and resets the internal builder state,
so subsequent calls to build() will contain fresh sequences).
For, keyboard events tutorial, click this link.
Actions
- It is a class and the package is org.openqa.selenium.interactions.Actions
- It represents collection of individual Action that you want to perform.
- Using this class we can handle keyboard and mouse events. i.e.,
- Keyboard interface methods
- Mouse interface methods
Action
- Action is an interface
- It represents single user interaction.
- Using this interface, on the Actions object we perform series of actions.
- Most widely and must use method is perform() after creating series of actions and storing in Action
clickAndHold(),
clickAndHold(WebElement target),
moveToElement(WebElement target),
moveToElement(WebElement target, int xOffset, int yOffset),
release() ,
release(WebElement target) and etc.
- Take a look at all the methods availabe for this class
https://www.selenium.dev/selenium/docs/api/java/index.html?org/openqa/selenium/interactions/package-tree.html - Definition by the book: The user-facing API for emulating complex user gestures. Use this class rather than using the Keyboard or Mouse directly.
by the method calls
- build() method
- The build() method is always the final method used
- All the listed actions will be compiled into a single step.
- Definition by the book:
ready to be performed (and resets the internal builder state,
so subsequent calls to build() will contain fresh sequences).
Use case : drag and drop images from source location to target
- Locate the source/from element which you want to drag and store it in a WebElement variable.
- Locate the target/to element where you want to drop the source element and store it in a WebElement variable.
- We work with Actions(class) & Action(interface) together so let's first create Actions object "builder" by attaching "driver" object.
- Build the series of actions on "builder" object and store it in "Action" interface variable say "drop1Image1".
NOTE : Must apply build() method at the end. - Perform the series actions using "perform()" method on the above created Action variable say "drop1Image1"
WebElement drag1FromImage1 = driver.findElement(By.xpath("//*[@id='gallery']//img[contains(@alt,'The peaks of High Tatras')]"));
WebElement dropImagesTo = driver.findElement(By.xpath("//div[@id='trash']"));
Actions builder = new Actions(driver);
Action drop1Image1 = builder.clickAndHold(drag1FromImage1)
.moveToElement(dropImagesTo)
.release(dropImagesTo)
.build();
drop1Image1.perform();
Demo site credits and courtesy : https://www.globalsqa.com/demo-site/draganddrop/
Click on the images to enlarge:
Before mouse events:
After mouse events:
Watch this space for walk through video tutorial for the example
MouseEventsActionsDragAndDropImagesDemo.java
//drag and drop - mouse events demo
package mouse.event.drag.and.drop.elements;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.interactions.Action;
public class MouseEventsActionsDragAndDropImagesDemo {
public static void main(String[] args) throws InterruptedException {
WebDriver driver;
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver_83.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
driver = new ChromeDriver();
driver.get("https://www.globalsqa.com/demo-site/draganddrop/");
driver.manage().window().maximize();
//drag and drop image from one location to another on web-page
// switch to Frame
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[@class='demo-frame lazyloaded']")));
// source/from location
WebElement drag1FromImage1 = driver.findElement(By.xpath("//*[@id='gallery']//img[contains(@alt,'The peaks of High Tatras')]"));
WebElement drag2FromImage2 = driver.findElement(By.xpath("//*[@id='gallery']//img[contains(@alt,'The chalet at the Green mountain lake')]"));
WebElement drag3FromImage3 = driver.findElement(By.xpath("//*[@id='gallery']//img[contains(@alt,'Planning the ascent')]"));
WebElement drag4FromImage4 = driver.findElement(By.xpath("//*[@id='gallery']//img[contains(@alt,'On top of Kozi kopka')]"));
// target/to location
WebElement dropImagesTo = driver.findElement(By.xpath("//div[@id='trash']"));
//Object of Actions class
Actions builder = new Actions(driver);
//Building the series of actions
Action drop1Image1 = builder.clickAndHold(drag1FromImage1) // without releasing clicks the the image source location
.moveToElement(dropImagesTo) //moves the mouse to the middle of target location
.release(dropImagesTo) //releases the mouse at the current mouse i.e, at target location
.build(); // build all the above 3 actions
//Performing the built actions
drop1Image1.perform();
Action drop2Image2 = builder.clickAndHold(drag2FromImage2)
.moveToElement(dropImagesTo)
.release(dropImagesTo)
.build();
drop2Image2.perform();
Action drop3Image3 = builder.clickAndHold(drag3FromImage3)
.moveToElement(dropImagesTo)
.release(dropImagesTo)
.build();
drop3Image3.perform();
Action drop4Image4 = builder.clickAndHold(drag4FromImage4)
.moveToElement(dropImagesTo)
.release(dropImagesTo)
.build();
drop4Image4.perform();
Thread.sleep(5000);
driver.quit();
}
}
Stay tuned for more automation!
- Sadakar Pochampalli
May 23, 2020
May 22, 2020
WebElement interface methods examples in selenium - part 2 | Understanding of methods isDisplayed()…
( JasperSoft BI Suite Tutorials - Sadakar Pochampalli )
Hi, In this post, we will see the differences between WebElement interface most commonly used methods - isDisplayed(), isEnabled() and isSelected() with real time example scenarios.
IsEnabled() has some special purpose of verifying elements such as buttons enabled or disabled status. Let's look into each of them.
Image and test site courtesy : https://www.testandquiz.com/selenium/testing.html
isDisplayed()
HTML for : Sample
Selenium snippet
isEnabled()
Please find this blog post for a real time login use case example in which you will see "Sign Up" button is enabled after selecting a check box of terms and conditions.
HTML
Checkout this video tutorial to understand the example below
IsEnabled() has some special purpose of verifying elements such as buttons enabled or disabled status. Let's look into each of them.
Image and test site courtesy : https://www.testandquiz.com/selenium/testing.html
isDisplayed()
- To verify presence of a web-element with in the web page.
- This method returns either true or false boolean values.
- If the element is present it returns "true" otherwise it returns "false".
- This method avoids the problem of having to parse an element's "style" attribute.
- This method can be applicable for almost all of the elements on web-page.
HTML for : Sample
<b xpath="1">This is sample text.</b>
Selenium snippet
//isDisplayed() | Text on web page | Example : This is sample text.
WebElement ThisIsSimpleText = driver.findElement(By.xpath("//b[contains(text(),'This is sample text.')]"));
boolean b1 = ThisIsSimpleText.isDisplayed();
System.out.println("Verify dispaly status of the text \"This is sample Text\"="+b1);
isEnabled()
- To verify if an element is enabled or disabled on web-page.
- Returns "ture" if element is enabled and returns "false" if an element is disabled.
- Examples: Mostly used with button elements, locked/disabled text input elements.
Please find this blog post for a real time login use case example in which you will see "Sign Up" button is enabled after selecting a check box of terms and conditions.
- Returns whether an element say check box or radio button is selected or not.
- If selected returns "true", if not selected returns "false".
- Examples: Check boxes, drop downs , radio buttons
HTML
<input id="male" type="radio" name="gender" value="male" xpath="1">
//isSelected() | Example : male radio button
WebElement maleRaditoButton = driver.findElement(By.xpath("//input[@id='male']"));
boolean b2 = maleRaditoButton.isSelected(); //false
System.out.println("Verify male radio button selected or not before click = "+b2);
//select the male radio button and verify isSelected()
maleRaditoButton.click();
boolean b3 = maleRaditoButton.isSelected(); //true
System.out.println("Verify male radio button selected or not after click = "+b3);
Checkout this video tutorial to understand the example below
WebElementInterfaceMethods_isDisplayedisSelectedDemo.java
package selenium.webelement.methods;
/* isDisplayed() , and isSelected() */
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.PageLoadStrategy;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.chrome.ChromeOptions;
public class WebElementInterfaceMethods_isDisplayedisSelectedDemo {
public static void main(String[] args) {
WebDriver driver;
//loading Chrome driver from physical drive
System.setProperty("webdriver.chrome.driver", "D:\\006_trainings\\chromedriver.exe");
System.setProperty("webdriver.chrome.silentOutput", "true");
//System.setProperty(ChromeDriverService.CHROME_DRIVER_SILENT_OUTPUT_PROPERTY, "true");
//launch the browser
driver = new ChromeDriver();
//navigate to site
driver.navigate().to("https://www.testandquiz.com/selenium/testing.html");
//maximize the browser
driver.manage().window().maximize();
//isDisplayed() | Text on web page | Example : This is sample text.
WebElement ThisIsSimpleText = driver.findElement(By.xpath("//b[contains(text(),'This is sample text.')]"));
boolean b1 = ThisIsSimpleText.isDisplayed();
System.out.println("Verify dispaly status of the text \"This is sample Text\"="+b1);
//isSelected() | Example : male radio button
WebElement maleRaditoButton = driver.findElement(By.xpath("//input[@id='male']"));
boolean b2 = maleRaditoButton.isSelected();
System.out.println("Verify male radio button selected or not before click = "+b2);
//select the male radio button and verify isSelected()
maleRaditoButton.click();
boolean b3 = maleRaditoButton.isSelected();
System.out.println("Verify male radio button selected or not after click = "+b3);
//close the browser
driver.close();
//close all the browsers opened by WebDriver during execution and quit the session
driver.quit();
}
}
May 22, 2020
Pages
About
Planet Jaspersoft aggregates blog posts from our community. If you would like your blog to be included in the Planet, please follow this help guide. Or just click this link to go straight to your Planet Feeds.
Feed Sources
- JasperSoft BI Suite Tutorials - Sadakar Pochampalli (273) Apply JasperSoft BI Suite Tutorials - Sadakar Pochampalli filter
- Technology Blog (50) Apply Technology Blog filter
- Jaspersoft Tech Talks (41) Apply Jaspersoft Tech Talks filter
- Jaspersoft Tutorials (30) Apply Jaspersoft Tutorials filter
- The Open Book on BI (26) Apply The Open Book on BI filter
- Rajesh Sirsikar (22) Apply Rajesh Sirsikar filter
- Bekwam Data as a Service (21) Apply Bekwam Data as a Service filter
- AgileTech - Ankur Gupta (19) Apply AgileTech - Ankur Gupta filter
- Ankur Gupta - Youtube (17) Apply Ankur Gupta - Youtube filter
- Digital Gene (15) Apply Digital Gene filter
- Tech Poet (13) Apply Tech Poet filter
- iTransparent - Jaspersoft Blog (9) Apply iTransparent - Jaspersoft Blog filter
- Paco Saucedo's blog » JasperReports (6) Apply Paco Saucedo's blog » JasperReports filter
- David Hoppmann's JasperServer Posts (2) Apply David Hoppmann's JasperServer Posts filter
- Jasper Related Posts from Wedjaa (1) Apply Jasper Related Posts from Wedjaa filter