Serenity BDD doesn't take screenshots with appium - selenium

I have a problem with Serenity BDD using the Screenplay Pattern with appium (I'm using Appium 1.3.1), the project do not generate the Screenshots in each Step, the generated report doesn't show the capture of the step, but in my code i don't have any issue or error in the IDE, this is my code and the capture of the Serenity Report:
import net.serenitybdd.junit.runners.SerenityRunner;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.abilities.BrowseTheWeb;
import net.serenitybdd.screenplay.questions.page.TheWebPage;
import net.thucydides.core.annotations.Issue;
import net.thucydides.core.annotations.Managed;
import net.thucydides.core.annotations.Screenshots;
import net.thucydides.core.annotations.Steps;
import net.thucydides.core.annotations.findby.By;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.remote.DesiredCapabilities;
import com.Otherpackage.tasks.OpenTheApplication;
import com.Otherpackage.tasks.Search;
import com.Otherpackage.tasks.escribeNombre;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import static net.serenitybdd.screenplay.GivenWhenThen.*;
import static net.serenitybdd.screenplay.EventualConsequence.eventually;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.hasItem;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;
#RunWith(SerenityRunner.class)
public class SearchByKeywordStory {
Actor anna = Actor.named("Anna");
#Managed
public static AppiumDriver<WebElement> herBrowser;
#Steps
OpenTheApplication openTheApplication;
#Before
public void annaCanBrowseTheWeb() {
anna.can(BrowseTheWeb.with(herBrowser));
}
#Test
public void search_results_should_show_the_search_term_in_the_title() throws
MalformedURLException, InterruptedException {
String packagename = "com.facebook.katana";
String URL="http://127.0.0.1:4723/wd/hub";
String activityname = "com.facebook.katana.LoginActivity";
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Galaxy S5");
capabilities.setCapability("udid", "284596bb");
capabilities.setCapability("platformVersion", "8.0");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("appPackage", packagename);
capabilities.setCapability("appActivity", activityname);
capabilities.setCapability("noReset", true);
herBrowser= new AndroidDriver<WebElement>(new URL(URL), capabilities);
herBrowser.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(4000);
when(anna).attemptsTo(escribeNombre.yacasi());
}
}
this is the other class "escribeNombre" that contain the Step:
package com.Otherpackage.tasks;
import static net.serenitybdd.screenplay.Tasks.instrumented;
import static org.openqa.selenium.Keys.ENTER;
import org.openqa.selenium.WebElement;
import com.accenture.features.search.SearchByKeywordStory;
import com.accenture.ui.SearchBox;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
import net.serenitybdd.screenplay.actions.Click;
import net.serenitybdd.screenplay.actions.Enter;
import net.thucydides.core.annotations.Step;
public class escribeNombre implements Task {
#Step("Abre la App y busca nombre")
public <T extends Actor> void performAs(T actor) {
WebElement num3 =
SearchByKeywordStory.herBrowser.findElementByClassName
("android.widget.EditText"); //Click a la barra de busqueda.
num3.sendKeys("Daniel Correa \n");
}
public static escribeNombre yacasi() {
return instrumented(escribeNombre.class);
}
}
and this is the Serenity Report, doesn't take any screenshot in the steps
https://i.imgur.com/uKkMGeE.png
anyone can help me with this? in the webpage it have little documentation about using it with appium, http://thucydides.info/docs/serenity-staging/#_running_tests_on_appium
if you have and example with serenity with appium would be great help for me
thanks for reading and sorry for my hardcoded code

Can you try setting serenity.take.screenshots=AFTER_EACH_STEP in serenity.properties file.
You can follow this thread about screenshots are not found in the serenity report.
This gives idea about getting screenshots on reports.

Related

How can I implement the Android Car API for Andorid Studio to read out my EVs percentage?

I'm currently trying to display the percentage of my Ev Via Android Auto. I can't manage to get CarInfo carInfo = getCarContext().getCarService(CarHardwareManager.class).getCarInfo(); to run. I used this in my automotive build.gradle useLibrary 'android.car' and tried importing many things but that didn't help obviously.
This is my first file:
package com.example.aatest4;
import android.car.Car;
import android.car.CarInfoManager;
import android.content.Intent;
import androidx.annotation.NonNull;
import androidx.car.app.CarAppMetadataHolderService;
import androidx.car.app.CarAppService;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.Session;
import androidx.car.app.hardware.CarHardwareManager;
import androidx.car.app.hardware.info.CarInfo;
import androidx.car.app.validation.HostValidator;
//import android.content.ServiceConnection;
public class HelloWorldService extends CarAppService {
#NonNull
#Override
public HostValidator createHostValidator() {
return HostValidator.ALLOW_ALL_HOSTS_VALIDATOR;
}
public Session onCreateSession() {
return new Session() {
#NonNull
#Override
public Screen onCreateScreen(#NonNull Intent intent) {
CarInfo carInfo = getCarContext().getCarService(CarHardwareManager.class).getCarInfo();
return new HelloWorldScreen(getCarContext());
}
};
}
}
and this my second:
package com.example.aatest4;
//import android.car.Car;
//import android.car.CarInfoManager;
import androidx.annotation.NonNull;
import androidx.car.app.CarContext;
import androidx.car.app.Screen;
import androidx.car.app.model.Pane;
import androidx.car.app.model.PaneTemplate;
import androidx.car.app.model.Row;
import androidx.car.app.model.Template;
public class HelloWorldScreen extends Screen {
//public HelloWorldScreen() {
public HelloWorldScreen(CarContext carContext) {
super(carContext);
}
#NonNull
#Override
public Template onGetTemplate() {
String akku = String.valueOf(50);
Row row = new Row.Builder().setTitle(akku + "% ").addText(akku + "%").build();
return new PaneTemplate.Builder(new Pane.Builder().addRow(row).build()) .setTitle("Akkuanzeige").build();
//Todo: Center?
}
}

Facing issue while using #Factory and #dataprovider in Testng

1. Could you please help me, looks like #factory, #dataProvider and
#dependsOn not working properly, here i have two inputs Client A and
Client B but i am only able to get only Client B not able to get the
Client A, looks like few methods are unreachable while executing,
really need help, How to handle this kind of issue
Below is my testNg.xml
<!DOCTYPE suite SYSTEM "https://testng.org/testng-1.0.dtd">
<suite name="Suite1" group-by-instances="true" verbose="1">
<parameter name="suit-param" value="This is at suite level"></parameter>
<test name="Test1">
<classes>
<class name="com.brcc.tool.Rm_Saa.RmUi"/>
</classes>
</test>
</suite>
Config class
public class DriverConfig {
public WebDriver driver;
public Properties prop = new Properties();
#BeforeSuite
public void setUp() throws IOException {
System.setProperty("webdriver.gecko.driver","drivers/geckodriver.exe");
driver = new FirefoxDriver();
FileInputStream ip = new FileInputStream(
"config.properties");
prop.load(ip);
driver.navigate().to(prop.getProperty("RmUrl"));
}
}
Below Is my testNg code
package com.brcc.tool.Rm_Saa;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.io.FileWriter;
import java.time.Duration;
import org.openqa.selenium.By;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.FluentWait;
import org.openqa.selenium.support.ui.Select;
import org.openqa.selenium.support.ui.Wait;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Factory;
import org.testng.annotations.Test;
import com.brcc.tool.Configuration.DriverConfig;
import com.brcc.tool.Configuration.SftpConn;
public class RmUi extends DriverConfig {
WebDriverWait wait;
private String data;
#BeforeSuite
public void beforeClass() throws Exception{
wait = new WebDriverWait(driver,60);
System.out.println("Before Test case");
}
#DataProvider
public static Iterator<Object[]> getTestData() throws Exception {
ArrayList<Object[]> getclientProduct = new ArrayList<Object[]>();
Object[] obj1 = {"Client A"};
Object[] obj2 = {"Client B"};
getclientProduct.add(obj1);
getclientProduct.add(obj2);
return getclientProduct.iterator();
}
#Factory(dataProvider = "getTestData")
public RmUi(String s) {
this.data = s;
}
#Test(priority = 1)
public void getTest() throws Exception {
System.out.println("login");
System.out.println("Client in Login = "+data);
// Next Test case later create a new test case and put below code
}
#Test(priority = 2,dependsOnMethods="getTest")
public void getRmApp() throws Exception {
System.out.println("getRmApp = "+data);
}
#Test(priority = 3,dependsOnMethods="getRmApp")
public void radioButton() throws Exception {
wait = new WebDriverWait(driver, 10);
System.out.println("radioButton ="+data);
}
#Test(priority = 4,retryAnalyzer = com.brcc.tool.RetryFailedTestCases.RetryTestCases.class,dependsOnMethods="radioButton")
public void clickOutputbatch()
{
System.out.println("clieckOutputbatch ="+data);
}
#Test(priority = 5,dependsOnMethods="clickOutputbatch")
public void getbatchReleaseStatus() throws Exception {
System.out.println("getbatchReleaseStatus ="+data);
System.out.println("_______________________________________________");
}
}
My Actual output
Before Test case
login
Client in Login = Client B
getRmApp = Client B
radioButton =Client B
clieckOutputbatch =Client B
getbatchReleaseStatus =Client B
_______________________________________________
login
Client in Login = Client A
getRmApp = Client A
radioButton =Client A
clieckOutputbatch =Client A
getbatchReleaseStatus =Client A
My Expected output
Before Test case
login
Client in Login = Client B
getRmApp = Client B
radioButton =Client B
clieckOutputbatch =Client B
getbatchReleaseStatus =Client B
_______________________________________________
login
Client in Login = Client A
getRmApp = Client A
After looking at the code you shared, I can confirm that the issue is present in your test code.
In your class DriverConfig you are instantiating a WebDriver object within a #BeforeSuite annotated method. #BeforeSuite by definition is meant to be executed only once per <suite> tag. What this means is that if your factory ended up producing two instances, the driver object would be instantiated ONLY for one of the instances and for the other one it would be null.
You are coupling this with a WebDriverWait that is perhaps taking in a null driver instance.
To fix this, you would need to get rid of your #BeforeSuite and replace it with #BeforeClass annotation. Here the assumption is that
you would like the same webdriver instance to be shared by multiple #Test methods in the same class.
your #Test methods in the same test class (of which your #Factory is producing instances) do not open up individual websites and work on it but instead try to operate on the same website.
your #Test methods in the test class, will NOT run in parallel, because if they do, then your tests will fail because multiple #Test methods are now going to be sharing the same WebDriver instance.
If you are keen on doing thread safe concurrent parallel executions wherein
Every #Test method is a standalone entity by itself and does things only within itself.
You would like all your #Test methods to be able to run in parallel,
then take a look at this library that I built for this very exact purpose
https://github.com/RationaleEmotions/autospawn

I am getting an empty pie chart in my selenium (java) extent report. Its appearing all black

I am generating an extent report for my selenium test script.It is not a maven project. It's a simple java project. The version of extentReports jar used is 2.41.2.
I am able to generate an html report but the problem is that the PASS/FAIL results are not reflecting in my extent report. I am getting an all black Pie chart in the report. Please refer the screen shot.
Please refer the picture of my extent report.
Below is my code block :
GenerateExtentReports.java (This class contains the methods to generate the extent report) :
package SeleniumReports;
import java.io.File;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import org.testng.Assert;
import org.testng.ITestResult;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
public class GenerateExtentReports {
ExtentReports extent;
ExtentTest test;
ITestResult res;
#BeforeTest
public void reportSetup(){
System.out.println("BeforTest_reportSetup");
Calendar mycalendar = Calendar.getInstance();
SimpleDateFormat formatter=new SimpleDateFormat("dd/mm/yyyy_hhmmss");
String timestamp=formatter.format(mycalendar.getTime());
extent=new ExtentReports(System.getProperty("user.dir")+"/TestOutput/My First Report"+timestamp+".html",true);
extent.addSystemInfo("Host Name", "Rashmi").addSystemInfo("Environment", "QA").addSystemInfo("User Name", "Rashmi Sharma");
extent.addSystemInfo("Host Name", "Rashmi").addSystemInfo("Environment", "QA").addSystemInfo("User Name", "Rashmi Sharma");
extent.loadConfig(new File(System.getProperty("user.dir")+"\\extent-config.xml"));
test=extent.startTest("loginUsingExcelData");
System.out.println(extent.startTest("loginUsingExcelData").getRunStatus().toString());
}
#AfterMethod
public void getResults(ITestResult res) {
System.out.println("AfterMethod_getResults");
// TODO Auto-generated method stub
if(res.getStatus()==ITestResult.SUCCESS){
//test.log(LogStatus.PASS, res.getThrowable());
}
else if(res.getStatus()==ITestResult.FAILURE){
test.log(LogStatus.FAIL, res.getThrowable());
}
else if(res.getStatus()==ITestResult.SKIP){
test.log(LogStatus.SKIP, res.getThrowable());
}
else if(res.getStatus()==ITestResult.STARTED){
test.log(LogStatus.INFO, "Test started");
}
System.out.println("TestLogs conditions end here");
extent.flush();
extent.endTest(test);
}}
loginUsingIterator.java (This class contains my test script) :
package SeleniumReports;
import static org.testng.Assert.assertTrue;
import java.io.File;
//import com.relevantcodes.extentreports.LogStatus;
import java.io.FileInputStream;
import java.io.IOException;
import java.lang.reflect.Method;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.apache.poi.xssf.usermodel.XSSFCell;
import org.apache.poi.xssf.usermodel.XSSFRow;
import org.apache.poi.xssf.usermodel.XSSFSheet;
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.ITestResult;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import com.relevantcodes.extentreports.ExtentReports;
import com.relevantcodes.extentreports.ExtentTest;
import com.relevantcodes.extentreports.LogStatus;
import SeleniumReports.MyMethods;
public class loginUsingIterator extends GenerateExtentReports {
WebDriver dr;
FileInputStream fin;
XSSFWorkbook wb;
XSSFSheet sh;
XSSFCell cell;
XSSFRow row;
ExtentReports extent;
ExtentTest test;
#BeforeClass
public void initialisation(){
//extent.startTest("initialisation");
System.out.println("BeforeClass_initialisation");
System.setProperty("webdriver.chrome.driver","C:\\Chrome selenium driver\\chromedriver.exe");
dr=new ChromeDriver();
dr.manage().deleteAllCookies();
dr.get("http://automationpractice.com/index.php");
//test.log(LogStatus.INFO, "Navigating to URL");
dr.manage().window().maximize();
//dr.findElement(By.xpath("//a[#class='login']")).click();
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
}
#Test
public void loginUsingExcelData() throws Exception{
//GenerateExtentReports extRep=new GenerateExtentReports();
//extRep.reportSetup();
fin=new FileInputStream("C:\\Users\\A638081\\SEL_Workspace\\ExtentReports\\TestData.xlsx");
wb=new XSSFWorkbook(fin);
sh=wb.getSheetAt(0);
Iterator rows=sh.rowIterator();
while(rows.hasNext()){
dr.findElement(By.xpath("//a[#class='login']")).click();
row=(XSSFRow) rows.next();
if(row.getRowNum()==0){
continue;
}
Iterator cells=row.cellIterator();
while(cells.hasNext()){
cell=(XSSFCell) cells.next();
//cell.setCellType(cell.CELL_TYPE_STRING);
System.out.println(cell.getStringCellValue());
dr.findElement(By.xpath("//input[#id='email']")).clear();
dr.findElement(By.xpath("//input[#id='email']")).sendKeys(cell.getStringCellValue());
dr.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
cell=(XSSFCell) cells.next();
System.out.println(cell.getStringCellValue());
dr.findElement(By.xpath("//input[#id='passwd']")).clear();
dr.findElement(By.xpath("//input[#id='passwd']")).sendKeys(cell.getStringCellValue());
dr.findElement(By.xpath("//button[#id='SubmitLogin']")).click();
MyMethods AddToCart=new MyMethods(dr);
AddToCart.addingToCart();
dr.findElement(By.xpath("//a[#class='logout']")).click();
//test.log(LogStatus.INFO, "Payment processed");
//extent.endTest(test);
System.out.println("first cycle completed");
}
}
}
#AfterTest
public void quit() throws IOException{
System.out.println("Entered tear down loop");
//System.out.println(test.getTest().getName().toString());
//System.out.println(extent.get.getRunStatus().toString());
fin.close();
dr.close();
dr.quit();
}}
Can anyone help?
I am struggling since a week.
You're missing ExtentHtmlReporter.
Change the below line in your code:
extent=new ExtentReports(System.getProperty("user.dir")+"/TestOutput/My First Report"+timestamp+".html",true);
To
ExtentHtmlReporter extentHtmlReporter = ExtentHtmlReporter(System.getProperty("user.dir")+"/TestOutput/My First Report"+timestamp+".html");
Extent.attachReporter(extentHtmlReporter):

Trying to retrieve the values from dropdown using Selenium WebElement into Array or List

I am trying to get all the values from the dropdown element into an Array or List. Can you please let me know if there is any delivered function or way to do it?
Select.getOptions() comes to mind.
Read the API docs for additional information.
import java.util.List;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Example {
public static void main(String[] args) {
WebDriver driver = new FirefoxDriver();
driver.get("http://www.Example.com/");
//List the Values
List<WebElement> options = driver.findElements(By.xpath("//*[#id='m']//option"));
//Count the Values
System.out.println(options.size());
for(int i=0;i<options.size();i++){
//Print the text
System.out.println(options.get(i).getText());
String optionName = options.get(i).getText();
//If u want to select the perticular Value
if(optionName.equals("xxxxx")){
options.get(i).click();
}
}
}
}

HSQLDB inmemory mode doesn't delete files on shutdown

I'm using HSQLDB version 2.2.9 for testing purposes.
When I create named in memory database, files aren't deleted after calling shutdown function. On my filesystem I have folder DBname.tmp and files DBname.lck, DBname.log, DBname.properties and DBname.script. As I understand documentation (http://hsqldb.org/doc/2.0/guide/dbproperties-chapt.html#dpc_connection_url) it shouldn't happened.
For testing I'm using the following code:
import java.io.IOException;
import org.hsqldb.Server;
import org.hsqldb.persist.HsqlProperties;
import org.hsqldb.server.ServerAcl.AclFormatException;
import org.junit.Test;
public class HSQLDBInMemTest {
#Test
public void test() throws IOException, AclFormatException {
HsqlProperties props = new HsqlProperties();
props.setProperty("server.database.0", "test1");
props.setProperty("server.dbname.0", "test1");
props.setProperty("server.database.1", "test2");
props.setProperty("server.dbname.1", "test2");
Server hsqlServer = new Server();
hsqlServer.setRestartOnShutdown(false);
hsqlServer.setNoSystemExit(true);
hsqlServer.setProperties(props);
hsqlServer.start();
hsqlServer.shutdown();
}
}
Answered here: http://sourceforge.net/mailarchive/message.php?msg_id=30881908 by fredt
The code should look like:
import java.io.IOException;
import org.hsqldb.Server;
import org.hsqldb.persist.HsqlProperties;
import org.hsqldb.server.ServerAcl.AclFormatException;
import org.junit.Test;
public class HSQLDBInMemTest {
#Test
public void test() throws IOException, AclFormatException {
HsqlProperties props = new HsqlProperties();
props.setProperty("server.database.0", "mem:test1");
props.setProperty("server.database.1", "mem:test2");
Server hsqlServer = new Server();
hsqlServer.setRestartOnShutdown(false);
hsqlServer.setNoSystemExit(true);
hsqlServer.setProperties(props);
hsqlServer.start();
hsqlServer.shutdown();
}
}
The path for a memory database looks like props.setProperty("server.database.0", "mem:test1");