Skip to content

Commit 5b4680f

Browse files
author
David Haeffner
committed
Added code export e2e test coverage for nested tests which open new windows
1 parent 30d9161 commit 5b4680f

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

packages/code-export-java-junit/__test__/src/__snapshots__/index.spec.js.snap

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,69 @@ public class ControlflowTest {
155155
"
156156
`;
157157

158+
exports[`Code Export Java Selenium should export a suite to JUnit code with commands that open a new window inside of a reused test method 1`] = `
159+
"// Generated by Selenium IDE
160+
import org.junit.Test;
161+
import org.junit.Before;
162+
import org.junit.After;
163+
import static org.junit.Assert.*;
164+
import static org.hamcrest.CoreMatchers.is;
165+
import static org.hamcrest.core.IsNot.not;
166+
import org.openqa.selenium.By;
167+
import org.openqa.selenium.WebDriver;
168+
import org.openqa.selenium.firefox.FirefoxDriver;
169+
import org.openqa.selenium.Dimension;
170+
import org.openqa.selenium.WebElement;
171+
import org.openqa.selenium.interactions.Actions;
172+
import org.openqa.selenium.support.ui.ExpectedConditions;
173+
import org.openqa.selenium.support.ui.WebDriverWait;
174+
import org.openqa.selenium.JavascriptExecutor;
175+
import org.openqa.selenium.Alert;
176+
import org.openqa.selenium.Keys;
177+
import java.util.*;
178+
public class DefaultSuiteTest {
179+
private WebDriver driver;
180+
private Map<String, Object> vars;
181+
JavascriptExecutor js;
182+
@Before
183+
public void setUp() {
184+
driver = new FirefoxDriver();
185+
js = (JavascriptExecutor) driver;
186+
vars = new HashMap<String, Object>();
187+
}
188+
@After
189+
public void tearDown() {
190+
driver.quit();
191+
}
192+
public String waitForWindow(int timeout) {
193+
try {
194+
Thread.sleep(timeout);
195+
} catch (InterruptedException e) {
196+
e.printStackTrace();
197+
}
198+
Set<String> whNow = driver.getWindowHandles();
199+
Set<String> whThen = (Set<String>) vars.get(\\"window_handles\\");
200+
if (whNow.size() > whThen.size()) {
201+
whNow.removeAll(whThen);
202+
}
203+
return whNow.iterator().next();
204+
}
205+
public void selectwindow() {
206+
driver.get(\\"http://the-internet.herokuapp.com/windows\\");
207+
vars.put(\\"window_handles\\", driver.getWindowHandles());
208+
driver.findElement(By.linkText(\\"Click Here\\")).click();
209+
vars.put(\\"win9425\\", waitForWindow(2000));
210+
driver.switchTo().window(vars.get(\\"win9425\\").toString());
211+
assertThat(driver.getTitle(), is(\\"New Window\\"));
212+
}
213+
@Test
214+
public void reuse() {
215+
selectwindow();
216+
}
217+
}
218+
"
219+
`;
220+
158221
exports[`Code Export Java Selenium should export a suite to JUnit code with reused test method 1`] = `
159222
"// Generated by Selenium IDE
160223
import org.junit.Test;

packages/code-export-java-junit/__test__/src/index.spec.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,16 @@ describe('Code Export Java Selenium', () => {
8787
expect(results.body).toBeDefined()
8888
expect(results.body).toMatchSnapshot()
8989
})
90+
it('should export a suite to JUnit code with commands that open a new window inside of a reused test method', async () => {
91+
const project = normalizeProject(readFile('nested-select-window.side'))
92+
const results = await emitSuite({
93+
baseUrl: project.url,
94+
suite: project.suites[0],
95+
tests: project.tests,
96+
})
97+
expect(results.body).toBeDefined()
98+
expect(results.body).toMatchSnapshot()
99+
})
90100
})
91101

92102
function normalizeProject(project) {
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
{
2+
"id": "212f1831-7949-459d-a0ba-daf472ed3e53",
3+
"version": "2.0",
4+
"name": "nested select window",
5+
"url": "http://the-internet.herokuapp.com",
6+
"tests": [{
7+
"id": "3147925e-12c9-4b8e-aac1-90f4f13e8404",
8+
"name": "reuse",
9+
"commands": [{
10+
"id": "4c01a3a4-9547-4233-8d45-92496d6a6307",
11+
"comment": "",
12+
"command": "run",
13+
"target": "select window",
14+
"targets": [],
15+
"value": ""
16+
}]
17+
}, {
18+
"id": "b85e7efd-0f6f-4626-b815-24ddc3f8fbd1",
19+
"name": "select window",
20+
"commands": [{
21+
"id": "6b96f8fe-141f-4e2d-8675-1698ad725c79",
22+
"comment": "",
23+
"command": "open",
24+
"target": "/windows",
25+
"targets": [],
26+
"value": ""
27+
}, {
28+
"id": "ee184b06-b880-4fed-ae23-b924f16284d9",
29+
"comment": "",
30+
"command": "click",
31+
"target": "linkText=Click Here",
32+
"targets": [
33+
["linkText=Click Here", "linkText"],
34+
["css=a:nth-child(2)", "css:finder"],
35+
["xpath=//a[contains(text(),'Click Here')]", "xpath:link"],
36+
["xpath=//div[@id='content']/div/a", "xpath:idRelative"],
37+
["xpath=//a[contains(@href, '/windows/new')]", "xpath:href"],
38+
["xpath=//div/div/a", "xpath:position"],
39+
["xpath=//a[contains(.,'Click Here')]", "xpath:innerText"]
40+
],
41+
"value": "",
42+
"opensWindow": true,
43+
"windowHandleName": "win9425",
44+
"windowTimeout": 2000
45+
}, {
46+
"id": "f08b16ff-85df-4bcc-82f7-e8861bdb5eb2",
47+
"comment": "",
48+
"command": "selectWindow",
49+
"target": "handle=${win9425}",
50+
"targets": [],
51+
"value": ""
52+
}, {
53+
"id": "c3319e1c-cd44-4213-a7f5-e780069cd1f0",
54+
"comment": "",
55+
"command": "assertTitle",
56+
"target": "New Window",
57+
"targets": [],
58+
"value": ""
59+
}]
60+
}],
61+
"suites": [{
62+
"id": "696ca955-3e12-4f0a-a4ef-369b647fd7eb",
63+
"name": "Default Suite",
64+
"persistSession": false,
65+
"parallel": false,
66+
"timeout": 300,
67+
"tests": ["3147925e-12c9-4b8e-aac1-90f4f13e8404"]
68+
}],
69+
"urls": ["http://the-internet.herokuapp.com/"],
70+
"plugins": []
71+
}

0 commit comments

Comments
 (0)