How to automate on End Test result Fail?

How to automate on End Test the result Fail?

  • If i use Username and Password invalid

  • On appiumstudio-reports

Test Execution Summary:

  • Step 9 = Failed

End Test:

  • End Test = Passed!?

Why the status on End Test is Passed?

And how i create on Appium Studio this specification?
When the Username and Password is valid i reseave the same error on appiumstudio-reports.

Because i have included on final step the call:
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//[@id=‘loginButton’]")));
driver.findElement(By.xpath("//
[@text=‘Login’]")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//[@id=‘loginStateMessage’]")));
String attribute1 = driver.findElement(By.xpath("//
[@text=(‘Etape 9 : Conection Failure’)]")).getAttribute(“id”);

Hi

In case you want to set the test status to fail or pass we have a method that allows you to do that :

driver.executeScript("client:client.setTestStatus(true,'msg : test pass')"); driver.executeScript("client:client.setTestStatus(false,'msg : test fail')");

e.g

String attribute1 = driver.findElement(By.xpath("//[@text=(‘Etape 9 : Conection Failure’)]")).getAttribute(“id”);
if (attribute1 == "failed")
 driver.executeScript("client:client.setTestStatus(false,'msg : test fail')");
else
 driver.executeScript("client:client.setTestStatus(true,'msg : test pass')");

Hello! Thanks for feedback me.
How and where do i put this examples to test?

“if (attribute1 == “failed”)
driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);
else
driver.executeScript(“client:client.setTestStatus(true,‘msg : test pass’)”);”

On this field?

because already try, and i don’t see any difference:

Instead of = xpath=//*[@text=(‘Etape 9 : Connection Passed’)]

I put the new = xpath=//*[@text=(‘Etape 9 : Connection Passed’)]")).getAttribute(“id”);
if (attribute1 == “passed”)
driver.executeScript(“client:client.setTestStatus(false,‘msg : test passed’)”);
else
driver.executeScript(“client:client.setTestStatus(true,‘msg : test failed’)”);

and the screen give the same feedback

can you share your java code?

also, which version of Appium Studio are you using?

Sure!

Appium Studio version = 11.4.83 (2018-01-21)

Java code:
//package ;
import io.appium.java_client.remote.AndroidMobileCapabilityType;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.android.AndroidElement;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.junit.*;
import java.net.URL;
import java.net.MalformedURLException;

public class LoginInvalido {
private String reportDirectory = “reports”;
private String reportFormat = “xml”;
private String testName = “LoginInvalido”;
private String accessKey = ";
protected AndroidDriver driver = null;

DesiredCapabilities dc = new DesiredCapabilities();

@Before
public void setUp() throws MalformedURLException {
dc.setCapability(“reportDirectory”, reportDirectory);
dc.setCapability(“reportFormat”, reportFormat);
dc.setCapability(“testName”, testName);
dc.setCapability(“accessKey”, accessKey);
dc.setCapability(MobileCapabilityType.UDID, “77671511090002076”);
driver = new AndroidDriver<>(new URL(“https://cloud.experitest.com:443/wd/hub”), dc);
}

@Test
public void testLoginInvalido() {
driver.findElement(By.xpath("//[@id=‘username’]")).sendKeys(“eleve10”);
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//
[@id=‘password’]")));
driver.findElement(By.xpath("//[@id=‘password’]")).sendKeys(“eleve10”);
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//
[@id=‘loginButton’]")));
driver.findElement(By.xpath("//[@text=‘Se connecter’]")).click();
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//
[@id=‘loginStateMessage’]")));
String attribute1 = driver.findElement(By.xpath("//[@text=(‘Etape 9 : Connexion réussie’)]")).getAttribute(“id”); if (attribute1 == “passed”) driver.executeScript(“client:client.setTestStatus(false,‘msg : test passed’)”); else driver.executeScript(“client:client.setTestStatus(true,‘msg : test failed’)”);")).getAttribute(“id”);
// driver.findElement(By.xpath("//
[@text=(‘Etape 9 : Connexion réussie’)]")).getAttribute(“id”); if (attribute1 == “passed”) driver.executeScript(“client:client.setTestStatus(false,‘msg : test passed’)”); else driver.executeScript(“client:client.setTestStatus(true,‘msg : test failed’)”);"));
}

@After
public void tearDown() {
driver.quit();
}
}

Hello Tom,

I forgot to say to you that i’m only testing Appium and Appium Studio without “code written” + usb device.

So the help you give me, with this code, it makes more sense if it is modified. If i have some program to execute like Eclipse.

"driver.executeScript(“client:client.setTestStatus(true,‘msg : test pass’)”); driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);

e.g

String attribute1 = driver.findElement(By.xpath("//[@text=(‘Etape 9 : Conection Failure’)]")).getAttribute(“id”);
if (attribute1 == “failed”)
driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);
else
driver.executeScript(“client:client.setTestStatus(true,‘msg : test pass’)”);"

But i’m started to testing with Eclipse Java + Appium Studio.
Searching contents about (how to working Eclipse with Appium Studio), the only way that i found, it was with plugin, but with cloud devices.
With my USB device i can’t have the url feedback report with passed or fail steps.
How can i be able to do it?

My code look like this :slight_smile:

package org.test;

import static org.junit.Assert.assertEquals;

import io.appium.java_client.MobileElement;
import io.appium.java_client.android.AndroidDriver;
//import junit.framework.TestCase;
//import org.junit.Test;
import org.junit.After;
import org.junit.Before;

//import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;

public class Test {

 static AndroidDriver driver;

 
public static void main(String[] args) throws MalformedURLException {

//Before
setUp();
sampleTest();
tearDown();
driver.executeScript(“client:client.setTestStatus(true,‘msg : test passed’)”);
driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);

}
//Test
public static void sampleTest() {
MobileElement el1 = (MobileElement) driver.findElementById("…:id/username");
el1.sendKeys(“11”);
MobileElement el2 = (MobileElement) driver.findElementById("…:id/password");
el2.sendKeys(“11”);
MobileElement el3 = (MobileElement) driver.findElementById("…:id/loginButton");
el3.click();
MobileElement el4 = (MobileElement) driver.findElementById("…/loginStateMessage");

    String attribute1 = driver.findElement(By.xpath("//[@text=('mauvais login/mot de passe')]")).getAttribute("id");
    if (attribute1 == "failed")
 	   driver.executeScript("client:client.setTestStatus(false,'msg : test fail')");
 	  else
 	   driver.executeScript("client:client.setTestStatus(true,'msg : test passed')");
       driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);

  }
  public static void tearDown() {
	  
	  driver.quit();
 
}
  
//After
  public static void setUp() throws MalformedURLException {
	    DesiredCapabilities desiredCapabilities = new DesiredCapabilities();
	    desiredCapabilities.setCapability("deviceName", "...");
	    desiredCapabilities.setCapability("platformName", "Android");
	    desiredCapabilities.setCapability("appPackage", "...l");
	    desiredCapabilities.setCapability("appActivity", "...");
	    desiredCapabilities.setCapability("udid", "...");
	    desiredCapabilities.setCapability("platformVersion", "5.0");
	  

	    
	  driver = new AndroidDriver(new URL("http://localhost:4723/wd/hub"), desiredCapabilities);


	  }

}

You release the driver (run the tearDown() method) before you are calling the

driver.executeScript(“client:client.setTestStatus(true,‘msg : test passed’)”);
driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);

change the Main function to

setUp();
sampleTest();
driver.executeScript(“client:client.setTestStatus(true,‘msg : test passed’)”);
driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);
tearDown();

for cloud execution, I’ve created a separate thread

Hello Tom!

I will change the main function //Before.

But on code //Test, the step already are there too.
It’s the good way? or i’ve only to put the driver reference on step //Before - //Test

I have some doubt about libraries.
This is the correct list to add? "import…:
Selenium-api-2.42.2
imageClient.jar
xmlrpc-client-3.1.2.jar
xmlrpc-common-3.1.2.jar
ws-common-util-1.0.2.jar
junit.jar
mobile-webdriver.jar

Hi Tom,
The code you gave me:
“setUp();
sampleTest();
driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);
tearDown();”

Origin this error:
Exception in thread “main” org.openqa.selenium.JavascriptException: javascript error (javascript error. TypeError: client.setTestStatus is not a function in at line number 1) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.9.1’, revision: ‘63f7b50’, time: ‘2018-02-07T22:42:22.379Z’
System info: host: ‘…’, ip: ‘…’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_161’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity:"…"…, appPackage: “…”, autoAcceptAlerts: false, autoDismissAlerts: false, autoWebview: false, desired: {appActivity: com.unowhy.sqool.activities…, appPackage:"…", deviceName: …, platformName: Android, platformVersion: 5.0, udid: 77671511090002076}, device.category: TABLET, device.majorVersion: 5.0.x, device.manufacture: “…”, device.model: …, device.name: …, device.os: Android, device.screenSize: 1280x800, device.serialNumber: 77671511090002076, device.version: 5.0, deviceName: …, dontGoHomeOnQuit: false, dontStopAppOnReset: false, fullReset: false, instrumentApp: false, javascriptEnabled: true, keystorePath: ~/.android/debug.keystore, noReset: false, platform: ANDROID, platformName: ANDROID, platformVersion: 5.0, projectName: , reportDirectory: reports, reportFormat: xml, reportUrl: C:\Users\User01\appiumstudi…, reservationDuration: 240, testName: Untitled, udid: 77671511090002076, useKeystore: false, waitForDeviceTimeout: 120000}
Session ID: 74ffccf8-7bc0-4859-b89d-fd49e93ecc11
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:537)
at org.test.Test.main(Test.java:38)

can you try with the attached version?

http://d242m5chux1g9j.cloudfront.net/AppiumStudio_windows_11_5_57.exe

Hello Tom!

Thanks for share the new Appium Studio Version.
But now i’ve other error

   setUp();
   sampleTest();
   driver.executeScript("client:client.report(\"msg : test fail\")");
   tearDown();

Now the error is this:
Exception in thread “main” org.openqa.selenium.JavascriptException: javascript error (javascript error. TypeError: Can not invoke method [jdk.internal.dynalink.beans.SimpleDynamicMethod Map com.experitest.image.agent.appium.backend.commands.browser.AppiumScriptClient.report(String,boolean)] with the passed arguments; they do not match any of its method signatures. in at line number 1) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
Build info: version: ‘3.9.1’, revision: ‘63f7b50’, time: ‘2018-02-07T22:42:22.379Z’
System info: host: …’, ip: ‘172.25.102.33’, os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘1.8.0_161’
Driver info: io.appium.java_client.android.AndroidDriver
Capabilities {appActivity: “”…, appPackage: “”, autoAcceptAlerts: false, autoDismissAlerts: false, autoWebview: false, desired: {appActivity:””…, appPackage: …, deviceName: …, platformName: Android, platformVersion: 5.0, udid: 77671511090002076}, device.category: TABLET, device.majorVersion: 5.0.x, device.manufacture: …, device.model: …, device.name: …, device.os: Android, device.screenSize: 1280x800, device.serialNumber: 77671511090002076, device.version: 5.0, deviceName: “”, dontGoHomeOnQuit: false, dontStopAppOnReset: false, fullReset: false, instrumentApp: false, javascriptEnabled: true, keystorePath: ~/.android/debug.keystore, noReset: false, platform: ANDROID, platformName: ANDROID, platformVersion: 5.0, projectName: , reportDirectory: reports, reportFormat: xml, reportUrl: C:\Users\User01\appiumstudi…, reservationDuration: 240, testName: Untitled, udid: 77671511090002076, useKeystore: false, waitForDeviceTimeout: 120000}
Session ID: d0dba142-613a-40bf-9375-2a719192744f
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:160)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:129)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:601)
at io.appium.java_client.DefaultGenericMobileDriver.execute(DefaultGenericMobileDriver.java:42)
at io.appium.java_client.AppiumDriver.execute(AppiumDriver.java:1)
at io.appium.java_client.android.AndroidDriver.execute(AndroidDriver.java:1)
at org.openqa.selenium.remote.RemoteWebDriver.executeScript(RemoteWebDriver.java:537)
at org.test.Test.main(Test.java:39)

try : driver.executeScript(“client:client.report(“msg : test fail”,false )”);

Tom,

Last week, i’m already been talking with someone from seetest.io.
I’m waiting for her answer.

If I change the line of code you sent me, asks me to create a string!
It passed the boolean as string!?

driver.executeScript(“client:client.report(‘msg : test fail’,false )”);

I try to find out what this “reportDirectory” and “reportFormat” actualy does. But there seem to be no documentation.

Do you know what it does or did you just copy paste the code from somewhere.

Here is some doc regarding this - https://docs.experitest.com/display/TC/Reporting+Capabilities

1 Like

Interesting, thanks for the link. After tying a bit more I noticed that Appium Studio will generate a report but Appium Server will not. There seem to be some significant differences between the two.