1
+ package com .example .webdriver ;
2
+ import org .openqa .selenium .By ;
3
+ import org .openqa .selenium .WebDriver ;
4
+ import org .openqa .selenium .WebElement ;
5
+ import org .openqa .selenium .support .FindBy ;
6
+ import org .openqa .selenium .support .PageFactory ;
7
+
8
+ import static junit .framework .Assert .assertTrue ;
9
+
10
+ public class EditIssue extends LoadableComponent <EditIssue > {
11
+
12
+ private final WebDriver driver ;
13
+
14
+ // By default the PageFactory will locate elements with the same name or id
15
+ // as the field. Since the issue_title element has an id attribute of "issue_title"
16
+ // we don't need any additional annotations.
17
+ private WebElement issue_title ;
18
+
19
+ // But we'd prefer a different name in our code than "issue_body", so we use the
20
+ // FindBy annotation to tell the PageFactory how to locate the element.
21
+ @ FindBy (id = "issue_body" ) private WebElement body ;
22
+
23
+ public EditIssue (WebDriver driver ) {
24
+ this .driver = driver ;
25
+
26
+ // This call sets the WebElement fields.
27
+ PageFactory .initElements (driver , this );
28
+ }
29
+
30
+ @ Override
31
+ protected void load () {
32
+ driver .get ("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+" );
33
+ }
34
+
35
+ @ Override
36
+ protected void isLoaded () throws Error {
37
+ String url = driver .getCurrentUrl ();
38
+ assertTrue ("Not on the issue entry page: " + url , url .endsWith ("/new" ));
39
+ }
40
+
41
+ public void setHowToReproduce (String howToReproduce ) {
42
+ WebElement field = driver .findElement (By .id ("issue_form_repro-command" ));
43
+ clearAndType (field , howToReproduce );
44
+ }
45
+
46
+ public void setLogOutput (String logOutput ) {
47
+ WebElement field = driver .findElement (By .id ("issue_form_logs" ));
48
+ clearAndType (field , logOutput );
49
+ }
50
+
51
+ public void setOperatingSystem (String operatingSystem ) {
52
+ WebElement field = driver .findElement (By .id ("issue_form_operating-system" ));
53
+ clearAndType (field , operatingSystem );
54
+ }
55
+
56
+ public void setSeleniumVersion (String seleniumVersion ) {
57
+ WebElement field = driver .findElement (By .id ("issue_form_selenium-version" ));
58
+ clearAndType (field , logOutput );
59
+ }
60
+
61
+ public void setBrowserVersion (String browserVersion ) {
62
+ WebElement field = driver .findElement (By .id ("issue_form_browser-versions" ));
63
+ clearAndType (field , browserVersion );
64
+ }
65
+
66
+ public void setDriverVersion (String driverVersion ) {
67
+ WebElement field = driver .findElement (By .id ("issue_form_browser-driver-versions" ));
68
+ clearAndType (field , driverVersion );
69
+ }
70
+
71
+ public void setUsingGrid (String usingGrid ) {
72
+ WebElement field = driver .findElement (By .id ("issue_form_selenium-grid-version" ));
73
+ clearAndType (field , usingGrid );
74
+ }
75
+
76
+ public IssueList submit () {
77
+ driver .findElement (By .cssSelector ("button[type='submit']" )).click ();
78
+ return new IssueList (driver );
79
+ }
80
+
81
+ private void clearAndType (WebElement field , String text ) {
82
+ field .clear ();
83
+ field .sendKeys (text );
84
+ }
85
+ }
86
+
87
+ EditIssue page = new EditIssue (driver ).get ();
88
+
89
+ // Further Updates
90
+
91
+ @ Override
92
+ protected void load () {
93
+ securedPage .get ();
94
+
95
+ driver .get ("https://github.com/SeleniumHQ/selenium/issues/new?assignees=&labels=I-defect%2Cneeds-triaging&projects=&template=bug-report.yml&title=%5B%F0%9F%90%9B+Bug%5D%3A+" );
96
+ }
0 commit comments