Fixing Unsuccessful Transaction on Payment Gateway using Midtrans (Android) - java

So I recently just trying to understand deeper into Payment Gateway (Android). I already read the documentation and try to implement it into my Android project. So here's the thing, couple times even until now, I'm always getting a message "Transaction unsuccessful. Please try again with another card or with a different payment method" when I try to click a button called Pay. So this Pay button when I clicked it, it supposed to open a new tab (page) to show all of the Payment Method. But again that page never showed up, and showing those errors only.
Can anyone help me fixing this problem? I'm gonna send u guys the code if u guys need it. BIG THANKS :)

This is my button code looks like. How did I can get a page that showing PaymentUiFlow (Payment Method Page)? I already try to configure it out with many different ways but still showing the same error.
private void actionButton() {
MidtransSDK.getInstance().setTransactionRequest(DataCustomer.transactionRequest(
"1",
getIntent().getIntExtra("price", 0),
getIntent().getIntExtra("qty", 0),
getIntent().getStringExtra("name")));
MidtransSDK.getInstance().startPaymentUiFlow(ProductOrderActivity.this, PaymentMethod.BANK_TRANSFER_MANDIRI);
}

Related

How to "handle" an alert as per UnhandledAlertException?

This topic is sadly very poisoned by non-applying answers, e.g. 1, 2, 3, 4, etc. pp.
The issue:
One may do an action which, when successful, makes the website raise an alert.
E.g. click on a "logout" button to see an "Are you sure you want to logout?" alert:
public class Logout extends PageObject {
static final Target LOGOUT = /* logout button, which will display the alert when clicked */;
public Performable logout() {
return Task.where("{0} clicks on Logout"
, Ensure.that(LOGOUT).isDisplayed()
, Click.on(LOGOUT) // done manually: alert visible; done by Serenity: no alert
);
}
}
Serenity will cause an org.openqa.selenium.UnhandledAlertException during execution of Click.on and the alert will not be present after this task. If the next task would be "interact with alert" in any way or form (as done in all the linked articles and all others I have perused before posting this question), the next task will then always fail because there is no alert .
This can be easily observed in the browser window as well: The alert may show, if at all, for but a split second and immediately disappear.
The question:
Given that the alert has to be handled before the action causing it completes: How do I do that?
N.b.:
I have done a deeper analysis in this old bug report. Includes a call stack where one may place breakpoints inbetween the alert's appearance and disappearance.
Others have indicated that it is an issue pertaining to chromedriver - but using a different framework with the same chromedriver works just fine.
A workaround might be to disable screenshots, but
I do not want to do that!
Serenity indicates (via a log warning) that this is a user error. So I'd rather correct my error than work around it.

WebDriverException when clicking the OK button on a Anyline dialog

So all I want to do is clicking on dialog that only pops up on the iOS Simulator (iOS 14.5, Appium Java-Client 7.3.0).
The dialog comes from Anyline because of course I have no camera on the simulator.
If there is any way to hide this dialog it would solve my problem too, I tried this with capabilities but it doesn't worked.
cap.setCapability("autoAcceptAlerts", false);
cap.setCapability("autoDismissAlerts", false);
Selecting the dialog is no problem, i can check that the Dialog is here:
#iOSXCUITFindBy(accessibility = "Anyline SDK cutout UI")
public IOSElement anylineDialog;
This is how it looks like:
So the next step would be to just click the ok button it worked at the beginning but now I can't even select it in the Appium Inspector anymore. Before I just used this:
#iOSXCUITFindBy(accessibility = "OK")
public IOSElement okButton;
I don't know why it doens't work anymore, but I can still select it with the help of TestProject.
I tested a lot of different selectors but it doesn't worked. (the one with accessibility = "OK" is also recommended in this tool)
I always get this exception and I don't know how to fix it, try catch also doesn't work:
org.openqa.selenium.WebDriverException: An unknown server-side error occurred while processing the command. Original error: *** -[__NSArrayM insertObject:atIndex:]: object cannot be nil
I tried out the stuff on this page and I also get the OK button as the only button as this code snippet shows.
HashMap<String, String> args = new HashMap<>();
args.put("action", "getButtons");
List<String> buttons = (List<String>)driver.executeScript("mobile: alert", args);
Also from the same site, I tried this with the same result.
args.put("action", "accept");
args.put("buttonLabel", "OK");
driver.executeScript("mobile: alert", args);
Maybe this is to specific but if someone has an idea how I could solve it, I would be very thankful.
The iOS bug you mentioned has been fixed in Appium 1.22.1 and 2.0.0-beta. Be sure you are running one of those versions and you should be fine.

Problem clicking elements using class and index

I'm trying to write code to automatically DM people on Instagram. Im stuck on getting the code to click on the DM button.
In UIautomatorviewer, there is no text or a resource-id, so I tried using the class.
When I run the code it doesn't click on the right thing. It clicks on the button NEXT to it.
Here is the code -
By path2 = By.xpath("//android.widget.ImageView[#index='3']");
driver.findElement(path2).click();
Thread.sleep(5000);
Can anyone help? I'm new to this so i'm not very experienced.
Because I can not see the entire XML I can not really tell what you did wrong but probably your xpath is not correct.
With UIAutomatorViewer you can save the XML and then you can test your xpath on it. Either with XMLSpy or an online tool like https://www.freeformatter.com/xpath-tester.html.
Probably there are more android.widget.ImageView with index = 3 and I think appium selects the first one? So you could change your xpath to a more unique one like:
//android.widget.FrameLayout//android.widget.LinearLayout//android.widget.ImageView[#index='3']"
Based on UIAutomator Viewer screen you can also use content-desc as shown below
By path2 = By.xpath("//android.widget.ImageView[contains(#content-desc,'Message')]");
driver.findElement(path2).click();

Handle Logout Button Action of JavaFX Application

Here is part of my code that shows error. This is done inside public void start method. I have already done the Login part, whenever user logs in the id and password remains in the TextField. Which is why I have created a logout button so that when user clicks on it, I want the useridtextfield & passwordtextfield to be empty.
LogoutButton.setOnAction(e->
UserIdTextField==null;
PasswordTextField==null;);
I have searched over the internet about this problem but got no solution regarding JavaFX Logout handling. I have no idea about FXML so I would appreciate any help.
The syntax for a lambda expression with multiple statements is
logoutButton.setOnAction(e -> {
/* statements */
});
(I.e. you need to delimit the statements with { ... }.)
As pointed out in the comments, comparing the text fields to null is probably not what you want to do here, but it will at least compile.

How to handle 'Are you sure you want to navigate away from this page' on page close?

I have an web application, which generates a JS message
'Are you sure you want to navigate away from this page?' when you try to open a new page.
I know I can handle this message by
Selenium.getAlert();
(or some modification of it, I haven't tried it yet)
But my main problem is that this message generates only when I leave this page.
In selenium I can leave page by using
Selenium.open("new address");
or
Selenium.back();
So I use code like this
Selenium.open("new address");
Selenium.getAlert();
But the problem is that Selenium.open doesn't finish and go to next code line in program until the new page is fully loaded, but the page can't be loaded until program goes to next code line and handles this alert. So it's ablocked situation and I don't know how to handle it.
I don't think it can be done, staying entirely within the Selenium RC API. I have cases similar to this that I handle by launching an AutoIt script, before the open(), that waits for the prompt and answers it. That only works on Windows, but if you need something for other systems, I'm sure there are equivalent tools.
Selenium has always had a problem with alerts and confirmations (which this is - a confirmation has an OK/Cancel choice) that occur duing page loading. There's even an ancient bug number enshrined in one of the error messages that explains that it can't catch them.
Use:
openAndWait(..)
Maybe this other SO question will help you.
I don't know if this will work, but it's an idea. You could try something like:
try {
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
Selenium.open("new address");
} catch (Exception e) {
// Should throw after 1 second
}
// Now we may be able to interact with the alert.
Selenium.getAlert();

Categories

Resources