OTP UP
Sun Dec 10 2023 10:12:40 GMT+0000 (Coordinated Universal Time)
Saved by @mehran
package tests;
import com.adak.ir.LoggingUtils;
import com.epam.reportportal.annotations.Step;
import com.epam.reportportal.testng.ReportPortalTestNGListener;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.appium.java_client.AppiumBy;
import org.junit.Assert;
import org.openqa.selenium.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import java.io.IOException;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import static java.lang.Thread.sleep;
@Listeners({ReportPortalTestNGListener.class})
public class AppiumAndroidTest extends BasePage {
public static final Logger LOGGER = LoggerFactory.getLogger(AppiumAndroidTest.class);
@Test
void easypayment() throws InterruptedException, IOException {
navigateToSplashPage();
inputNubmer();
// Home();
}
@Step
public void navigateToSplashPage() {
String elementText = "فارسی";
By byText = AppiumBy.androidUIAutomator("new UiSelector().text(\"" + elementText + "\")");
WebElement element = driver.findElement(byText);
element.click();
String screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
LoggingUtils.logBase64(screenshot, "صفحه معرفی");
LOGGER.info(" صفحه معرفی");
}
@Step
public void inputNubmer() throws InterruptedException, IOException {
String baseUrl = "http://192.168.2.112:8090/api/v1/%s";
String assignBodyTemplate = "{\"operator\": \"%s\", \"simType\": \"%s\", \"appName\": \"%s\"}";
HttpClient client = HttpClient.newBuilder().build();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(String.format(baseUrl, "assign")))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(String.format(assignBodyTemplate, "MCI", "CREDIT", "MY_MCI")))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
ObjectMapper objectMapper = new ObjectMapper();
JsonNode jsonNode = objectMapper.readTree(response.body());
driver.findElement(By.id("com.sibche.aspardproject.app:id/edit_text")).sendKeys(jsonNode.get("number").asText());
driver.findElement(By.id("com.sibche.aspardproject.app:id/btn_action")).click();
request = HttpRequest.newBuilder()
.uri(URI.create(String.format(baseUrl, "watch?token=" + jsonNode.get("token").asText())))
.header("Content-Type", "application/json")
.GET()
.build();
response = client.send(request, HttpResponse.BodyHandlers.ofString());
objectMapper = new ObjectMapper();
jsonNode = objectMapper.readTree(response.body());
String code = jsonNode.get("code").asText();
driver.findElement(By.id("com.sibche.aspardproject.app:id/et_pin_code")).sendKeys(code);
LOGGER.info("لاگین");
String screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
LoggingUtils.logBase64(screenshot, "تست otp");
LOGGER.info(" تست otp");
// driver.findElement(By.id("com.sibche.aspardproject.app:id/favorites_container")).isDisplayed();
sleep(500);
driver.findElement(By.id("com.sibche.aspardproject.app:id/barcode_view")).isEnabled();
boolean isWizard = false;
boolean isFavorites = false;
try {
isWizard = driver.findElement(By.id("com.sibche.aspardproject.app:id/wizardPositiveBtn")).isDisplayed();
} catch (NoSuchElementException e) {
// Element not found
}
try {
isFavorites = driver.findElement(By.id("com.sibche.aspardproject.app:id/favorites_container")).isDisplayed();
} catch (NoSuchElementException e) {
// Element not found
}
if (isWizard || isFavorites) {
LOGGER.info("PASS");
} else {
LOGGER.error("Test failed");
Assert.fail("Test failed");
}
String screenshot2 = ((TakesScreenshot) driver).getScreenshotAs(OutputType.BASE64);
LoggingUtils.logBase64(screenshot2, "نهایی");
LOGGER.info(" صفحه نهایی");
}
}



Comments