package test;
import Base_data.DefaultMapPayment;
import com.codeborne.selenide.Selenide;
import database.DataBase;
import io.qameta.allure.Allure;
import io.qameta.allure.Description;
import io.qameta.allure.Owner;
import io.qameta.allure.Step;
import io.qameta.allure.model.Status;
import org.assertj.core.api.SoftAssertions;
import org.json.JSONException;
import org.json.JSONObject;
import pkg.Account;
import page.Login_page;
import pkg.Payment;
import org.openqa.selenium.Cookie;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import static com.codeborne.selenide.Selenide.executeJavaScript;
public class Test {
final tests.MapDB MapDB = new tests.MapDB();
final Login_page Login_page = new Login_page();
final DataBase DataBase = new DataBase();
final DefaultMapPayment DefaultMapPayment = new DefaultMapPayment();
@org.junit.jupiter.api.Test
@Owner("Daria Dodonova")
@Description("Readonly Payment")
@Step
public void menuAccesses() throws InterruptedException, IOException {
Selenide.open("Мой сайт");
List<Payment> payments = DataBase.payment();
String[] permission_id = {"4", "3"};
Account account = null;
Map<String, Integer> expected = null;
SoftAssertions softAsserts = null;
for (var i = 0; i < permission_id.length; i++) {
Map<String, List<Account>> auth1 = MapDB.storage("");
String permissionId = permission_id[i];
Allure.step("PermissionId: " + permissionId);
List<Account> accountId = auth1.get(permissionId);
for (var j = 0; j < accountId.size(); j++) {
account = accountId.get(j);
String username = account.getUsername();
String password = account.getPassword();
Allure.step("AccountId: " + account.getAccounId());
// expected = DefaultMapPayment.getDefaultMap();
// expected = DefaultMapPayment.fillMenuByPermissionId(permissionId, expected);
Login_page.setLogin(username)
.setPassword(password)
.clickSubmit();
String token = executeJavaScript("return localStorage.getItem('token');");
System.out.println(token);
for (var v = 0; v < payments.size(); v++) {
Payment payment = payments.get(v);
Allure.step("PaymentId: " + payment.getId());
int id = payment.getId();
System.out.println(id);
Set<Cookie> cookies = Selenide.getWebDriver().manage().getCookies();
for (Cookie cookie : cookies) {
if (cookie.getName().equals("refresh")) {
String refreshToken = cookie.getValue();
System.out.println("Refresh Token: " + refreshToken);
}
}
JSONObject jsonArr = getReadonly("Мой сайт"+ id, token, refreshToken);
System.out.println(jsonArr);
System.out.println(jsonArr.get("readonly"));
testImplementation 'org.seleniumhq.selenium:selenium-java:3.14.0'
testImplementation 'org.seleniumhq.selenium:selenium-api:4.18.1'
testImplementation 'com.codeborne:selenide:7.2.0'
public TreeMap<String, Boolean> FillMenuByPermissionId(String permissionId, TreeMap<String, Boolean> expected) {
String[] aliases = FillMapByPermissionId().get(permissionId);
for (var i = 0; i < aliases.length; i++) {
String alias = aliases[i];
expected.put(alias, true);
System.out.println(permissionId);
}
return expected;
}
@BeforeAll
public void setUp() {
WebDriverManager.chromedriver().setup();
WebDriverManager.chromedriver().clearDriverCache().setup();
WebDriverManager.chromedriver().clearResolutionCache().setup();
ChromeOptions options = new ChromeOptions();
options.setCapability("browserVersion", "latest-1");
options.setCapability("platformName", "MacOS Catalina");
WebDriverManager wdm = WebDriverManager.chromedriver().capabilities(options);
wdm.setup();
WebDriver driver = new ChromeDriver(options);
driver = wdm.remoteAddress("https://***").create();
//
WebDriverManager.chromedriver().setup();
Configuration.browser = "chrome";
Configuration.driverManagerEnabled = true;
Configuration.browserSize = "1920x1080";
Configuration.headless = false;
}
}
Feature: smoke test #1, authorization in crm
Scenario: successful authorization
When Open login page "https://***"
And Enter value in "Login" text: "**"
And Enter value in "password" text: "***"
And Click the button "submit"
Then The main page will open "https://***"
import com.codeborne.selenide.Config;
import com.codeborne.selenide.Configuration;
import io.cucumber.java.BeforeAll;
import io.github.bonigarcia.wdm.WebDriverManager;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import static org.openqa.selenium.WebDriver.*;
abstract public class BaseTest {
@BeforeAll
public void setUp() {
WebDriverManager.chromedriver().setup();
WebDriverManager.chromedriver().clearDriverCache().setup();
WebDriverManager.chromedriver().clearResolutionCache().setup();
ChromeOptions options = new ChromeOptions();
options.setBinary("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome");
WebDriver driver = new ChromeDriver(options);
driver.get("https://***");
options.addArguments("--headless=new");
driver.close();
driver.quit();
WebDriverManager.chromedriver().setup();
Configuration.browser = "chrome";
Configuration.driverManagerEnabled = true;
Configuration.browserSize = "1920x1080";
Configuration.headless = false;
}
}
package Step;
import com.codeborne.selenide.Configuration;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
import com.codeborne.selenide.WebDriverRunner;
import io.cucumber.java.en.And;
import io.cucumber.java.en.Then;
import io.cucumber.java.en.When;
import org.openqa.selenium.By;
import org.junit.jupiter.api.Assertions;
import org.openqa.selenium.Dimension;
import static com.codeborne.selenide.Selenide.$x;
import static com.codeborne.selenide.files.DownloadActions.click;
public class MyStepdefs {
// final private SelenideElement Login = $x("//input[@name ='Login']");
// final private SelenideElement Password = $x("//input[@name ='password']");
// final private SelenideElement btnType = $x("//input[@type ='sabmit']");
@When("Open login page \"([^\"]*)\"$")
public void openLoginPage(String url) {
// Dimension dimension = new Dimension(1920, 1080);
// Selenide.open("URL");
// WebDriverRunner.getWebDriver().manage().window().setSize(dimension);
Selenide.open(url);
}
@And("Enter value in \"([^\"]*)\" text: \"([^\"]*)\"$")
public void enterValueInText(String fieldName, String fieldValue) {
String Name;
if (fieldName.equals("Login")) Name = "Login";
else Name = "password";
WebDriverRunner.getWebDriver().findElement(By.name(Name)).sendKeys(fieldName);
}
@And("Click the button \"([^\"]*)\"$")
public void clickTheButton(String btnLog) {
WebDriverRunner.getWebDriver().findElement(By.name(btnLog)).click();
}
@Then("The main page will open \"([^\"]*)\"$")
public void theMainPageWillOpen(String url2) {
String currentUrl = WebDriverRunner.getWebDriver().getCurrentUrl();
Assertions.assertEquals(currentUrl, url2);
}
}