[tests] Add basic Selenium tests for Dependabot PRs (#537)#584
[tests] Add basic Selenium tests for Dependabot PRs (#537)#584aoutifrak wants to merge 0 commit intoopenwisp:masterfrom aoutifrak:master
Conversation
aoutifrak
left a comment
There was a problem hiding this comment.
Fixed the formatting issues to comply with style guidelines.
codesankalp
left a comment
There was a problem hiding this comment.
Hi @aoutifrak, thanks for your contribution!
Please take a look at my comments below. For the Selenium tests, you can refer to other repositories like openwisp-controller to avoid duplication and follow best practices for implementing this feature.
pandafy
left a comment
There was a problem hiding this comment.
@aoutifrak I have left suggestions to make the tests consistent with other OpenWISP modules.
aoutifrak
left a comment
There was a problem hiding this comment.
Updated test cases for batch user creation, CSV import, and user generation.
Replaced double quotes with single quotes for string literals to maintain code consistency.
Added detailed comments to explain each part of the test case logic for better understanding.
Ensured alignment with OpenWISP conventions, including the use of self.open() and self.find_element().
These changes enhance the clarity and maintainability of the tests.
There was a problem hiding this comment.
- Added SELENIUM_HEADLESS=1 to the workflow environment variables.
- Ensures Selenium tests run in headless mode in CI for consistency.
- Helps prevent UI-related flakiness in automated tests.
This change improves reliability and aligns the workflow with best practices for Selenium testing in CI environments.
pandafy
left a comment
There was a problem hiding this comment.
Thanks for contributing! I have left some suggestions to improve the tests.
| @@ -0,0 +1,3 @@ | |||
| csv-user1,password1,csvuser1@example.com,CSV1,User1 | |||
| csv-user2,password2,csvuser2@example.com,CSV2,User2 | |||
| csv-user3,password3,csvuser3@example.com,CSV3,User3 No newline at end of file | |||
There was a problem hiding this comment.
Add a blank line at end of the file. You can configure your code editor to always do that.
There was a problem hiding this comment.
endline are exsiste just didn't show here
| self.open(reverse('admin:openwisp_users_organization_add')) | ||
| self.find_element(By.ID, "id_name").send_keys("Test Batch") | ||
| self.find_element(By.CSS_SELECTOR, "input[type=submit]").click() |
There was a problem hiding this comment.
You can use self._get_org() helper method to create an organization here.
|
|
||
| self.find_element(By.ID, "id_name").send_keys("Test Batch") | ||
| prefix_field = self.find_element(By.ID, "id_prefix") | ||
| prefix_field.clear() |
There was a problem hiding this comment.
Why are we clearing the field before entering data? Wouldn't the field be already empty?
| self.find_element(By.ID, "id_name").send_keys("Test Batch") | ||
| self.find_element(By.CSS_SELECTOR, "input[type=submit]").click() | ||
|
|
||
| self.open("/admin/openwisp_radius/radiusbatch/add/") |
There was a problem hiding this comment.
Let's maintain consistent quoting style.
Also, use django.urls.reverse to get the path of the page. This applies to all the occurrences.
| class BasicTest( | ||
| SeleniumTestMixin, FileMixin, StaticLiveServerTestCase, TestOrganizationMixin | ||
| ): | ||
| browser = 'chrome' |
There was a problem hiding this comment.
Any specific reason for using chrome browser for this test? If not, we can remove this.
There was a problem hiding this comment.
there is no reason thanks
| # Verify that users from the CSV file were created | ||
| self.find_element(By.CLASS_NAME, 'field-name').click() | ||
| self.open(reverse('admin:openwisp_users_user_changelist')) | ||
| user1_link = self.wait_for_visibility( | ||
| By.XPATH, "//a[contains(text(), 'user1')]", 10 | ||
| ) | ||
| self.assertIsNotNone(user1_link) | ||
|
|
||
| # Ensure another user from the CSV is also created | ||
| user2_link = self.find_element(By.XPATH, "//a[contains(text(), 'user2')]") | ||
| self.assertIsNotNone(user2_link) |
There was a problem hiding this comment.
Verify that user were created in the database using
self.assertEqual(User.objects.filter(username='<user1>).exists(), True)
self.assertEqual(User.objects.filter(username='<user2>).exists(), True)
| # Navigate to organization creation page | ||
| self.open(reverse('admin:openwisp_users_organization_add')) | ||
| self.find_element(By.ID, 'id_name', 10).send_keys('Test Batch') | ||
| self.find_element(By.CSS_SELECTOR, 'input[type=submit]', 10).click() |
There was a problem hiding this comment.
Use self._get_org() to create organization object.
| # Verify that users with hashed passwords are created | ||
| self.find_element(By.CLASS_NAME, 'field-name').click() | ||
| self.open(reverse('admin:openwisp_users_user_changelist')) | ||
| hash_user1_link = self.wait_for_visibility( | ||
| By.XPATH, "//a[contains(text(), 'hash_user1')]", 10 | ||
| ) | ||
| self.assertIsNotNone(hash_user1_link) | ||
|
|
||
| hash_user2_link = self.find_element( | ||
| By.XPATH, "//a[contains(text(), 'hash_user2')]", 10 | ||
| ) | ||
| self.assertIsNotNone(hash_user2_link) |
There was a problem hiding this comment.
You can verify that the users are created using
self.assertEqual(User.objects.filter(username='<>').exists(), Trie)
We should also verify that the password works for the user. Otherwise, this test is similar to one above it.
| # Create an organization for the prefix user generation | ||
| self.open(reverse('admin:openwisp_users_organization_add')) | ||
| self.find_element(By.ID, 'id_name', 10).send_keys('Test Batch') | ||
| self.find_element(By.CSS_SELECTOR, 'input[type=submit]', 10).click() |
There was a problem hiding this comment.
Use self._get_org() to create organization object.
| assert contains_ten, "No element contains the number 10" | ||
|
|
||
| # Test case for user generation using CSV file upload | ||
| def test_csv_user_generation(self): |
|
@aoutifrak why did you close this pull request? |
|
Reopening. |
Checklist
Reference to Existing Issue
Closes #537.
Please open a new issue if there isn't an existing issue yet.
Description of Changes
Please describe these changes.
Screenshot
Please include any relevant screenshots.