Browser is not launching for the second TestNG Test case - java

The browser is not launching for the second testcase of a TestNG Test group.
Tried playing with the Before and AfterTest but still the browser is not launching. also add checks the browser running. not sure what I miss here.
Error:
org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#Email"}
(Session info: chrome=91.0.4472.77)
this causes the b browser is not launched at the time
Driver Class:
package com.portalHelpers;
import org.openqa.selenium.Alert;
import org.openqa.selenium.chrome.ChromeDriverService;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.WebDriver;
import java.io.File;
import java.util.Date;
import org.openqa.selenium.Platform;
import org.openqa.selenium.remote.service.DriverService;
import org.openqa.selenium.support.events.EventFiringWebDriver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import java.io.IOException;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;
import static java.lang.String.valueOf;
public class WebDriverHelper extends EventFiringWebDriver {
public static RemoteWebDriver remoteDriver;
protected static HtmlUnitDriver htmlDriver;
protected static Alert _alert;
protected static DriverService cds;
private static String driverClass = System.getProperty("driverClass");
public static long now = new Date().getTime();
public static com.itextpdf.text.Document dataFeed;
public final static String DefaultTimeOut = "40000";
public final static int TimeOut = 90;
protected static String chrome_driver_location = "/Users/me/Downloads/chromedriver";
public static String url = System.getProperty("url");
public static String browser = System.getProperty("browser");
private static String platform = Platform.getCurrent().name();
private static String CHROME_DRIVER = "chrome_driver";
//******************URLs************************************************************//
public static String url_test = "www.google.com";
public static String url_live = "www.google.com";
//******************Browser settings************************************************************//
//Browser settings
static {
//
if (browser.equalsIgnoreCase("chrome")) {
if (platform.equalsIgnoreCase("Mac")) {
CHROME_DRIVER = CHROME_DRIVER + "_mac";
} else if (platform.equalsIgnoreCase("LINUX")) {
CHROME_DRIVER = CHROME_DRIVER + "_linux";
} else {
CHROME_DRIVER = CHROME_DRIVER + "_win.exe";
}
setWebDriverToChrome();
}
Runtime.getRuntime().addShutdownHook(new Thread() {
#Override
public void run() {
remoteDriver.close();
}
});
}
static {
if (url.equalsIgnoreCase("url_test")) {
open_test();
} else if (url.equalsIgnoreCase("url_live")) {
open_live();
}
}
public WebDriverHelper() {
super(remoteDriver);
manage().window().maximize();
manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
}
#BeforeTest
public void setUp () throws Exception{
setWebDriverToChrome();}
#AfterTest
public void tearDown () throws Exception{
if(remoteDriver !=null){
remoteDriver.close();
}}
public static void setWebDriverToChrome () {
System.setProperty("webdriver.chrome.driver",chrome_driver_location);
cds = new ChromeDriverService.Builder()
.usingDriverExecutable(new File(chrome_driver_location))
.usingAnyFreePort()
.build();
try {
cds.start();
} catch (IOException e) {
throw new IllegalStateException(e.getMessage());
}
ChromeOptions opt = new ChromeOptions();
opt.addArguments("disable-infobars");
opt.addArguments("--start-maximized");
opt.addArguments("--disable-extensions");
remoteDriver = new RemoteWebDriver(cds.getUrl(), opt);
}
public void openWebPage (String url){
//Get url and maximize the window
remoteDriver.get(url);
remoteDriver.manage().window().maximize();
}
public static void open_test () {
remoteDriver.get(url_test);
remoteDriver.manage().window().maximize();
}
public static void open_live() {
remoteDriver.get(url_live);
// remoteDriver.manage().window().maximize();
}
public static WebDriver getSelenium () {
if ((remoteDriver == null) && (!"noBrowser".equals(driverClass))) {
throw new IllegalStateException("Selenium client is not initialised.");
}
return remoteDriver;
}
}
Test Class:
package Testsuites;
import com.portalHelpers.PageObjects;
import com.portalHelpers.WebDriverHelper;
import com.portalHelpers.SeleniumMethodsHelper;
import org.testng.Assert;
import org.testng.annotations.Test;
public class testSuite extends WebDriverHelper {
PageObjects pageObjects = new PageObjects();
SeleniumMethodsHelper seleniumMethodsHelper = new SeleniumMethodsHelper();
String user1 = "user1t#google.com";
String standardPass = "1234";
String user2 = "user2#gmail.com";
#Test(groups = "MainFlowTests")
public void preparation(){
String actual_url = getCurrentUrl();
System.out.println(actual_url);
//sending the username and password parameters to the login method//
PageObjects.login_logic(remoteDriver,user1, standardPass);
//Asserting the user logged in is the one we used and that we are on logged in//
String name = PageObjects.account_Email().getText();
System.out.println(name);
Assert.assertEquals(name,useer1);
seleniumMethodsHelper.sleep(3);
SeleniumMethodsHelper.mouseOver(PageObjects.promo_Button());
seleniumMethodsHelper.sleep(8);
}
#Test(groups = "MainFlowTests")
public void offerCreation(){
String actual_url = getCurrentUrl();
System.out.println(actual_url);
//sending the username and password parameters to the login method//
//PageObjects.email_Field().click();
PageObjects.login_logic(remoteDriver,dryFoodsCam, standardPass);
seleniumMethodsHelper.sleep(3);
}
}
Image shows the TestNG configuration.
Hope you can find what I miss here or if something is wrong.
Thanks

Related

java.lang.NullPointerException exception is occurred when running the test script Page Object Model using Selenium Web Driver

package com.qa.base;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import com.qa.util.TestUitl;
public class TestBase {
public static WebDriver driver;
public static Properties prop;
// Creating a Constructor
public TestBase() {
prop = new Properties();
try {
File file = new File("/APIAutomation/CRMTest/src/main/java/com/qa/config/config.properties");
FileInputStream fis = new FileInputStream(file);
prop.load(fis);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static void initializtion() {
String browser = prop.getProperty("browser");
if(browser.equals("chrome")) {
System.setProperty("webdriver.chrome.driver", "C:/APIAutomation/chromedriver.exe");
driver = new ChromeDriver();
}
else
{
System.out.println("Quit Running Script");
}
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.manage().timeouts().implicitlyWait(TestUitl.PAGE_LOAD_TIMEOUT, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(TestUitl.IMPLICIT_WAIT, TimeUnit.SECONDS);
driver.get(prop.getProperty("url"));
}
}
Page Factory
package com.qa.pages;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.qa.base.TestBase;
public class loginPage extends TestBase{
//Page Factory
#FindBy(name="email")
WebElement email;
#FindBy(name="password")
WebElement password;
#FindBy(xpath=".//div[#class='ui fluid large blue submit button']")
WebElement loginButton;
#FindBy(xpath="//div[#class ='column']/div[2][#class='ui message']")
WebElement OldLogin;
//Initialization the Page Object
public loginPage() {
PageFactory.initElements(driver, this);
}
//Actions
public String validateLoginPageTitle() {
return driver.getTitle();
}
public String validateUserName() {
return OldLogin.getText();
}
public HomePage login(String user, String pass) {
email.sendKeys(user);
password.sendKeys(pass);
loginButton.click();
return new HomePage();
}
}
Page Factory HomePage
package com.qa.pages;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.PageFactory;
import com.qa.base.TestBase;
public class HomePage extends TestBase{
//PageFactory
#FindBy(xpath = ".//div[#id='main-nav']/a[#href='/home']")
WebElement Homepage;
#FindBy(xpath =".//div/span[#class='user-display']")
WebElement username;
#FindBy(xpath =".//span[contains(text(),'Contacts')]")
WebElement contactlink;
#FindBy(xpath="//a[5][contains(#href,'/deals')]")
WebElement dealslink;
//Initializing Page Object
public HomePage() {
PageFactory.initElements(driver, this);
}
//Actions
public String validateHomePage() {
return driver.getTitle();
}
public boolean validateHomePageDisplayed() {
return Homepage.isDisplayed();
}
public String validateUser() {
return username.getText();
}
public boolean verifyUsername() {
return username.isDisplayed();
}
public ContactPage clickContactLink() {
contactlink.click();
return new ContactPage();
}
public DealsPage clickDeals() {
dealslink.click();
return new DealsPage();
}
}
Test Case Class
package com.crm.qa.TestCases;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.qa.base.TestBase;
import com.qa.pages.ContactPage;
import com.qa.pages.HomePage;
import com.qa.pages.loginPage;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
public class HomePageTest extends TestBase {
loginPage loginpage;
HomePage homepage;
ContactPage contactpage;
//Create a constructor of HomePageTest and call the super class i.e the TestBase class constructor will be called
public HomePageTest() {
super();
}
// test case should be separated - independent with each other
// before each test cases - launch the browser and login
// after each test cases - close the browser
#BeforeMethod
public void setUp() {
initializtion();
loginpage = new loginPage();
//Login method is returning homepage object
homepage = loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
}
#Test
public void verifyHomePageTitleTest() {
String homepageTitle = homepage.validateHomePage();
System.out.println("Print HomePage Title:::::::::::::::::" +homepageTitle);
Assert.assertEquals(homepageTitle, "Cogmento CRM","Homepage title is not matching");
}
#Test
public void verifyUsernameTest() {
Assert.assertTrue(homepage.verifyUsername(), "Username is not matching");
}
#Test
public void verifyUserTest() {
String Username = homepage.validateUser();
Assert.assertEquals(Username, "Gokul Kuppusamy","Username text is not matching");
}
#Test
public void verifyContactPageTest() {
System.out.println("Clicking Contact Page");
contactpage = homepage.clickContactLink();
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
package com.crm.qa.TestCases;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
import com.qa.base.TestBase;
import com.qa.pages.ContactPage;
import com.qa.pages.HomePage;
import com.qa.pages.loginPage;
public class ContactPageTest extends TestBase {
loginPage loginpage;
HomePage homepage;
ContactPage contactpage;
public ContactPageTest() {
super();
}
#BeforeMethod
public void setUp() throws Exception {
initializtion();
loginpage = new loginPage();
// Login method is returning homepage object
homepage = loginpage.login(prop.getProperty("username"), prop.getProperty("password"));
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
Thread.sleep(3000);
homepage.validateHomePageDisplayed();
/*
* Thread.sleep(3000); homepage.clickContactLink(null);
*/
}
#Test
public void verifyContactsPageNewButtonTest() {
Assert.assertTrue(contactpage.verifyNewButton());
}
#Test(priority = 1)
public void verifyContactsPageLableTest() {
driver.manage().timeouts().implicitlyWait(5000, TimeUnit.SECONDS);
Assert.assertTrue(contactpage.verifyContactlable(), "Contacts is missing on the page");
}
#Test(priority = 2)
public void selectContactDetailsTest() {
contactpage.selectContactDetails();
}
#AfterMethod
public void tearDown() {
driver.quit();
}
}
java.lang.NullPointerException
at com.crm.qa.TestCases.ContactPageTest.verifyContactsPageNewButtonTest(ContactPageTest.java:49)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
initializtion();
loginpage = new loginPage();
//below line is missing please add in HomePageTest class
**homepage=new Homepage();**
Please confirm whether you are using only one driver instance for all pages, Basically Null point exception occurring for this , The solution uses a global variable for driver instance
public static Webdrivr driver;

Cannot instantiate class tests.LoginPageTest

Console package tests;
import java.net.MalformedURLException;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
import junit.framework.Assert;
import pages.DashBoardPage;
import pages.LoginPage;
Here is the code for loginpageTest but it does not get instantiate. I feel like something is not instiliazed somewhere. When i run this app opens up but throws the error this test cannot be instatiated
public class LoginPageTest extends LoginPage {
//DashBoardPage dashBoardPage = new DashBoardPage(driver);
public static WebDriver driver;
LoginPage loginPage;
DashBoardPage ds;
public LoginPageTest() {
super(driver);
ds=new DashBoardPage(driver);
}
#BeforeTest
public void setup() throws MalformedURLException {
intialization();
}
/*#Test(priority = 1)
public void LoginPageTitleTest() {
Assert.assertEquals(getPageTitle(), "verizon");
}*/
// 07/02/2019
#Test(priority =2)
public void VerizonlogoTest() throws InterruptedException {
Thread.sleep(5000);
try{
if(UserID.isDisplayed())
{
clickUserID();
clickPassword();
clickLoginBtn();
}
}
catch(Exception e)
{
System.out.println("Clicking on I Agree Button");
}
finally{
clickAgree();
}
explicitWait(ds.dashBoard);
Assert.assertTrue(ds.getDashBoardTitle().equals("Dashboard"));
/*driver.findElement(By.xpath("//android.widget.EditText[#resource-id='USER']")).sendKeys("jomonli");
driver.findElement(By.xpath("//android.widget.EditText[#resource-id='PASSWORD']")).sendKeys("Brownlenovo5#");
driver.findElement(By.xpath("//android.view.View[#resource-id='btnLogin']")).isEnabled();
Assert.assertTrue(driver.findElement(By.xpath("//android.view.View[#text='Verizon Mobile Single Sign on']")).isDisplayed());
Assert.assertTrue(driver.findElement(By.xpath("//android.view.View[#text='First time user, click here to activate.']")).isEnabled());
*/
//LoginPage loginPage = PageFactory.initElements(driver, LoginPage.class);
//isElementVisible(loginPage.getVerizonLogo());
//loginPage.clickUserID();
}
/*
* #Test(priority = 2, description = "Logo is present Test") public boolean
* VerizonLogoTest() { //boolean logo = loginPage.VerizonLogo();
* //Assert.assertTrue(logo); //return logo; }
*
* #Test(priority = 3, description = "LoginBtn is clickable and enabled")
* public boolean LoginBtnClickableTest() { //boolean clickable =
* loginPage.LoginBtnClickable(); //Assert.assertTrue(clickable); //return
* clickable; }
*/
//#Test(priority = 4, description = "User is able to login succesfully with valid credentials")
public void LoginTest() {
// dashBoardPage = loginPage.Login(prop.getProperty("userID"),
// prop.getProperty("password"));
}
/*
* #Test(description = "FirstTimeUserLink is clickable and enabled") public
* boolean FirstTimeUserLinkClickableTest() { boolean clickable =
* loginPage.FirstTimeUserLinkClickable(); Assert.assertTrue(clickable);
* return clickable; }
*/
#AfterTest
public void teardown() {
driver.quit();
}
// private Object () {
// // TODO Auto-generated method stub
// return null;
// }
}
Here is the code for loginpageTest but it does not get instantiate. I feel like something is not instiliazed somewhere. When i run this app opens up but throws the error this test cannot be instatiated
======================================================================
BASE PAGE
package base;
import java.net.URL;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
public class BaseClass {
public static Properties prop;
public static WebDriver driver;
public static URL url;
public static WebDriver intialization() {
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability("deviceName", "Galaxy Tab S3");// setting > about
// phone
cap.setCapability("udid", "624258263526a1e8");
// udid is the device name when you press - cmd adb devices
cap.setCapability("platformName", "Android");
cap.setCapability("platformVersion", "8.0.0");
cap.setCapability("appPackage", "com.verizon.launcher.sdnasit");
cap.setCapability("appActivity", "com.verizon.launcher.webview.WebActivity");
// cap.setCapability(MobileCapabilityType.APP, "Apk file location
// C:\\apkfiles\\AndroidUI.apk"
cap.setCapability("noReset", "True");
cap.setCapability("automationName", "uiautomator2");
cap.setCapability(MobileCapabilityType.NEW_COMMAND_TIMEOUT, 60);
// any application will have app package and app activity
// download apk info from playstore
try{
url = new URL("http://127.0.0.1:4723/wd/hub");
}
catch(Exception e)
{
e.printStackTrace();
}
driver = new AndroidDriver(url, cap);
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
//LoginPageTest loginPage= new LoginPageTest();
return driver;
}
}
May be your device don`t on Debug Mode.
(Check your phone tools => Additional settings => For developers => Debug Mode(Or "Debug by USB") => Switch On)

How to call a method in every test which is in the base class and has a data provider in selenium

I have been trying to integrate browser stack with my selenium scripts. As part of which i have added desired capabilities in my 'getBrowser' method with data provider in the Base class. As i want to run my scripts in multiple browsers. The browsers list is in "getData" method in Base class.
How can i call the getBrowser method in my testcases and have the getData(browsers list) defined in only the base class. This what i have done and its not right. i have added my base class and the test script.
Base.getBrowser(Platform platform, String browserName, String browserVersion); this line is were i am stuck.
Any help would be appreciated. Thanks
package com.gale.precision.FundVisualizer.core;
import java.net.MalformedURLException;
import java.net.URL;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.DataProvider;
import org.openqa.selenium.Platform;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.edge.EdgeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
public class Base {
//public static WebDriver driver = null;
public static WebDriver driver;
public static String DriverPath = System.getProperty("user.dir") + "//" + "Drivers";
public static String DirectoryPath = System.getProperty("user.dir");
public static Properties prop = new Properties();
public static InputStream input = null;
public static final String USERNAME = "antonyprabhu1";
public static final String AUTOMATE_KEY = "xHRMpqxgD8sn3e3sr75s";
public static final String URL = "https://" + USERNAME + ":" + AUTOMATE_KEY + "#hub-cloud.browserstack.com/wd/hub";
#DataProvider(name = "EnvironmentDetails")
public static void getBrowser(Platform platform, String browserName, String browserVersion) throws MalformedURLException
{
DesiredCapabilities capability = new DesiredCapabilities();
capability.setPlatform(platform);
capability.setBrowserName(browserName);
capability.setVersion(browserVersion);
capability.setCapability("browserstack.debug", "true");
driver = new RemoteWebDriver(new URL(URL), capability);
try {
input = new FileInputStream(DirectoryPath + "//" + "config" + "//" + "app.properties");
prop.load(input);
} catch (IOException e) {
e.printStackTrace();
}
}
#DataProvider(name = "EnvironmentDetails", parallel = true)
public Object[][] getData() {
Object[][] testData = new Object[][] {
{
Platform.MAC, "chrome", "62.0"
}, {
Platform.WIN8,
"chrome",
"62.0"
}, {
Platform.WINDOWS,
"firefox",
"57"
}
};
return testData;
}
public static void closeBrowser() {
driver.quit();
}
}
package comparison;
import java.net.MalformedURLException;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.Platform;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebElement;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterTest;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import com.gale.precision.FundVisualizer.core.Base;
import com.gale.precision.FundVisualizer.core.ExtentReport;
import com.gale.precision.FundVisualizer.pageObject.Comparison;
import com.gale.precision.FundVisualizer.pageObject.InvestmentsSearch;
#SuppressWarnings("unused")
public class AddedInvestmentDisplay extends ExtentReport {
/*============================================================================================================================
Test case : Verify that already selected Investments for comparison does not show up
======================================================================================*/
#Test(testName = "Comparison: Verify an already selected Investment for comparison does not show up in search")
public void verifyAddedInvestmentDisplay() throws InterruptedException, MalformedURLException {
//test = extent.createTest(Thread.currentThread().getStackTrace()[1].getMethodName());
Base.getBrowser(Platform platform, String browserName, String browserVersion);
InvestmentsSearch.login(Base.driver);
InvestmentsSearch.InvestmentsLink(Base.driver).click();
JavascriptExecutor jse = (JavascriptExecutor) Base.driver;
jse.executeScript("window.scrollBy(0,750)", "");
InvestmentsSearch.ViewResults(Base.driver).click();
for (int i = 0; i <= 2; i++)
{
try {
Comparison.firstCheckBox(Base.driver).click();
break;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
//Base.clickingStaleElements(Comparison.firstCheckBox(Base.driver));
//Comparison.firstCheckBox(Base.driver).click();
for (int i = 0; i <= 2; i++)
{
try {
Comparison.analyzeOrCompare(Base.driver).click();
break;
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
Comparison.addInvestmentField(Base.driver).sendKeys("MFC027");
Comparison.firstSearchResult(Base.driver).click();
Comparison.addInvestmentField(Base.driver).sendKeys("MFC027");
Assert.assertEquals(Comparison.emptySearchResult(Base.driver).isDisplayed(), true);
}
#DataProvider(name = "EnvironmentDetails", parallel = true)
public Object[][] getData() {
Object[][] testData = new Object[][] {
{
Platform.MAC, "chrome", "62.0"
}, {
Platform.WIN8,
"chrome",
"62.0"
}, {
Platform.WINDOWS,
"firefox",
"57"
}
};
return testData;
}
#AfterClass
public void tearDown()
{
Base.closeBrowser();
}
}
I could resolve this issue by passing the parameters in the #test method
#Test(testName="Comparison: Verify adding an index in the comparison", dataProvider = "EnvironmentDetails",dataProviderClass = BrowsersDataProvider.class)
public void verifyAddingIndex(Platform platform, String browserName, String browserVersion) throws InterruptedException, MalformedURLException {
//test = extent.createTest(Thread.currentThread().getStackTrace()[1].getMethodName());
Base.getBrowser(platform,browserName,browserVersion);
InvestmentsSearch.login(Base.driver);
like

How to connect to ACR122 with CardService

I'm writing a program (Java Application) for reading ePassport. For access I use the library org.jmrtd. What kind of object should I transfer in CardService.getInstance() ?
import net.sf.scuba.smartcards.CardService;
import net.sf.scuba.smartcards.CardServiceException;
import org.jmrtd.BACKeySpec;
import org.jmrtd.PassportService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class TestComponent {
private static final Logger log = LoggerFactory.getLogger(MainApp.class);
public static void main(String args[]) {
try {
CardService cs = CardService.getInstance(???????);
PassportService ps = new PassportService(cs);
ps.open();
ps.sendSelectApplet(false);
ps.sendSelectApplet(false);
BACKeySpec bacKey = new BACKeySpec() {
public String getDocumentNumber() {
return "xxxxxxxx";
}
public String getDateOfBirth() {
return "yyMMdd";
}
public String getDateOfExpiry() {
return "yyMMdd";
}
};
ps.doBAC(bacKey);
ps.close();
} catch (CardServiceException e) {
e.printStackTrace();
}
}
}
Answer found:
add in pom
net.sf.scuba
scuba-sc-j2se
0.0.13
import net.sf.scuba.smartcards.TerminalCardService;
CardTerminal terminal =TerminalFactory.getDefault().terminals().list().get(0);
CardService cs = CardService.getInstance(terminal);
PassportService ps = new PassportService(cs);
ps.open();

#Test method is not waiting selenium code to complete its execution

package demoActitime;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class LoginActitime {
private String UN;
private String Pass;
private WebElement username;
private WebElement password;
private WebDriver driver = new FirefoxDriver();
private String Url = "http://demo.actitime.com/";
private String Urlvalid = "http://demo.actitime.com/user/submit_tt.do";
private String expected = null;
private String actual = null;
private String xpathUsername = null;
private String xpathPassword = null;
private String xpathLogin = null;
#BeforeMethod
public void findElements()
{
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get(Url);
xpathUsername = "//input[#id='username']";
xpathPassword = "//input[#type='password']";
xpathLogin = "//a[#id='loginButton']/div";
}
#AfterMethod
public void doTask()
{
System.out.println(expected);
driver.findElement(By.xpath(xpathUsername)).clear();
driver.findElement(By.xpath(xpathPassword)).clear();
driver.findElement(By.xpath(xpathUsername)).sendKeys(UN);
driver.findElement(By.xpath(xpathPassword)).sendKeys(Pass);
driver.findElement(By.xpath(xpathLogin)).click();
actual = driver.getTitle();
Assert.assertEquals(actual, expected);
// driver.quit();
}
#Test(priority = 0)
public void LoginValidUNInvalidPass()
{
this.UN="admin";
this.Pass="basheer";
System.out.println("LoginValidUNInvalidPass");
expected = "actiTIME - Login";
}
#Test()
public void LoginValidUNValidPass()
{
this.UN="admin";
this.Pass="manager";
System.out.println("LoginValidUNValidPass");
expected = "actiTIME - Enter Time-Track";
}
#Test
public void LoginInValidUNInvalidPass()
{
this.UN="basheer";
this.Pass="basheer";
System.out.println("LoginInValidUNInvalidPass");
expected = "actiTIME - Login";
}
#Test
public void LoginInValidUNValidPass()
{
this.UN="basheer";
this.Pass="manager";
System.out.println("LoginInValidUNValidPass");
expected = "actiTIME - Login";
}
}
This is my Updated Code. I have removed the initialization, finding of elements in aftermethod and placed in beforemethod. When i pass valid username and password, #After Method is not waiting for web driver to login, its showing test execution is completed.
Try below sample program, it might helps you. I had restructured your code and used #BeforeTest & #AfterTest. Let me know it is working for you or not.
package demoActitime;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class LoginActitime {
//defining all required variables
private String UN = "";
private String Pass = "";
private WebElement username = null;
private WebElement password = null;
private WebElement login = null;
private WebDriver driver = null;
private String Url = "http://demo.actitime.com/";
private String Urlvalid = "http://demo.actitime.com/user/submit_tt.do";
private String expected = null;
private String actual = null;
private String xpathUsername = null;
private String xpathPassword = null;
private String xpathLogin = null;
#BeforeTest
public void findElements()
{
//initialising webdriver with url
driver = new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30,TimeUnit.SECONDS);
driver.get(Url);
//initialising webelements
xpathUsername = "//input[#id='username']";
xpathPassword = "//input[#type='password']";
xpathLogin = "//a[#id='loginButton']/div";
username = driver.findElement(By.xpath(xpathUsername));
password = driver.findElement(By.xpath(xpathPassword));
login = driver.findElement(By.xpath(xpathLogin));
}
#AfterTest
public void doTask()
{
System.out.println(expected);
username.clear();
password.clear();
}
#Test(priority = 0)
public void invalidLogin()
{
this.UN="validUser";
this.Pass="invalidPassword";
username.sendKeys(UN);
password.sendKeys(Pass);
login.click();
expected = "expected title";
actual = driver.getTitle();
Assert.assertEquals(actual, expected);
}
#Test(priority = 1)
public void validLogin()
{
this.UN="validUser";
this.Pass="validPassword";
username.sendKeys(UN);
password.sendKeys(Pass);
login.click();
expected = "expected title";
actual = driver.getTitle();
Assert.assertEquals(actual, expected);
}
}
After clicking login button, its taking time for webpage to change its title. Hence your getting feeling that #afterMethod is not waiting to complete login action.
In case of invalid credentials, after clicking on login button, the webpage title is not changing, and your getting feeling that #after Method is not waiting for login to happen.
Put some 2 seconds wait after clicking on login button and your script will work as expected:
driver.findElement(By.xpath(xpathLogin)).click();
Thread.sleep(2000);

Categories

Resources