Leanft Custom Framework HTML reports are not generated - java

Below is my SAMPLE code in which i am trying to create a simple report using the Leanft in which i am getting on result xml file.
#Test
public void Google() throws Exception {
Reporter.init();
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
Thread.sleep(4000);
if( driver.getTitle().equalsIgnoreCase("google")){
Reporter.reportEvent("test", "test",Status.Failed);
}
Reporter.generateReport();
driver.quit();
}

As specified in the docs, if you're going to use a custom framework you'll also need to initialize the SDK (SDK.init() and SDK.cleanup())
E.G.
public static void main(String [] args){
// initialize the SDK and report only once per process
try{
ModifiableSDKConfiguration config = new ModifiableSDKConfiguration();
config.setServerAddress(new URI("ws://myServerAddress:5095"));
SDK.init(config);
Reporter.init();
//put your test code here.
//Generate the report and cleanup the SDK usage.
Reporter.generateReport();
SDK.cleanup();
} catch(Exception e){
}
}

I see nothing wrong with your code as the report generates as you told it too.
However, I believe you were wanting something more like this to show that it PASSES when it finds the Google title:
#Test
public void Google() throws Exception {
Reporter.init();
WebDriver driver = new FirefoxDriver();
driver.get("https://www.google.com");
Thread.sleep(4000);
if( driver.getTitle().equalsIgnoreCase("google")){
Reporter.reportEvent("test", "test",Status.Passed);
} else {
Reporter.reportEvent("test","test",Status.Failed);
}
Reporter.generateReport();
driver.quit();
}

Related

JUnit Test Fails in Jenkins

My JUnit Tests run fine in eclipse and pass locally however in Jenkins my 1st test passes and 2nd one fails and I know why but cant figure out the solution. The Jenkins output says it cant find the element however it is there and I have the proper waits.
Here is the 1st test case that passes.
#Before
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver", "C:\\eclipse\\chromedriver\\chromedriver.exe");
driver = new ChromeDriver();
homeUrl = "https://myadp.adpcorp.com/wps/myportal/main/myADP_new";
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
driver.get(homeUrl);
}
//Full test
#Test
public void fullTest() throws Exception {
step01_VerifyHomePage();
}
// Go to Home page and verify title
public void step01_VerifyHomePage() throws Exception {
driver.getTitle().contains(homeTitle);
Thread.sleep(3000);
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
This is the one that fails in Jenkins
//Full test
#Test
public void fullTest() throws Exception {
step02_HoverMyWorkSpace();
}
public void step02_HoverMyWorkSpace() throws Exception {
WebDriverWait wait = new WebDriverWait(driver,20000);
wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("DivMyWorkList"))));
if ( driver.findElement(By.id("DivMyWorkList")).isDisplayed()){
System.out.println("DivMyWorkList Visiable");
}else{
System.out.println("DivMyWorkList NOT Visiable");
}
// Assert.assertEquals(true, workspace.isDisplayed());
// Thread.sleep(3000);
}
#After
public void tearDown() throws Exception {
driver.quit();
String verificationErrorString = verificationErrors.toString();
if (!"".equals(verificationErrorString)) {
fail(verificationErrorString);
}
}
Jenkins Output
The problem i think is that Jenkins cant find the element because the page is not coming up in what ever environment it is using. When I use
wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("DivMyWorkList")))); Jenkins test hangs and times out.
If this is the case is there a way around this? It dose not make sense that the 1st test passes by using the same url and the 2nd one uses same url to the exact same page and it can find the title but not the web element.
I am using a VM and created a free style project on it.
I have been working on this for the past week any help would be appreciated.

how to Automate/test Android hybrid apps using appium?

I trying to automate a hybrid app using the appium. i had completed the total setup ready and also testing using sample apk file. I facing problem in getting the object properties for my hybrid app. I am not able to inspect ids using Appium inspector or uiautomatorviewer. It shows only one class for my app .
i also need to enable WebView debugging, for making
setWebContentsDebugging Enabled
to true on the WebView class.can any one help me how to do that?
some of the blogs are saying to keep driver.context("web_view"); but i not clear how to get that. please help to to solve this.
thanks.
this is my java class
public class myMavenTest {
private WebDriver driver;
//i think is not the way to do this.so i comented this.
/*public void onCreate(){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
if(0 != (getApplicationInfo().flags = ApplicationInfo.FLAG_DEBUGGABLE)){
WebView.setWebContentsDebuggingEnabled(true);
}
}
}*/
#BeforeTest
public void setUp() throws Exception
{
System.out.println("in the setup function");
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability(CapabilityType.BROWSER_NAME, "");
capabilities.setCapability("deviceName","My Android");
capabilities.setCapability("platformVersion","5.1");
capabilities.setCapability("platformName","Android");
capabilities.setCapability("appPackage","com.mysoftware.testapp");
capabilities.setCapability("appActivity","com.mysoftware.testapp.MainActivity");
try
{
driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(5,TimeUnit.SECONDS);
//Thread.sleep(10000);
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
}
#Test
public void Loginforsample() throws Exception
{
System.out.println("in the login() function");
//i tried using classname of my app. but it is not recognizing
driver.findElement(By.className("ink-dark")).click();
//After the button clicks need to enter the text
driver.findElement(By.xpath("//need to find xpath'")).sendKeys("My first Automation");
//tried using selendroid.apk works fine here.
/*driver.findElement(By.id("io.selendroid.testapp:id/startUserRegistration")).click();*/
Thread.sleep(10000);
}
#AfterTest
public void tearDown() throws InterruptedException
{
Thread.sleep(10000);
driver.quit();
}
}
Use below the sample Hybrid App code which I have written for a combination of WEBView Native View. Hope it helps for you!
public class Hybrid_App {
public static void main(String[] args) throws MalformedURLException, InterruptedException{
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("deviceName", "Atom 2x");
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "5.1");
capabilities.setCapability("appPackage","***YourHydridAppPkg****");
capabilities.setCapability("appActivity", "****YourlauchableActivity***");
AndroidDriver driver= new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
Thread.sleep(4000);
Set<String> contextHandles = driver.getContextHandles();
Map<String,String> hashMap= new HashMap<String,String>();
for(String contextname:contextHandles){
if(contextname.contains("NATIVE")){
hashMap.put("native", contextname);
}else{
hashMap.put("webview", contextname);
}
}
//native page - Native
driver.context(hashMap.get("native"));
WebDriverWait wait= new WebDriverWait(driver, 50);
WebElement ele_voucher = wait.until(ExpectedConditions.visibilityOfElementLocated(
By.xpath("//*[#class='android.view.View'][#index='9'][#content-desc='VOUCHERS']")));
System.out.println(ele_voucher.isDisplayed());
Thread.sleep(6000);
ele_voucher.click();
Thread.sleep(9000);
//second page - Native
driver.context(hashMap.get("native"));
Thread.sleep(5000);
driver.findElementByXPath("//*[#class='android.view.View'][#index='17'][#content-desc='REDEEM']").click();
Thread.sleep(8000);
System.out.println("----Third page----"+" uname,pwd element");
//third page - Webview
driver.context(hashMap.get("webview"));
Thread.sleep(6000);
driver.findElementByXPath("//input[#class='x-input-email'][#type='email'][#name='email']").sendKeys("descbatch#gmail.com");
WebElement ele_pwd = driver.findElementByXPath("//input[#class='x-input-password'][#type='password'][#name='password']");
ele_pwd.click();
Thread.sleep(4000);
ele_pwd.sendKeys("12345");
Thread.sleep(6000);
System.out.println("----Third page----"+" Sign in element");
//fourth page - Native
driver.context(hashMap.get("native"));
Thread.sleep(6000);
driver.findElementByXPath("//*[#class='android.view.View'][#index='69'][#content-desc='SIGN IN']").click();
Thread.sleep(6000);
driver.sendKeyEvent(AndroidKeyCode.BACK);
}
}

Not able to click on permission pop-up (Access Contact List) in appium

I am new to Appium.
I am trying to automate an application which on launch asks to allow to access Contact List. I did research on various websites for the solution but couldn`t resole this issue.
Code:
public class TestSuiteBase {
WebDriver driver = null;
//Element Variables
String deviceIdTextbox = "et_Registration_DeviceID";
#BeforeClass
public void setup() throws MalformedURLException, InterruptedException {
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("platformVersion", "4.4.2");
capabilities.setCapability("deviceName", "0ef3c26f");
capabilities.setCapability("browserName", "");
capabilities.setCapability("app", "D:\\Ashish\\AppiumProject\\Mobile Framework\\apk\\androidApplication.apk");
capabilities.setCapability("appPackage", "com.atyati.rbl.mfi");
capabilities.setCapability("appActivity", "com.atyati.rbl.mfi.Activity.SplashScreenActivity");
AndroidDriver driver = new AndroidDriver(new URL("http://127.0.0.1:4723/wd/hub"), capabilities);
driver.manage().timeouts().implicitlyWait(80, TimeUnit.SECONDS);
Thread.sleep(10000);
}
#Test
public void Test() throws Exception {
Thread.sleep(2000);
DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("appWaitPackage", "com.android.packageinstaller");
capabilities.setCapability("appWaitActivity", ".permission.ui.GrantPermissionsActivity");
System.out.println("Trying to click Allow");
driver.findElement(MobileBy.id("permission_allow_button")).click();
driver.findElement(By.id(deviceIdTextbox)).sendKeys("123456789");
}
#AfterClass
public void tearDown() throws Exception {
driver.quit();
}
Output: My code launches the app but when permission pop-up surfaces, it is unable to click.
Issue: Not able click on permission pop-up.
Query: Do I need to specify "appActivity" before moving to each screen?
Let me know if any other details needed.
I have figured it out where I was going wrong.
Solution: I have to specify the complete resource id for the Edit Textbox
String deviceIdTextbox = "com.atyati.rbl.mfi:id/et_Registration_DeviceID";
Also, it is not needed to specify the activity.
#Test
public void Test() throws Exception {
Thread.sleep(1000);
if(androidDriver!=null){
System.out.println("driver does not == null");
System.out.println("Trying to click Allow");
androidDriver.findElement(By.id(contactListAllowPermissionBtn)).click();
Thread.sleep(1000);
androidDriver.findElement(By.id(deviceIdTextbox)).sendKeys("123456789");
androidDriver.findElement(By.id(registerUserBtn)).click();
} else {
System.out.println("driver == null");
}
}
You can use this JAVA CODE for clicking on allow app permission button as many times it appears. just add the method and in your class file and call the method in your test case. This code is taken from example on THIS POST
public void allowAppPermission(){
while (driver.findElements(MobileBy.xpath("//*[#class='android.widget.Button'][2]")).size()>0)
{ driver.findElement(MobileBy.xpath("//*[#class='android.widget.Button'][2]")).click();
}
}

Selenium WebDriver using TestNG and Excel

Hello i really need help with Selenium WebDriver using TestNG and Excel
i try to get data from excel to open browser and navigate URL. its work successfully and terminal and testng report showing test pass but its not open browser or doing anything its just run its self and show report
Config File
public void openBrowser(String browser){
try {
if (browser.equals("Mozilla")) {
driver = new FirefoxDriver();
} else if(browser.equals("IE")){
driver = new InternetExplorerDriver();
} else if(browser.equals("Chrome")){
System.setProperty("webdriver.chrome.driver", "\\Applications\\Google Chrome.app\\Contents\\MacOS\\Google Chrome ");
driver = new ChromeDriver();
}
} catch (Exception e) {
}
}
public void navigate(String baseUrl){
try {
driver.manage().window().maximize();
driver.manage().deleteAllCookies();
driver.navigate().to(baseUrl);
} catch (Exception e) {
}
}
And Test Execute File
public class NewTest {
public String exPath = Config.filePath;
public String exName = Config.fileName;
public String exWrSheet = "Logiin Functional Test";
public Config config;
#BeforeTest
public void openBrowser() {
config = new Config();
Excel.setExcelFile(exPath+exName, exWrSheet);
String browser = Excel.getCellData(1, 2);
config.openBrowser(browser);
}
#BeforeMethod
public void navigate() {
config = new Config();
Excel.setExcelFile(exPath+exName, exWrSheet);
String baseUrl = Excel.getCellData(2, 2);
config.navigate(baseUrl);
}
#Test
public void test() {
System.out.println("Test");
}
#AfterTest
public void closeBroser() {
//Config.tearDown();
}
I don't have quite enough rep to make a comment, which I would prefer here, but if you aren't getting any sort of exception, I'd suspect the value you're getting for the browser variable is not matching anything in your if-then-else in openBrowser and then falling through. Step through the code with a debugger or just add:
String browser = Excel.getCellData(1, 2);
System.out.println("Browser value from Excel =" + browser);
config.openBrowser(browser);
to see what you're reading from the file.
1 - TestNg is always pass because you are using "void" method and you catch "all" exception
2 - No browser opened because in openBrowser(String browser), NullPointException throws and you already catch it.
-> you need to init an instance of WebDriver and pass it through your test.

Web driver is not performing actions on web page

I'm automating a php web page using webdriver and java language. My code was executing and I was able to perform actions on web page, but today only the login method is executing and my second method gets failed everytime I run. I'm so worried why it is happening. Please help, I'm new in automation testing.
public class TestNGClass {
private String baseUrl = "http://test.com/test2/1.4.6.3/public/admin/";
private WebDriver driver = new FirefoxDriver();
#Test
public void login() {
driver.manage().window().maximize();
driver.get(baseUrl);
driver.findElement(By.name("username")).sendKeys("abc");
driver.findElement(By.name("password")).sendKeys("123");
driver.findElement(By.name("login")).submit();
System.out.print("\nCongrats..You have successfully logged in.");
}
#Test
public void createUser() {
String expectedTitle = "User";
String actualTitle = driver.getTitle();
Assert.assertEquals(actualTitle, expectedTitle,"Title Not Found!");
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.xpath("//body/div[3]/div[2]/ul/li[2]/a/img")).click();
Error :
java.lang.AssertionError: Title Not Found! expected [User] but found []
This is because you are using Assert.
Assert.assertEquals(actualTitle, expectedTitle,"Title Not Found!");
Make use of Try catch in-order to proceed next step.
try{
Assert.assertEquals(actualTitle, expectedTitle,"Title Not Found!");
}catch (Exception e)
{
}

Categories