Skip to content

Commit af02e52

Browse files
Merge pull request #1675 from atlassian/jsm/fix-flaky-comment-action
Jsm/fix flaky comment action
2 parents 28b33d8 + b0828a8 commit af02e52

File tree

9 files changed

+57
-47
lines changed

9 files changed

+57
-47
lines changed

app/selenium_ui/base_page.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,12 +132,15 @@ def __wait_until(self, expected_condition, locator, time_out=timeout):
132132

133133
return WebDriverWait(self.driver, time_out).until(expected_condition, message=message)
134134

135-
def dismiss_popup(self, *args):
136-
for elem in args:
137-
if self.driver.find_elements(by=By.CSS_SELECTOR, value=elem):
135+
def dismiss_popup(self, popup_selectors):
136+
for selector_type, selector_value in popup_selectors:
137+
if self.driver.find_elements(by=selector_type, value=selector_value):
138138
try:
139-
self.driver.execute_script(f"document.querySelector(\'{elem}\').click()")
140-
except(WebDriverException, Exception):
139+
if selector_type == By.CSS_SELECTOR:
140+
self.driver.execute_script(f"document.querySelector('{selector_value}').click()")
141+
elif selector_type == By.XPATH:
142+
self.driver.find_element(by=selector_type, value=selector_value).click()
143+
except (WebDriverException, Exception):
141144
pass
142145

143146
def return_to_parent_frame(self):

app/selenium_ui/bitbucket/pages/pages.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,7 @@ def wait_for_navigation_panel(self):
103103
class PopupManager(BasePage):
104104

105105
def dismiss_default_popup(self):
106-
return self.dismiss_popup(PopupLocators.default_popup, PopupLocators.popup_1, PopupLocators.popup_2,
107-
PopupLocators.popup_3, PopupLocators.popup_4, PopupLocators.popup_5,
108-
PopupLocators.popup_6, PopupLocators.popup_7)
106+
return self.dismiss_popup(PopupLocators.popup_selectors)
109107

110108

111109
class Repository(BasePage):

app/selenium_ui/bitbucket/pages/selectors.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,16 @@ def projects_url(self):
7575

7676

7777
class PopupLocators:
78-
default_popup = '.feature-discovery-close'
79-
popup_1 = '.css-1it7f5o'
80-
popup_2 = 'button.aui-button-link.feature-discovery-close'
81-
popup_3 = '.css-15p34h1'
82-
popup_4 = '.css-1dqf51u'
83-
popup_5 = '.css-1kflcxk'
84-
popup_6 = '.css-1gh2dqy'
85-
popup_7 = "[data-testid='whats-new-modal'] button[aria-label='Close modal'] > span > span[aria-hidden='true']"
78+
popup_selectors = [
79+
(By.CSS_SELECTOR, ".feature-discovery-close"),
80+
(By.CSS_SELECTOR, ".css-1it7f5o"),
81+
(By.CSS_SELECTOR, "button.aui-button-link.feature-discovery-close"),
82+
(By.CSS_SELECTOR, ".css-15p34h1"),
83+
(By.CSS_SELECTOR, ".css-1dqf51u"),
84+
(By.CSS_SELECTOR, ".css-1kflcxk"),
85+
(By.CSS_SELECTOR, ".css-1gh2dqy"),
86+
(By.CSS_SELECTOR, "[data-testid='whats-new-modal'] button[aria-label='Close modal'] > span > span[aria-hidden='true']")
87+
]
8688

8789

8890
class LoginPageLocators:

app/selenium_ui/confluence/pages/pages.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,7 @@ class AllUpdates(BasePage):
8282
class PopupManager(BasePage):
8383

8484
def dismiss_default_popup(self):
85-
return self.dismiss_popup(PopupLocators.timezone_popups, PopupLocators.skip_onbording_1,
86-
PopupLocators.skip_onboarding_2,
87-
PopupLocators.time_saving_template,
88-
PopupLocators.welcome_to_confluence,
89-
PopupLocators.dark_theme_popup)
85+
return self.dismiss_popup(PopupLocators.popup_selectors)
9086

9187

9288
class Page(BasePage):

app/selenium_ui/confluence/pages/selectors.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@ def logout_url(self):
2929

3030

3131
class PopupLocators:
32-
timezone_popups = '.button-panel-button .set-timezone-button'
33-
skip_onbording_1 = '.aui-button aui-button-link .skip-onboarding'
34-
skip_onboarding_2 = '.aui-button.aui-button-link.skip-onboarding'
35-
time_saving_template = '#closeDisDialog'
36-
welcome_to_confluence = '.aui-button.aui-button-primary.show-onboarding'
37-
dark_theme_popup = 'button[aria-label="Close this modal"]'
32+
popup_selectors = [
33+
(By.CSS_SELECTOR, ".button-panel-button .set-timezone-button"),
34+
(By.CSS_SELECTOR, ".aui-button aui-button-link .skip-onboarding"),
35+
(By.CSS_SELECTOR, ".aui-button.aui-button-link.skip-onboarding"),
36+
(By.CSS_SELECTOR, "#closeDisDialog"),
37+
(By.CSS_SELECTOR, ".aui-button.aui-button-primary.show-onboarding"),
38+
(By.CSS_SELECTOR, "button[aria-label='Close this modal']")
39+
]
3840

3941

4042
class LoginPageLocators:

app/selenium_ui/jira/pages/pages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
class PopupManager(BasePage):
1313

1414
def dismiss_default_popup(self):
15-
return self.dismiss_popup(PopupLocators.default_popup, PopupLocators.popup_1, PopupLocators.popup_2)
15+
return self.dismiss_popup(PopupLocators.popup_selectors)
1616

1717

1818
class Login(BasePage):

app/selenium_ui/jira/pages/selectors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33

44

55
class PopupLocators:
6-
default_popup = '.aui-message .icon-close'
7-
popup_1 = 'form.tip-footer>.helptip-close'
8-
popup_2 = '.aui-inline-dialog-contents .cancel'
6+
popup_selectors = [
7+
(By.CSS_SELECTOR, ".aui-message .icon-close"),
8+
(By.CSS_SELECTOR, "form.tip-footer>.helptip-close"),
9+
(By.CSS_SELECTOR, ".aui-inline-dialog-contents .cancel")
10+
]
911

1012

1113
class UrlManager:

app/selenium_ui/jsm/pages/agent_pages.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@
99
class PopupManager(BasePage):
1010

1111
def dismiss_default_popup(self):
12-
return self.dismiss_popup(PopupLocators.default_popup, PopupLocators.popup_1, PopupLocators.popup_2,
13-
PopupLocators.popup_3, PopupLocators.popup_4,
14-
PopupLocators.popup_5, PopupLocators.popup_6, PopupLocators.popup_7)
12+
return self.dismiss_popup(PopupLocators.popup_selectors)
1513

1614

1715
class Login(BasePage):
@@ -127,21 +125,27 @@ def check_comment_text_is_displayed(self, text, rte_status=None):
127125
if self.wait_until_present(ViewCustomerRequestLocators.comment_tinymce_field).text != text:
128126
self.wait_until_present(ViewCustomerRequestLocators.comment_tinymce_field).send_keys(text)
129127
self.return_to_parent_frame()
130-
self.wait_until_present(ViewCustomerRequestLocators.comment_internally_btn).click()
128+
if self.get_elements(ViewCustomerRequestLocators.comment_internally_btn):
129+
self.wait_until_present(ViewCustomerRequestLocators.comment_internally_btn).click()
130+
else:
131+
self.wait_until_present(ViewCustomerRequestLocators.comment_internally_btn_jsm10).click()
131132
elif self.wait_until_present(ViewCustomerRequestLocators.comment_text_field).text != text:
132133
self.wait_until_present(ViewCustomerRequestLocators.comment_text_field).send_keys(text)
133-
self.wait_until_present(ViewCustomerRequestLocators.comment_internally_btn).click()
134+
if self.get_elements(ViewCustomerRequestLocators.comment_internally_btn):
135+
self.wait_until_present(ViewCustomerRequestLocators.comment_internally_btn).click()
136+
else:
137+
self.wait_until_present(ViewCustomerRequestLocators.comment_internally_btn_jsm10).click()
134138

135139
def add_request_comment(self, rte_status):
136140
comment_text = f"Add comment from selenium - {self.generate_random_string(30)}"
137141
self.wait_until_visible(ViewCustomerRequestLocators.comment_area)
138142
textarea = self.get_element(ViewCustomerRequestLocators.comment_collapsed_textarea)
139143
self.driver.execute_script("arguments[0].scrollIntoView(true);", textarea)
140144
textarea.click()
141-
if not self.get_elements(ViewCustomerRequestLocators.comment_internally_btn):
142-
comment_button = self.get_element(ViewCustomerRequestLocators.comment_internally_btn_jsm10)
143-
else:
145+
if self.get_elements(ViewCustomerRequestLocators.comment_internally_btn):
144146
comment_button = self.get_element(ViewCustomerRequestLocators.comment_internally_btn)
147+
else:
148+
comment_button = self.get_element(ViewCustomerRequestLocators.comment_internally_btn_jsm10)
145149
self.driver.execute_script("arguments[0].scrollIntoView(true);", comment_button)
146150

147151
if rte_status:

app/selenium_ui/jsm/pages/agent_selectors.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,17 @@
33

44

55
class PopupLocators:
6-
default_popup = '.aui-message .icon-close'
7-
popup_1 = 'form.tip-footer>.helptip-close'
8-
popup_2 = '.aui-inline-dialog-contents .cancel'
9-
popup_3 = '.aui-close-button'
10-
popup_4 = '.aui-button aui-button-link'
11-
popup_5 = '.buttons-container > div > a'
12-
popup_6 = '.css-19r5em7'
13-
popup_7 = '.css-178ag6o'
6+
popup_selectors = [
7+
(By.CSS_SELECTOR, ".aui-message .icon-close"),
8+
(By.CSS_SELECTOR, "form.tip-footer>.helptip-close"),
9+
(By.CSS_SELECTOR, ".aui-inline-dialog-contents .cancel"),
10+
(By.CSS_SELECTOR, ".aui-close-button"),
11+
(By.CSS_SELECTOR, ".aui-button aui-button-link"),
12+
(By.CSS_SELECTOR, ".buttons-container > div > a"),
13+
(By.CSS_SELECTOR, ".css-19r5em7"),
14+
(By.CSS_SELECTOR, ".css-178ag6o"),
15+
(By.XPATH, "//button[contains(text(),'Got it')]")
16+
]
1417

1518

1619
class UrlManager:

0 commit comments

Comments
 (0)