Skip to content

Commit

Permalink
updated hamcrest to 2.1 and selenide to 5.0.1 and fixed page initiali…
Browse files Browse the repository at this point in the history
…zation issues after update
  • Loading branch information
GannaChernyshova committed Jan 9, 2019
1 parent 77b19e3 commit 06c7a5c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 24 deletions.
3 changes: 1 addition & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ apply plugin: 'nebula.source-jar'
apply plugin: 'nebula.javadoc-jar'

group = 'ru.alfabank.tests'
version = '3.5.2'

description = """light testing framework Akita"""

Expand Down Expand Up @@ -130,7 +129,7 @@ bintray {

test {
maxParallelForks = 1
ignoreFailures = true
ignoreFailures = false

jvmArgs += "-Dfile.encoding=UTF-8"
jvmArgs += "-Dbrowser=chrome"
Expand Down
22 changes: 14 additions & 8 deletions src/main/java/ru/alfabank/alfatest/cucumber/api/Pages.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* Copyright 2017 Alfa Laboratory
* <p>
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* <p>
*
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand All @@ -15,7 +15,6 @@
*/
package ru.alfabank.alfatest.cucumber.api;

import com.codeborne.selenide.ElementsContainer;
import com.codeborne.selenide.Selenide;
import com.google.common.collect.Maps;
import lombok.SneakyThrows;
Expand Down Expand Up @@ -74,18 +73,18 @@ public static <T extends AkitaPage> void withPage(Class<T> clazz, boolean checkI
* Получение страницы из "pages" по имени
*/
public AkitaPage get(String pageName) {
return Selenide.page(getPageMapInstanceInternal().get(pageName)).initialize();
return Selenide.page(getPageFromPagesByName(pageName)).initialize();
}

/**
* Получение страницы по классу
*/
@SuppressWarnings("unchecked")
public <T extends AkitaPage> T get(Class<T> clazz, String name) {
AkitaPage page = Selenide.page(getPageMapInstanceInternal().get(name)).initialize();
public <T extends AkitaPage> T get(Class<T> clazz, String pageName) {
AkitaPage page = Selenide.page(Selenide.page(getPageFromPagesByName(pageName))).initialize();

if (!clazz.isInstance(page)) {
throw new IllegalStateException(name + " page is not a instance of " + clazz + ". Named page is a " + page);
throw new IllegalStateException(pageName + " page is not a instance of " + clazz + ". Named page is a " + page);
}
return (T) page;
}
Expand All @@ -94,6 +93,13 @@ private Map<String, AkitaPage> getPageMapInstanceInternal() {
return pages;
}

private AkitaPage getPageFromPagesByName(String pageName) throws IllegalArgumentException {
AkitaPage page = getPageMapInstanceInternal().get(pageName);
if (page == null)
throw new IllegalArgumentException(pageName + " page is not declared in a list of available pages");
return page;
}

/**
* Добавление инстанциированной страницы в "pages" с проверкой на NULL
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package ru.alfabank.tests.core.helpers;

import com.google.common.base.Strings;
Expand Down
1 change: 0 additions & 1 deletion src/test/java/ru/alfabank/other/AkitaScenarioTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ public void prepare() {
Scenario scenario = new StubScenario();
AkitaPage akitaPageMock = mock(AkitaPage.class);
akitaScenario.setEnvironment(new AkitaEnvironment(scenario));
akitaScenario.getPages().put("Title", akitaPageMock);
}

@Test(expected = IllegalArgumentException.class)
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/ru/alfabank/other/PagesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ public void putNegative() {
pages.put("Test", nullPage);
}

@Test
@Test(expected = IllegalArgumentException.class)
public void getNegative() {
assertThat(pages.get("WRONG_KEY"), is(nullValue()));
pages.get("WRONG_KEY_TO_GET_PAGE");
}
}
20 changes: 10 additions & 10 deletions src/test/java/ru/alfabank/steps/ApiStepsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,18 +118,18 @@ public void sendHttpRequestFromFileWithVarsPost() throws java.lang.Exception {
String bodyFileName = "/src/test/resources/bodyWithParams.json";

stubFor(post(urlEqualTo("/post/resource"))
.withRequestBody(WireMock.equalTo(body))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody("TEST_BODY")));
.withRequestBody(WireMock.equalTo(body))
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/xml")
.withBody("TEST_BODY")));

List<RequestParam> params = Collections.singletonList(
RequestParam.builder()
.name("body")
.type(RequestParamType.BODY)
.value(bodyFileName)
.build());
RequestParam.builder()
.name("body")
.type(RequestParamType.BODY)
.value(bodyFileName)
.build());
api.sendHttpRequestSaveResponse("POST", "/post/resource", "RESPONSE_POST_BODY", params);
assertThat(akitaScenario.getVar("RESPONSE_POST_BODY"), equalTo("TEST_BODY"));
}
Expand Down

0 comments on commit 06c7a5c

Please sign in to comment.