Selenide+Spock, one class per page - navigating to a page seems to open a new window
I am new to both Spock and Selenide, so I apologize if it's smth obvious, I was not able to google an answer though.
I am trying to write a simple test for a Jenkins site (test machine only has access to local resources, so I cannot give a Google example, but should be about the same).
It opens the site, inputs a word in the search field, presses Enter, and then checks the search results for a match.
There are three classes:
1. JenkinsTest - where the test is written in Spock notation.
2. JenkinsPage - responsible for putting test in the search field and pressing Enter.
3. SearchResultsPage - responsible for checking the search results.
The problem is SearchResultsPage seems to open its own browser window instead of looking at the existing one. So when I look at $("body") from this class, I get "This is the initial start page for the WebDriver server.".
Is there a way to have a class per page, and still have them all hooked up to the same browser window? Currently JenkinsPage uses the same window that is originally opened, but SearchResultsPage opens a new browser window that is closed a second later.
JenkinsTest.groovy:
package sandbox-test;
import org.junit.Test;
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.open;
import org.openqa.selenium.chrome.ChromeOptions;
import spock.lang.*
class JenkinsTest extends spock.lang.Specification {
public void "Can search for assure"() {
setup:
open("http://local.hostname.com/jenkins/")
when:
new JenkinsPage().searchFor("test")
SearchResultsPage results = new SearchResultsPage()
then:
results.getResults() == "testresults"
}
}
JenkinsPage.groovy:
package sandbox-test;
import org.openqa.selenium.By;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;
class JenkinsPage {
def searchFor(String text) {
$(By.name("q")).val(text).pressEnter()
}
}
SearchResultsPage.groovy:
package sandbox-test;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
class SearchResultsPage {
public ElementsCollection getResults() {
return $("body")
}
public SelenideElement getResult(int index) {
return $("#main-panel li", index)
}
}
internet-explorer spock selenide
add a comment |
I am new to both Spock and Selenide, so I apologize if it's smth obvious, I was not able to google an answer though.
I am trying to write a simple test for a Jenkins site (test machine only has access to local resources, so I cannot give a Google example, but should be about the same).
It opens the site, inputs a word in the search field, presses Enter, and then checks the search results for a match.
There are three classes:
1. JenkinsTest - where the test is written in Spock notation.
2. JenkinsPage - responsible for putting test in the search field and pressing Enter.
3. SearchResultsPage - responsible for checking the search results.
The problem is SearchResultsPage seems to open its own browser window instead of looking at the existing one. So when I look at $("body") from this class, I get "This is the initial start page for the WebDriver server.".
Is there a way to have a class per page, and still have them all hooked up to the same browser window? Currently JenkinsPage uses the same window that is originally opened, but SearchResultsPage opens a new browser window that is closed a second later.
JenkinsTest.groovy:
package sandbox-test;
import org.junit.Test;
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.open;
import org.openqa.selenium.chrome.ChromeOptions;
import spock.lang.*
class JenkinsTest extends spock.lang.Specification {
public void "Can search for assure"() {
setup:
open("http://local.hostname.com/jenkins/")
when:
new JenkinsPage().searchFor("test")
SearchResultsPage results = new SearchResultsPage()
then:
results.getResults() == "testresults"
}
}
JenkinsPage.groovy:
package sandbox-test;
import org.openqa.selenium.By;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;
class JenkinsPage {
def searchFor(String text) {
$(By.name("q")).val(text).pressEnter()
}
}
SearchResultsPage.groovy:
package sandbox-test;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
class SearchResultsPage {
public ElementsCollection getResults() {
return $("body")
}
public SelenideElement getResult(int index) {
return $("#main-panel li", index)
}
}
internet-explorer spock selenide
add a comment |
I am new to both Spock and Selenide, so I apologize if it's smth obvious, I was not able to google an answer though.
I am trying to write a simple test for a Jenkins site (test machine only has access to local resources, so I cannot give a Google example, but should be about the same).
It opens the site, inputs a word in the search field, presses Enter, and then checks the search results for a match.
There are three classes:
1. JenkinsTest - where the test is written in Spock notation.
2. JenkinsPage - responsible for putting test in the search field and pressing Enter.
3. SearchResultsPage - responsible for checking the search results.
The problem is SearchResultsPage seems to open its own browser window instead of looking at the existing one. So when I look at $("body") from this class, I get "This is the initial start page for the WebDriver server.".
Is there a way to have a class per page, and still have them all hooked up to the same browser window? Currently JenkinsPage uses the same window that is originally opened, but SearchResultsPage opens a new browser window that is closed a second later.
JenkinsTest.groovy:
package sandbox-test;
import org.junit.Test;
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.open;
import org.openqa.selenium.chrome.ChromeOptions;
import spock.lang.*
class JenkinsTest extends spock.lang.Specification {
public void "Can search for assure"() {
setup:
open("http://local.hostname.com/jenkins/")
when:
new JenkinsPage().searchFor("test")
SearchResultsPage results = new SearchResultsPage()
then:
results.getResults() == "testresults"
}
}
JenkinsPage.groovy:
package sandbox-test;
import org.openqa.selenium.By;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;
class JenkinsPage {
def searchFor(String text) {
$(By.name("q")).val(text).pressEnter()
}
}
SearchResultsPage.groovy:
package sandbox-test;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
class SearchResultsPage {
public ElementsCollection getResults() {
return $("body")
}
public SelenideElement getResult(int index) {
return $("#main-panel li", index)
}
}
internet-explorer spock selenide
I am new to both Spock and Selenide, so I apologize if it's smth obvious, I was not able to google an answer though.
I am trying to write a simple test for a Jenkins site (test machine only has access to local resources, so I cannot give a Google example, but should be about the same).
It opens the site, inputs a word in the search field, presses Enter, and then checks the search results for a match.
There are three classes:
1. JenkinsTest - where the test is written in Spock notation.
2. JenkinsPage - responsible for putting test in the search field and pressing Enter.
3. SearchResultsPage - responsible for checking the search results.
The problem is SearchResultsPage seems to open its own browser window instead of looking at the existing one. So when I look at $("body") from this class, I get "This is the initial start page for the WebDriver server.".
Is there a way to have a class per page, and still have them all hooked up to the same browser window? Currently JenkinsPage uses the same window that is originally opened, but SearchResultsPage opens a new browser window that is closed a second later.
JenkinsTest.groovy:
package sandbox-test;
import org.junit.Test;
import static com.codeborne.selenide.CollectionCondition.sizeGreaterThan;
import static com.codeborne.selenide.Condition.text;
import static com.codeborne.selenide.Selenide.open;
import org.openqa.selenium.chrome.ChromeOptions;
import spock.lang.*
class JenkinsTest extends spock.lang.Specification {
public void "Can search for assure"() {
setup:
open("http://local.hostname.com/jenkins/")
when:
new JenkinsPage().searchFor("test")
SearchResultsPage results = new SearchResultsPage()
then:
results.getResults() == "testresults"
}
}
JenkinsPage.groovy:
package sandbox-test;
import org.openqa.selenium.By;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.page;
class JenkinsPage {
def searchFor(String text) {
$(By.name("q")).val(text).pressEnter()
}
}
SearchResultsPage.groovy:
package sandbox-test;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.SelenideElement;
import static com.codeborne.selenide.Selenide.$;
import static com.codeborne.selenide.Selenide.$$;
class SearchResultsPage {
public ElementsCollection getResults() {
return $("body")
}
public SelenideElement getResult(int index) {
return $("#main-panel li", index)
}
}
internet-explorer spock selenide
internet-explorer spock selenide
asked Nov 20 '18 at 1:30
hali17hali17
11
11
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
Got it working in the end.
In JenkinsTest used this line for a "then" block:
results.getResult().getText().contains("assure-integration-ofm")
results.getResults().first().text == "assure-integration-ofm"
And rewrote SearchResultsPage.groovy as:
package sandbox-test;
import org.openqa.selenium.By;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
class SearchResultsPage {
public ElementsCollection getResults() {
ElementsCollection list = Selenide.$$(By.xpath("//ol/li"))
return list
}
public SelenideElement getResult() {
SelenideElement list = Selenide.$(By.xpath("//ol"))
return list
}
}
I still don't understand why didn't the original work, as I took it from the Selenide's examples and changed only slightly. But oh well.
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384987%2fselenidespock-one-class-per-page-navigating-to-a-page-seems-to-open-a-new-wi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Got it working in the end.
In JenkinsTest used this line for a "then" block:
results.getResult().getText().contains("assure-integration-ofm")
results.getResults().first().text == "assure-integration-ofm"
And rewrote SearchResultsPage.groovy as:
package sandbox-test;
import org.openqa.selenium.By;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
class SearchResultsPage {
public ElementsCollection getResults() {
ElementsCollection list = Selenide.$$(By.xpath("//ol/li"))
return list
}
public SelenideElement getResult() {
SelenideElement list = Selenide.$(By.xpath("//ol"))
return list
}
}
I still don't understand why didn't the original work, as I took it from the Selenide's examples and changed only slightly. But oh well.
add a comment |
Got it working in the end.
In JenkinsTest used this line for a "then" block:
results.getResult().getText().contains("assure-integration-ofm")
results.getResults().first().text == "assure-integration-ofm"
And rewrote SearchResultsPage.groovy as:
package sandbox-test;
import org.openqa.selenium.By;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
class SearchResultsPage {
public ElementsCollection getResults() {
ElementsCollection list = Selenide.$$(By.xpath("//ol/li"))
return list
}
public SelenideElement getResult() {
SelenideElement list = Selenide.$(By.xpath("//ol"))
return list
}
}
I still don't understand why didn't the original work, as I took it from the Selenide's examples and changed only slightly. But oh well.
add a comment |
Got it working in the end.
In JenkinsTest used this line for a "then" block:
results.getResult().getText().contains("assure-integration-ofm")
results.getResults().first().text == "assure-integration-ofm"
And rewrote SearchResultsPage.groovy as:
package sandbox-test;
import org.openqa.selenium.By;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
class SearchResultsPage {
public ElementsCollection getResults() {
ElementsCollection list = Selenide.$$(By.xpath("//ol/li"))
return list
}
public SelenideElement getResult() {
SelenideElement list = Selenide.$(By.xpath("//ol"))
return list
}
}
I still don't understand why didn't the original work, as I took it from the Selenide's examples and changed only slightly. But oh well.
Got it working in the end.
In JenkinsTest used this line for a "then" block:
results.getResult().getText().contains("assure-integration-ofm")
results.getResults().first().text == "assure-integration-ofm"
And rewrote SearchResultsPage.groovy as:
package sandbox-test;
import org.openqa.selenium.By;
import com.codeborne.selenide.Condition;
import com.codeborne.selenide.ElementsCollection;
import com.codeborne.selenide.Selenide;
import com.codeborne.selenide.SelenideElement;
class SearchResultsPage {
public ElementsCollection getResults() {
ElementsCollection list = Selenide.$$(By.xpath("//ol/li"))
return list
}
public SelenideElement getResult() {
SelenideElement list = Selenide.$(By.xpath("//ol"))
return list
}
}
I still don't understand why didn't the original work, as I took it from the Selenide's examples and changed only slightly. But oh well.
answered Nov 20 '18 at 19:45
hali17hali17
11
11
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53384987%2fselenidespock-one-class-per-page-navigating-to-a-page-seems-to-open-a-new-wi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown