#120 parse kias page
This commit is contained in:
parent
bab621677e
commit
c21739bfc6
67
src/test/java/IndexKiasTest.java
Normal file
67
src/test/java/IndexKiasTest.java
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.Iterables;
|
||||||
|
import core.PageObject;
|
||||||
|
import core.TestTemplate;
|
||||||
|
import grant.KiasPage;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.openqa.selenium.WebElement;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.context.SpringBootTest;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import ru.ulstu.NgTrackerApplication;
|
||||||
|
import ru.ulstu.deadline.model.Deadline;
|
||||||
|
import ru.ulstu.grant.model.Grant;
|
||||||
|
import ru.ulstu.grant.model.GrantDto;
|
||||||
|
import ru.ulstu.user.repository.UserRepository;
|
||||||
|
|
||||||
|
import java.text.ParseException;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@SpringBootTest(classes = NgTrackerApplication.class, webEnvironment = SpringBootTest.WebEnvironment.DEFINED_PORT)
|
||||||
|
public class IndexKiasTest extends TestTemplate {
|
||||||
|
private final static String BASE_URL = "https://www.rfbr.ru/rffi/ru/contest_search?CONTEST_STATUS_ID=%s&CONTEST_TYPE=%s&CONTEST_YEAR=%s";
|
||||||
|
private final static String CONTEST_STATUS_ID = "1";
|
||||||
|
private final static String CONTEST_TYPE = "-1";
|
||||||
|
private final static String CONTEST_YEAR = "2019";
|
||||||
|
|
||||||
|
private final Map<PageObject, List<String>> navigationHolder = ImmutableMap.of(
|
||||||
|
new KiasPage(), Arrays.asList("Поиск по конкурсам",
|
||||||
|
String.format(BASE_URL, CONTEST_STATUS_ID, CONTEST_TYPE, CONTEST_YEAR))
|
||||||
|
);
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
UserRepository userRepository;
|
||||||
|
|
||||||
|
public List<GrantDto> getNewGrantsDto() throws ParseException {
|
||||||
|
Map.Entry<PageObject, List<String>> page = Iterables.get(navigationHolder.entrySet(), 0);
|
||||||
|
getContext().goTo(page.getValue().get(1));
|
||||||
|
KiasPage kiasPage = (KiasPage) getContext().initPage(page.getKey());
|
||||||
|
List<WebElement> kiasGrants = new ArrayList<>();
|
||||||
|
List<GrantDto> newGrants = new ArrayList<>();
|
||||||
|
do {
|
||||||
|
kiasGrants.addAll(kiasPage.getPageOfGrants());
|
||||||
|
for (WebElement grant : kiasGrants) {
|
||||||
|
GrantDto grantDto = new GrantDto();
|
||||||
|
grantDto.setTitle(kiasPage.getGrantTitle(grant));
|
||||||
|
String deadlineDate = kiasPage.getFirstDeadline(grant); //10.06.2019 23:59
|
||||||
|
SimpleDateFormat formatter = new SimpleDateFormat("dd.MM.yyyy HH:mm");
|
||||||
|
Date date = formatter.parse(deadlineDate);
|
||||||
|
Deadline deadline = new Deadline(date, "Окончание приёма заявок");
|
||||||
|
grantDto.setDeadlines(Arrays.asList(deadline));
|
||||||
|
grantDto.setLeaderId(userRepository.findOneByLoginIgnoreCase("admin").getId());
|
||||||
|
grantDto.setStatus(Grant.GrantStatus.LOADED_FROM_KIAS);
|
||||||
|
newGrants.add(grantDto);
|
||||||
|
}
|
||||||
|
kiasGrants.clear();
|
||||||
|
}
|
||||||
|
while (kiasPage.checkPagination()); //проверка существования следующей страницы с грантами
|
||||||
|
|
||||||
|
return newGrants;
|
||||||
|
}
|
||||||
|
}
|
@ -4,7 +4,9 @@ import core.PageObject;
|
|||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
|
|
||||||
public class KiasPage extends PageObject {
|
public class KiasPage extends PageObject {
|
||||||
@Override
|
@Override
|
||||||
@ -13,9 +15,31 @@ public class KiasPage extends PageObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<WebElement> getGrants() {
|
public List<WebElement> getGrants() {
|
||||||
WebElement listContest = driver.findElement(By.tagName("tBody"));
|
List<WebElement> grants = new ArrayList<>();
|
||||||
return listContest.findElements(By.cssSelector("tr.tr"));
|
do {
|
||||||
|
grants.addAll(getPageOfGrants());
|
||||||
|
}
|
||||||
|
while (checkPagination());
|
||||||
|
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<WebElement> getPageOfGrants() {
|
||||||
|
WebElement listContest = driver.findElement(By.tagName("tBody"));
|
||||||
|
List<WebElement> grants = listContest.findElements(By.cssSelector("tr.tr"));
|
||||||
|
return grants;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkPagination() {
|
||||||
|
try {
|
||||||
|
if (driver.findElements(By.id("js-ctrlNext")).size() > 0) {
|
||||||
|
driver.findElement(By.id("js-ctrlNext")).click();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
} catch (NoSuchElementException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getGrantTitle(WebElement grant) {
|
public String getGrantTitle(WebElement grant) {
|
||||||
|
Loading…
Reference in New Issue
Block a user