I am using an excel sheet :
Excel snapshot
Need to iterate over the rows, one after another after taking the values from getCelldata(rownum, colnum) and validating the same from the same row.
But here I need to iterate only the row number.
Code sample:
#Test (priority=1, description = "Login Functionality")
public void login() {
driver.get(data.getProperty("base.url"));
obj_login = new login (driver);
ExcelBase.setExcelFileSheet("Capacitor_unit");
obj_login.enter_username(ExcelBase.getCellData(3,1));
obj_login.enter_password(ExcelBase.getCellData(3,2));
obj_login.select_login();
}
The next one should be (ExcelBase.getCellData(4,1)) and then (5,1) till data ends.
Full class code overview:
public class TC01_newDesign extends TestBase{
login obj_login;
createNewDesign obj_CreateNewDesign;
saveDesign obj_SaveDesign;
capacitorUnit obj_capacitorUnit;
logout obj_logout;
#Test (priority=1, description = "Login Functionality")
public void login() {
driver.get(data.getProperty("base.url"));
obj_login = new login (driver);
ExcelBase.setExcelFileSheet("Capacitor_unit");
..
obj_login.select_login();
}
#Test (priority=2, description = "Create new Design")
public void createNewDesign() {
log.info("Create New Design");
obj_CreateNewDesign = new createNewDesign (driver);
..
}
#Test (priority=3, description = "Capacitor Unit Design")
public void capacitorUnit() {
log.info("Capacitor Unit Design");
obj_capacitorUnit = new capacitorUnit (driver);
..
log.info("Assert actual searched string with expected string from Excel.");
assertStrings(obj_capacitorUnit.get_unitVoltage().replaceAll("\\s+",""),ExcelBase.getCellData(3,50));
..
}
#Test (priority=4, description = "Logout app")
public void logout() {
log.info("Logout from CapDes");
obj_logout = new logout (driver);
}
}
Related
am trying to implement depends on methods
i have given depends on login as agent for booking an appointment but its showing non exist method
ihave given #data provider and depends on method
this is login test case
public class TC001_Login extends ProjectSpecificMethods{
#BeforeTest
public void setValues() {
testCaseName = "Login";
testDescription = "This test is to verify whether user able to login and logout";
nodes = "login";
authors = "manoj";
category = "Smoke";
}
#Test(priority = 0)
public void loginAsAgent() throws InterruptedException, IOException {
new LoginPage(driver, node)
.enterUserName()
.enterPassword()
.enterCaptchAndClickLogin()
.clickOnLogout()
.verifyLogout();
}
}
this is appointment booking test case
public class TC003_BookAppointment extends ProjectSpecificMethods {
#BeforeTest
public void setValues() {
testCaseName = "bookappointment";
testDescription = "booking an appointment";
nodes = "appointment,appointment1";
authors = "manoj";
category = "Smoke";
dataSheetName = "ScheduleAppointment";
sheetName = "TestData";
}
#Test(dataProvider = "fetchData",dependsOnMethods = {"loginAsAgent"})
public void bookappointment(String visatype,String VscCode,String noofapplicants,String date,String path) throws IOException, Exception {
new LoginPage(driver, node)
.enterUserName()
.enterPassword()
.enterCaptchAndClickLogin()
.clickGroupScheduling()
.selectVisaType(visatype)
.selectVscCenter(VscCode)
.selectNumberOfApplicants(noofapplicants)
.enterCaptcha()
.selectDate_Normal(date)
.selectTime()
.confirmSlot_Normal()
.submitScheduling_Normal()
.generatePassportNumber()
.uploadexcel(path)
.clickUploadexcel()
.clickConsentcheckbox()
.clickSaveApplicantDetais()
.downloadAppointmentslip()
.downloadGroupSchedulingForm()
.verifyGroupid();
}
}
tried to give classname.methodname but not working
I have a scenario: fillout form on https://cloud.google.com/products/calculator and click email estimate (a pop-up window opens), then open and switch to new tab (https://yopmail.com/en/email-generator) and copy random email, then switch to previous tab (https://cloud.google.com/products/calculator) . And after that popup (Email Your Estimate) becomes weird, inactive, but in manual testing everything is ok. What's the problem?
GIF record with a problem
public void fillOutForm() {
estimatePage = new GoogleCloudHomePage(driver)
.openPage()
.search(SEARCH_TERM)
.goToPricingCalculatorFromSearchResults()
.switchToCalculatorFrame()
.selectComputeEngineItem()
.setNumberOfInstances(NUMBER_OF_INSTANCES)
.setOperatingSystem(OPERATING_SYSTEM)
.setMachineClass(MACHINE_CLASS)
.setSeries(SERIES)
.setMachineType(MACHINE_TYPE)
.setGPU(NUMBER_OF_GPUS, GPU_TYPE)
.setLocalSSD(LOCAL_SSD)
.setDatacenterLocation(DATACENTER_LOCATION)
.setCommittedUsage(COMMITTED_USAGE)
.addToEstimate();
emailEstimatePage = estimatePage.goToEmailEstimate();
tabManager = new TabManager(driver);
tabManager.openNewTab();
tabManager.switchToTab(1);
emailGeneratorPage = new YopmailHomePage(driver)
.openPage()
.generateNewEmailAddress()
.copyEmailAddress();
tabManager.switchToTab(0);
//THE PROBLEM IS HERE. POP-UP CORRUPTED CAN'T FIND ELEMENT ON THIS STEP/ watch gif
emailEstimatePage.switchToContentFrame();
emailEstimatePage.setEmail();
emailEstimatePage.sendEmail();
tabManager.switchToTab(1);
emailInboxPage = new YopmailHomePage(driver)
.openPage()
.goToEmailInboxPage()
.getGoogleCloudEstimateMessage();
}
code of TabManager
public class TabManager {
public WebDriver driver;
public TabManager(WebDriver driver) {
this.driver = driver;
}
public void openNewTab() {
((JavascriptExecutor) driver).executeScript("window.open()");
}
public void switchToTab(int tabIndex) {
ArrayList<String> tabs = new ArrayList<>(driver.getWindowHandles());
driver.switchTo().window(tabs.get(tabIndex));
}
}
I am trying to run different classes parallarly though testNG to generate one single extent report for all classes. Also I am trying to generate logs for each classes which will be shown in the extent report. However when the extent report is generated I can see that the logs for a test case of one class is shown in the test case of other class. How to resolve this issue? Below is my code:
//// This is my base class for extent report:
#BeforeSuite
public static void setUp()
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
report = new ExtentReports();
report.attachReporter(htmlReporter);
report.setSystemInfo("OS", "Mac Sierra");
report.setSystemInfo("Host Name", "Testing Xpert");
report.setSystemInfo("Environment", "QA");
report.setSystemInfo("User Name", "Vivek");
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("My Own Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
//Creating a method getScreenshot and passing two parameters
//driver and screenshotName
public static String getScreenshot(WebDriver driver, String screenshotName) throws Exception {
//below line is just to append the date format with the screenshot name to avoid duplicate names
String dateName = new SimpleDateFormat("yyyyMMddhhmmss").format(new Date());
TakesScreenshot ts = (TakesScreenshot) driver;
File source = ts.getScreenshotAs(OutputType.FILE);
String destination = System.getProperty("user.dir") + "/test-output/"+screenshotName+dateName+".png";
File finalDestination = new File(destination);
FileHandler.copy(source, finalDestination);
//FileUtils.copyFile(source, finalDestination);
return destination;
}
#AfterMethod
public void getResult(ITestResult result) throws Exception
{
if(result.getStatus() == ITestResult.FAILURE)
{
test.log(Status.FAIL, "Test Case Failed is "+result.getName());
// test.log(Status.FAIL, "Test Case Failed is "+result.getThrowable());
String screenshotPath = ExtentReportBaseClass.getScreenshot(UtilityMethods.getdriver(), result.getName());
test.log(Status.FAIL, (Markup) test.addScreenCaptureFromPath(screenshotPath));
//test.log(Status.FAIL, MarkupHelper.createLabel(result.getName()+" Test case FAILED due to below issues:",test.addScreenCaptureFromPath(screenshotPath)));
test.fail(result.getThrowable());
}
else if(result.getStatus() == ITestResult.SUCCESS)
{
test.log(Status.PASS, "Test Case Passed is "+result.getName());
}
else
{
test.log(Status.SKIP, MarkupHelper.createLabel(result.getName()+" Test Case SKIPPED", ExtentColor.ORANGE));
test.skip(result.getThrowable());
}
}
#AfterSuite
public void tearDown()
{
report.flush();
}
There are my two classes which i am running. Method for generating logs are defined in the class.(test.log(test.getStatus(), "This will add item to the cart");)
public class PurchaseItemTestCase extends ExtentReportBaseClass{
#BeforeClass
public void launchBrowser() throws InterruptedException {
//System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
//driver = new ChromeDriver();
driver = util.openBrowser(ConstantsValues.BROWSER_NAME);
util.launchWebsite();
driver.manage().window().maximize();
//report = ExtentReportBaseClass.setUp();
}
#Test
public void chkPurchaseItem() throws InterruptedException {
//ExtentTest test;
test = report.createTest("chkPurchaseItem", "This will check status for purchasing an item.");
driver.findElement(By.xpath("//img[#title='Faded Short Sleeve T-shirts']")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(#id,'fancy')]")));
System.out.println("after frame");
Thread.sleep(4000);
test.log(test.getStatus(), "This will add item to the cart");
driver.findElement(By.xpath("//button[#type='submit']//span[contains(.,'Add')]")).click();
Set handles = driver.getWindowHandles();
System.out.println(handles);
// Pass a window handle to the other window
for (String handle1 : driver.getWindowHandles()) {
System.out.println(handle1);
driver.switchTo().window(handle1);
Thread.sleep(3000);
driver.findElement(By.xpath("//a[#title='Proceed to checkout']//span[contains(.,'Proceed')]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath(
"//a[#class='button btn btn-default standard-checkout button-medium']//span[contains(.,'Proceed')]//i[#class='icon-chevron-right right']"))
.click();
test.log(test.getStatus(), "We will login to the account");
driver.findElement(By.id("email")).sendKeys("vivekkumar009#gmail.com");
driver.findElement(By.id("passwd")).sendKeys("vivek123");
Thread.sleep(3000);
// UtilityMethods.getdriver().findElement(By.id("SubmitLogin"));
driver.findElement(By.id("SubmitLogin")).click();
test.log(test.getStatus(), "User will add address for shipment");
driver.findElement(By.name("processAddress")).click();
test.log(test.getStatus(), "User will agree to terms and condition ");
driver.findElement(By.id("cgv")).click();
driver.findElement(By.xpath("//button[#name=\"processCarrier\"]")).click();
driver.findElement(By.className("cheque")).click();
test.log(test.getStatus(), "User confirms order");
driver.findElement(By.xpath("//span[contains(text(),'I confirm my order')]")).click();
boolean chkElement = util.getdriver().findElement(By.className("home")).isDisplayed();
System.out.println(chkElement);
Assert.assertTrue(chkElement);
}
this is the 2nd class:
public class CategoryWisePurchase extends ExtentReportBaseClass {
#BeforeClass
public void launchApplicationBrowser() {
util.openBrowser(ConstantsValues.BROWSER_NAME);
util.launchWebsite();
}
#Test
public void CategoryWiseShopping() throws InterruptedException {
test = report.createTest("Category Wise Shopping", "This will check if the user is able to shop different products by selecting its category");
// Actions actions = new Actions(UtilityMethods.getdriver());
Actions action = new Actions(UtilityMethods.getdriver());
test.log(test.getStatus(), "User will select the category of a particular item");
WebElement mainMenu = UtilityMethods.getdriver().findElement(By.xpath("//a[#title='Women']"));
WebElement subMenu = UtilityMethods.getdriver().findElement(By.xpath("//a[#title='T-shirts']"));
action.moveToElement(mainMenu).build().perform();
Thread.sleep(2000);
action.moveToElement(subMenu).click().build().perform();
test.log(test.getStatus(), "Various products will be shown to the user of the selected category");
//reportLog("Various products will be shown to the user of the selected category");
boolean chkElement = UtilityMethods.getdriver().findElement(By.xpath("//form[#method='post']")).isDisplayed();
System.out.println(chkElement);
Assert.assertTrue(chkElement);
}
}
That will happen if the test is in your Base class. In parallel, the test will be used by all classes that inherit your Base class. Better to use a threadlocal here or an implementation similar to:
https://github.com/anshooarora/extentreports-java/blob/master/src/test/java/com/aventstack/extentreports/common/ExtentTestManager.java
Also, is you see the examples section of the docs, you already have a barebones ExtentTestNGReportBuilder example which you can use without creating any custom code like here.
I am trying to send my tests to testrail from selenium but im not using an assert to end the test, i just want it to pass if it runs to completion? Is this possible? Also is there any examples of how this working in the code? I currently have:
public class login_errors extends ConditionsWebDriverFactory {
public static String TEST_RUN_ID = "R1713";
public static String TESTRAIL_USERNAME = "f2009#hotmail.com";
public static String TESTRAIL_PASSWORD = "Password100";
public static String RAILS_ENGINE_URL = "https://testdec.testrail.com/";
public static final int TEST_CASE_PASSED_STATUS = 1;
public static final int TEST_CASE_FAILED_STATUS = 5;
#Test
public void login_errors() throws IOException, APIException {
Header header = new Header();
header.guest_select_login();
Pages.Login login = new Pages.Login();
login.login_with_empty_fields();
login.login_with_invalid_email();
login.email_or_password_incorrect();
login.login_open_and_close();
login_errors.addResultForTestCase("T65013",TEST_CASE_PASSED_STATUS," ");
}
public static void addResultForTestCase(String testCaseId, int status,
String error) throws IOException, APIException {
String testRunId = TEST_RUN_ID;
APIClient client = new APIClient(RAILS_ENGINE_URL);
client.setUser(TESTRAIL_USERNAME);
client.setPassword(TESTRAIL_PASSWORD);
Map data = new HashMap();
data.put("status_id", status);
data.put("comment", "Test Executed - Status updated automatically from Selenium test automation.");
client.sendPost("add_result_for_case/"+testRunId+"/"+testCaseId+"",data );
}
}
I am getting a 401 status from this code.
Simply place the addResultForTestCase method at the end of the run. Ensure the Test CASE is used rather than the run id. You are currently using the incorrect ID
I am trying to merge multiple test cases from various classes into one extent report. All test cases are running successfully but it is not adding those test cases into my extent report. The version of my Extent Report is 2.41.2.It is showing the previous extent report only, No new report showing all the test cases is generated. I am successfully generating a single class report but not able to generate multiple classes extent report. Here is my code:
// First I have created a base class for Extent Report:
public static ExtentHtmlReporter htmlReporter;
public static ExtentReports extent;
public static ExtentTest test;
#BeforeSuite
public void setUp()
{
htmlReporter = new ExtentHtmlReporter(System.getProperty("user.dir") +"/test-output/MyOwnReport.html");
extent = new ExtentReports();
extent.attachReporter(htmlReporter);
extent.setSystemInfo("OS", "Mac Sierra");
extent.setSystemInfo("Host Name", "Krishna");
extent.setSystemInfo("Environment", "QA");
extent.setSystemInfo("User Name", "Krishna Sakinala");
htmlReporter.config().setChartVisibilityOnOpen(true);
htmlReporter.config().setDocumentTitle("AutomationTesting.in Demo Report");
htmlReporter.config().setReportName("My Own Report");
htmlReporter.config().setTestViewChartLocation(ChartLocation.TOP);
htmlReporter.config().setTheme(Theme.DARK);
}
#AfterSuite
public void tearDown()
{
extent.flush();
}
}
// Now Logintestcase Extending Base Extent report class:
public class LoginTestCase extends ExtentReportBaseClass {
static WebDriver driver;
Homepage login = new Homepage();
UtilityMethods util = new UtilityMethods();
String locUsernameElem;
String locPasswordelem;
String Sign_in;
String insertEmail;
String insertFirstName;
String createAccountButton;
// #Parameters("browser")
#BeforeClass
public void launchBrowser() {
driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
}
#Test
public void registration() throws InterruptedException {
test = extent.createTest("registration", "This will check status for registration of the user.");
Sign_in = Utility.ConstantsValues.SIGN_IN;
insertEmail = Utility.ConstantsValues.EMAIL_ADDRESS;
createAccountButton = Utility.ConstantsValues.CREATE_ACOUNT;
// insertFirstName=ConstantsValues.USER_FIRSTNAME;
util.clickElement(Sign_in);
Thread.sleep(2000);
// driver.findElement(By.xpath("//input[#id='email_create']")).sendKeys("vivekkumar9652gmail.com");
util.sendData(insertEmail);
util.clickElement(ConstantsValues.CREATE_ACCOUNT);
util.clickElement(ConstantsValues.USER_TITLE);
util.sendDataById("customer_firstname", ConstantsValues.FIRST_NAME);
util.sendDataById("customer_lastname", ConstantsValues.LAST_NAME);
// util.sendData(ConstantsValues.LAST_NAME);
util.sendData(ConstantsValues.USER_PASSWORD);
util.clickElement(ConstantsValues.USER_NEWSLETTER);
Select day = new Select(driver.findElement(By.id("days")));
day.selectByValue("1");
Select month = new Select(driver.findElement(By.id("months")));
month.selectByValue("2");
Select year = new Select(driver.findElement(By.id("years")));
year.selectByValue("2014");
util.sendData(ConstantsValues.USER_COMPANY);
util.sendData(ConstantsValues.USER_STATE);
util.sendData(ConstantsValues.USER_ADDRESS1);
util.sendData(ConstantsValues.USER_MOBILENUMBER);
util.sendData(ConstantsValues.USER_ZIPCODE);
util.sendData(ConstantsValues.USER_ALIAS);
util.sendData(ConstantsValues.USER_CITY);
util.clickElement(ConstantsValues.SUBMITACCOUNT);
util.clickElement(ConstantsValues.USER_SIGN_OUT);
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
#Test
public void userLogin() {
test = extent.createTest("userLogin", "This will check status for login of the user");
// util.clickElement(ConstantsValues.SIGN_IN);
util.sendData(ConstantsValues.LOGIN_USERNAME);
util.sendData(ConstantsValues.LOGIN_PASSWORD);
util.clickElement(ConstantsValues.USER_SIGNIN_Account);
//Assert.assertNotEquals("Krishna", "Krishna");
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.RED));
}
}
//Now another class Extending BaseExtentReport Class:
public class PurchaseItemTestCase extends ExtentReportBaseClass {
WebDriver driver;
UtilityMethods util = new UtilityMethods();
// #Parameters("browser")
#BeforeClass
public void launchBrowser() throws InterruptedException {
System.setProperty("webdriver.chrome.driver", "D:\\chromedriver.exe");
driver = new ChromeDriver();
driver = UtilityMethods.openBrowser(ConstantsValues.BROWSER_NAME);
UtilityMethods.launchWebsite(Utility.ConstantsValues.URL);
driver.manage().window().maximize();
}
#Test
public void chkPurchaseItem() throws InterruptedException {
test = extent.createTest("chkPurchaseItem", "This will check status for purchasing an item.");
driver.findElement(By.xpath("//img[#title='Faded Short Sleeve T-shirts']")).click();
driver.switchTo().defaultContent();
driver.switchTo().frame(driver.findElement(By.xpath("//iframe[contains(#id,'fancy')]")));
System.out.println("after frame");
Thread.sleep(4000);
driver.findElement(By.xpath("//button[#type='submit']//span[contains(.,'Add')]")).click();
Set handles = driver.getWindowHandles();
System.out.println(handles);
// Pass a window handle to the other window
for (String handle1 : driver.getWindowHandles()) {
System.out.println(handle1);
driver.switchTo().window(handle1);
Thread.sleep(3000);
driver.findElement(By.xpath("//a[#title='Proceed to checkout']//span[contains(.,'Proceed')]")).click();
Thread.sleep(3000);
driver.findElement(By.xpath(
"//a[#class='button btn btn-default standard-checkout button-medium']//span[contains(.,'Proceed')]//i[#class='icon-chevron-right right']"))
.click();
driver.findElement(By.id("email")).sendKeys("vivekkumar009#gmail.com");
driver.findElement(By.id("passwd")).sendKeys("vivek123");
Thread.sleep(3000);
// UtilityMethods.getdriver().findElement(By.id("SubmitLogin"));
driver.findElement(By.id("SubmitLogin")).click();
driver.findElement(By.name("processAddress")).click();
driver.findElement(By.id("cgv")).click();
driver.findElement(By.xpath("//button[#name=\"processCarrier\"]")).click();
driver.findElement(By.className("cheque")).click();
driver.findElement(By.xpath("//span[contains(text(),'I confirm my order')]")).click();
test.log(Status.PASS, MarkupHelper.createLabel("PASS", ExtentColor.GREEN));
}
}
}
Make your extent test as thread local variable.
Example:
Public ThreadLocal<ExtentTest> test;