This repository has been archived by the owner on Jan 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathOsNativeTest.java
102 lines (89 loc) · 3.55 KB
/
OsNativeTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package org.sakuli.example.uiOnly;
import org.apache.commons.lang.StringUtils;
import org.sakuli.actions.environment.Application;
import org.sakuli.actions.environment.Environment;
import org.sakuli.actions.logging.Logger;
import org.sakuli.actions.screenbased.Region;
import org.sakuli.example.AbstractSakuliSeTest;
import org.sakuli.selenium.actions.testcase.SeTestCaseAction;
import org.sakuli.selenium.testng.SakuliSeTest;
import org.sakuli.selenium.testng.SakuliTestCase;
import org.sakuli.utils.ResourceHelper;
import org.sikuli.script.Key;
import org.testng.Assert;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;
import java.nio.file.Path;
/**
* @author tschneck
* Date: 4/27/17
*/
@Listeners(SakuliSeTest.class)
public class OsNativeTest {
private Application gedit;
private Region screen;
private Environment env;
private SeTestCaseAction tc;
@BeforeMethod
public void setUp() throws Exception {
gedit = new Application("gedit");
screen = new Region();
env = new Environment();
tc = new SeTestCaseAction();
}
@AfterMethod
public void tearDown() throws Exception {
if (gedit != null) {
gedit.closeApp();
}
}
private void checkEnvironment() throws Exception {
if (StringUtils.isNotBlank(env.getEnv("VNC_PORT"))) {
Logger.logInfo("----- Load XFCE screenshots");
tc.addImagePaths(ResourceHelper.getClasspathResource(OsNativeTest.class, "xfce-env", "image folder for XFCE not found"));
}
if (AbstractSakuliSeTest.isTargetEnvironment("LinuxMint")) {
Logger.logInfo("----- Load LinuxMint screenshots");
tc.addImagePaths(ResourceHelper.getClasspathResource(OsNativeTest.class, "mint", "image folder for LinuxMint not found"));
}
}
@Test
@SakuliTestCase(warningTime = 50, criticalTime = 60)
public void testEditorOpensReadMe() throws Exception {
checkEnvironment();
gedit.open();
// shows fluent API and how sub regions can be used
final Region geditAnchor = screen.waitForImage("gedit", 5)
.highlight()
.click();
// move focus mouse pointer
geditAnchor.below(100).highlight().mouseMove();
// use already known region
final Region otherDocument = geditAnchor
// create larger search region
.below(200).setW(300).highlight()
.waitForImage("search", 20).highlight()
.click()
.type("Hello Guys!")
// base region of "search" button grows 400px
.grow(400, 400).highlight(2)
.find("other_documents").highlight();
otherDocument.click();
//open readme file
final Path readMeFile = ResourceHelper.getClasspathResource(this.getClass(), "README.md", "resolve test file 'README.md'");
screen.waitForImage("cancel_button.png", 5).highlight()
.left(50).highlight().click()
.type(readMeFile.toAbsolutePath().normalize().toString())
.type(Key.ENTER)
.sleep(2);
gedit.focus();
//mark all and copy it to the clipboard
env.type("a", Key.CTRL).sleep(1).type("c", Key.CTRL);
final String clipboard = env.getClipboard();
//assert the readme content
System.out.println(clipboard);
Assert.assertTrue(clipboard.contains("Sakuli Selenium"));
}
}