Skip to content

Conversation

Shtogryn
Copy link
Collaborator

@Shtogryn Shtogryn commented Dec 26, 2024

Purpose

The purpose of update is to fix failed test step of test_edit_preprint test

Summary of Changes

Updated select_top_level_subject() method

Reviewer's Actions

git fetch <remote> pull/273/head:pshtohryn/ENG-6071/fix/select_top_level_subject

Run this test using

MacOS - pytest tests/test_preprints.py::TestPreprintWorkflow::test_edit_preprint -sv
Windows - pytest .\tests\test_preprints.py::TestPreprintWorkflow::test_edit_preprint -sv

Testing Changes Moving Forward

N/A

Ticket

https://openscience.atlassian.net/browse/ENG-6071

@Ramyapatil712
Copy link
Collaborator

Ramyapatil712 commented Dec 30, 2024

Update Reviewer's Actions - Path to run the test as below
pytest tests/test_preprints.py::TestPreprintWorkflow::test_edit_preprint -sv

Copy link
Member

@felliott felliott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly small stuff, and some other things we'll want to go over at Forest Fire. It might all be good, but I'm not familiar enough with the problem to say. It's also been awhile since I worked on selenium code, so my memory may not be working well. We will see!

Cheers,
@felliott

@@ -1,9 +1,13 @@
import time
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove if unused

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import time
from urllib.parse import urljoin

import ipdb
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove if unused

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

)

def select_top_level_subject(self, selection):
subject_selector = 'div[data-analytics-scope="Browse"] > ul > li'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could this be constructed from top_level_subjects, which has the same selector, but is a GroupLocator? I wonder if there's a .first method or something like that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't found the method like this one in GroupLocator()


def select_top_level_subject(self, selection):
subject_selector = 'div[data-analytics-scope="Browse"] > ul > li'
wait = WebDriverWait(self.driver, 20)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: 20 seconds sounds like a long time. Do we need that long?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, this will bail early if the condition is met, correct? If so, 20s isn't the worst thing, but if it's taking that long, we might want a flag raised. This is probably an FF topic.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated.

def select_top_level_subject(self, selection):
subject_selector = 'div[data-analytics-scope="Browse"] > ul > li'
wait = WebDriverWait(self.driver, 20)
wait.until(text_to_be_present_in_elements((By.CSS_SELECTOR, subject_selector), selection))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might be fine, but isn't there a selector to check text contents? I'm pretty sure there's one for xpath, not sure about css.

'input.ember-checkbox.ember-view'
)
checkbox.click()
subject.click()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Q: does this work? I always remember checkboxes being difficult to trigger a click on. If this works, awesome!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works.

def __call__(self, driver: WebDriver):
try:
element_texts = [element.text for element in driver.find_elements(*self.locator)]
return any([self.text in element_text for element_text in element_texts])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we can't use a "contains-text" selector, could these lines be combined to help the check short-circuit faster?. I'm not sure, but it might be worth investigating.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Shtogryn Shtogryn force-pushed the pshtohryn/ENG-6071/fix/select_top_level_subject branch from 4a025e6 to f637a4c Compare March 12, 2025 17:37
@felliott felliott dismissed their stale review March 12, 2025 18:45

it's all good now

@jh27539 jh27539 merged commit 0fdd942 into CenterForOpenScience:develop Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants