Skip to content

Commit

Permalink
Update syntax for "When I go to the relative URL '$relativeURL'" step
Browse files Browse the repository at this point in the history
  • Loading branch information
vkepin committed Jan 10, 2023
1 parent b147549 commit 77d5123
Show file tree
Hide file tree
Showing 5 changed files with 91 additions and 12 deletions.
50 changes: 50 additions & 0 deletions docs/modules/plugins/partials/plugin-web-app-steps.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,56 @@
:popup-alert: https://www.w3schools.com/js/js_popup.asp
:close-spec: https://w3c.github.io/webdriver/webdriver-spec.html#close-window[close]

=== Steps opening pages

==== Open page with relative URL

Navigates the browser to the specific path in the current host defined in the _relative URL_ step parameter.

A relative URL can point to a file within a web site (like `about.html` or `/products`).

- If the parameter starts with '/' char, navigation will be performed from the root of the host, see examples below.
- If the parameter starts without '/' char or with './', navigation will be performed from the current path directory.

.Examples
|===
|Current page |Relative URL parameter|Opened page

|https://mysite.com
|about.html
|https://mysite.com/about.html

|https://mysite.com
|/products/new
|https://mysite.com/products/new

|https://mysite.com/path/foo
|stats
|https://mysite.com/path/foo/stats

|https://mysite.com/path/foo
|./docs/info.html
|https://mysite.com/path/foo/docs/info.html

|https://mysite.com/path/foo
|/documents
|https://mysite.com/documents
|===

[source,gherkin]
----
When I go to relative URL `$relativeURL`
----

* `relativeURL` - A string value of the relative URL

. Open main application page and then navigate to '/products/new' page on the application host
[source,gherkin]
----
Given I am on main application page
When I go to relative URL `/products/new`
----

=== Clicking steps

==== Click on element
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -236,9 +236,24 @@ public void isPageScrolledToAnElement(Locator locator)
}

/**
* Goes to the relative URL
* Navigates the browser to the specific path in the current host
* defined in the <i>relative URL</i> step variable
* <br>
* A <b>relative URL</b> - points to a file within a web site (like <i>'about.html'</i> or <i>'/products'</i>)<br>
* A <b>relative URL</b> - points to a file within a web site
* (like <i>'about.html'</i> or <i>'/products'</i>)<br>
* <p>
* <table border="1">
* <caption>Examples:</caption>
* <tr>
* <td>Current page</td><td>Relative URL parameter</td><td>Opened page</td>
* </tr>
* <tr>
* <td>https://mysite.com/path/foo</td><td>stats</td><td>https://mysite.com/path/stats</td>
* </tr>
* <tr>
* <td>https://mysite.com/path/foo</td><td>/documents</td><td>https://mysite.com/documents</td>
* </tr>
* </table>
* <p>
* Actions performed at this step:
* <ul>
Expand All @@ -248,8 +263,8 @@ public void isPageScrolledToAnElement(Locator locator)
* <p>
* @param relativeURL A string value of the relative URL
*/
@When("I go to the relative URL '$relativeURL'")
public void iGoTo(String relativeURL)
@When("I go to relative URL `$relativeURL`")
public void openRelativeUrl(String relativeURL)
{
setContextSteps.switchingToDefault();
URI currentURI = UriUtils.createUri(getWebDriver().getCurrentUrl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,7 @@ When I wait until element located by `<locator>` contains text `<text>'
Composite: Then element located '$locator' disappears in '$timeout'
!-- WARNING: The step "Then element located '$locator' disappears in '$timeout'" is deprecated and will be removed in VIVIDUS 0.6.0
Then element located by `<locator>` disappears in `<timeout>`

Composite: When I go to the relative URL '$relativeURL'
!-- WARNING: The step "When I go to the relative URL '$relativeURL'" is deprecated and will be removed in VIVIDUS 0.7.0
When I go to relative URL `<relativeURL>`
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2019-2022 the original author or authors.
* Copyright 2019-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -224,32 +224,32 @@ void testIsElementAtTheTopElementNull()
// @formatter:on
// CHECKSTYLE:ON
})
void testIGoTo(String baseUrl, String toGo, String expected)
void testOpenRelativeUrl(String baseUrl, String toGo, String expected)
{
when(webDriverProvider.get()).thenReturn(driver);
when(driver.getCurrentUrl()).thenReturn(baseUrl);
pageSteps.iGoTo(toGo);
pageSteps.openRelativeUrl(toGo);
verify(setContextSteps).switchingToDefault();
verify(navigateActions).navigateTo(expected);
}

@Test
void testIGoToIOS()
void testOpenRelativeUrlIOS()
{
when(webDriverProvider.get()).thenReturn(driver);
when(driver.getCurrentUrl()).thenReturn(URL);
when(webDriverManager.isIOS()).thenReturn(true);
pageSteps.iGoTo(RELATIVE_URL);
pageSteps.openRelativeUrl(RELATIVE_URL);
verify(waitActions).waitForPageLoad();
}

@Test
void testIGoToNotIOS()
void testOpenRelativeUrlNotIOS()
{
when(webDriverProvider.get()).thenReturn(driver);
when(driver.getCurrentUrl()).thenReturn(URL);
when(webDriverManager.isIOS()).thenReturn(false);
pageSteps.iGoTo(RELATIVE_URL);
pageSteps.openRelativeUrl(RELATIVE_URL);
verifyNoInteractions(waitActions);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,13 @@ Examples:
|DNS_LOOKUP_TIME |
|DOM_CONTENT_LOAD_TIME|
|PAGE_LOAD_TIME |

Scenario: Verify step: When I go to relative URL `$relativeURL`
Given I am on a page with the URL '${vividus-test-site-url}'
When I go to relative URL `/elementState.html`
Then number of elements found by `id(element-to-hide)` is equal to `1`

Scenario: Verify deprecated step: When I go to the relative URL '$relativeURL'
Given I am on a page with the URL '${vividus-test-site-url}'
When I go to the relative URL '/elementState.html'
Then number of elements found by `id(element-to-hide)` is equal to `1`

0 comments on commit 77d5123

Please sign in to comment.