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: Error Test_Executor Get id from element NATIVE:xpath=//*[@text=('Etape 9 : Fail connection)][0

Because i have included steps:
public void testLoginInvalido() {
driver.findElement(By.xpath("//[@id=‘username’]")).sendKeys(“user1”);
new WebDriverWait(driver, 10).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//
[@id=‘password’]")));
driver.findElement(By.xpath("//[@id=‘password’]")).sendKeys(“user1”);
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 : Fail connection’)]")).getAttribute(“id”);
}

The final call to exception:
Step 8 =
Element : xpath=//*[@id=‘loginStateMessage’]
Time Out 10000

Step 9 =
Element : xpath=//[@text=(‘Etape 9 : Fail connection’)]
Property : Id
Log:
ERROR: ----> 10:58:56 AM Error Test_Executor Get id from element NATIVE:xpath=//
[@text=('Etape 9 : Fail connection)][0]

ERROR: ----> 10:58:56 AM Error Test_Executor Element was not identified: ‘xpath=//*[@text=(‘Etape 9 : Fail connection’)]’

@MiriamCoelho Appium studio forum is here:

Hello Telmo!

Yesterday i’ve created some post on the link that you send me but “…” blocked me

Apparently you were blocked :slight_smile: and from the stats on your user, you dont have any topic so it was deleted. You can try and reach them https://experitest.com/support/contact-us/ or just try other alternatives for your tests (open source or comercial ones).

G’luck

It’s a problem!
On my first post to asking help, i’m block…

Thanks Telmo

Hello Telmo!

I have managed some testing on platform Appium Studio. But for now it’s not my priority - cloud devices.

My priority is testing Appium with USB Devices and I need help to understand how can i create some issues with help (Eclipse+Appium) and how connect eclipse to provide the report about the test that as been executable?

If my test is related to a login fail, how can i have the result about it?

When i try this example:
//Test
public static Boolean 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("…:id/loginStateMessage");

    String attribute1 =  driver.findElementById("...id/errorMessage").getAttribute("hidden");
    if (attribute1 == "true") return false;
    else return true;

Console give this error:
Not recognise - String attribute1 = driver.findElementById(“id/errorMessage”).getAttribute(“hidden”);

There isn’t “hidden” attribute. Are you trying to make sure element with id “errorMessage” is visible or is not visible?

=S

When the login fail this “errorMessage” appear on device, so i tried to rule the option (if appear the message login fail, also test fails) in that case the attribute Hidden to"visible or not visible".

You have other option to help me?

Already have try put this code: driver.executeScript(“client:client.setTestStatus(false,‘msg : test fail’)”);

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

But gave me 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: ……, appPackage: …, deviceName: …, platformName: Android, platformVersion: 5.0, udid: 77671511090002076}, device.category: TABLET, device.majorVersion: 5.0.x, device.manufacture: …y, 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……, 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)

If it is suppose to appear just look for it:

driver.findElementById("...id/errorMessage")

If it doesn’t appear it will throw an exception and that fails test, if not exception is not thrown and so test is succeeded. You should also explore waits in order to wait for elements (FluentWait or WebDriverWait).

Hello Telmo!

I have try this code:

“String attribute1 = driver.findElementById(”…:id/errorMessage").getAttribute(“hidden”);
if (attribute1 == “true”) return false;
else return true;"

Something like this:
public class Test {

 static AndroidDriver driver;

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

“setUp();
sampleTest();
driver.executeScript(“client:client.report(“msg : test fail”)”);
tearDown();

public static Boolean 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("…:id/loginStateMessage");

String attribute1 = driver.findElementById(“com.unowhy.sqool:id/errorMessage”).getAttribute(“hidden”);
if (attribute1 == “true”) return false;
else return true;

Eclipse gave this error:
Exception in thread “main” org.openqa.selenium.NoSuchElementException: An element could not be located on the page using the given search parameters. (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
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: “”, databaseEnabled: false, desired: {appActivity: “”…, appPackage: “”, deviceName: “”, platformName: android, platformVersion: 5.0, udid: 77671511090002076}, deviceManufacturer: “”, deviceModel: “”, deviceName: 77671511090002076, deviceScreenSize: 1280x800, deviceUDID: 77671511090002076, javascriptEnabled: true, locationContextEnabled: false, networkConnectionEnabled: true, platform: LINUX, platformName: LINUX, platformVersion: 5.0, takesScreenshot: true, udid: 77671511090002076, warnings: {}, webStorageEnabled: false}
Session ID: 760090eb-a6c0-4e85-868a-82871f1679f6
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.RemoteWebElement.execute(RemoteWebElement.java:279)
at io.appium.java_client.DefaultGenericMobileElement.execute(DefaultGenericMobileElement.java:45)
at io.appium.java_client.MobileElement.execute(MobileElement.java:1)
at io.appium.java_client.android.AndroidElement.execute(AndroidElement.java:1)
at org.openqa.selenium.remote.RemoteWebElement.getAttribute(RemoteWebElement.java:128)
at org.test.Test.sampleTest(Test.java:57)
at org.test.Test.main(Test.java:38)

Hello Telmo!

I’ve edited the answer of March 2, because before, i put here the wrong response code from Eclipse.

Hello Telmo!

I’ve tried some other solution:

Instead of =

“//Before
setUp();
sampleTest();
driver.executeScript(“client:client.report(“msg : test fail”)”);
tearDown();

String attribute1 = driver.findElementById("…:id/errorMessage").getAttribute(“hidden”);
if (attribute1 == “true”) return false;
else return true; “

** Code change, to =

“//Before
setUp();
sampleTest();
tearDown();

FluentWait wait = new FluentWait(driver);
Boolean element = (Boolean) wait.until(new ExpectedCondition() {

		@Override
		public Boolean apply(WebDriver arg0) {
			// TODO Auto-generated method stub
			return driver.findElementById("com.unowhy.sqool:id/errorMessage").isDisplayed();
		}

	});
    
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

      if (element == true) {
    	  driver.executeScript("client:client.setTestStatus(false,'msg : test fail')");
    
    	  return false;
      }
      else {
    	  return true;
      }

But the step 12 has the status passed and green color: