Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    nramisetty7
    @nramisetty7
    @rehansulehria I wrap the code that fails with headless in an if condition. if not self.headless and then write the code that I want to execute in headed mode.
    Michael Mintz
    @mdmintz
    @rehansulehria Which OS? If you're running a headless browser in Linux, you maybe be able to set --xvfb to use the xvfb virtual display if elements aren't displaying in headless mode. You'll need a new version of SeleniumBase for that. The ElementNotInteractable Exception means there was an overlay that covered the element you wanted to click. You'll either need to wait for the overlay to go away, or try using js_click instead.
    10 replies
    Praveen Raj
    @praveenraj123
    @mdmintz jenkin job executing in linux os chrome browser and headless mode
    Michael Mintz
    @mdmintz
    @praveenraj123 Try with --xvfb instead. Use the latest version of SeleniumBase.
    That should give you same same behavior on Linux as non-headless mode, without needing to run a browser in its native headless mode.
    Ivan Borisov
    @ivan-borisov

    Any way to exclude page url comparsion from Visual Regression Testing. Because I have this problem, I am testing the same site on different staging servers.
    So for example
    https://site1.com/app/feature
    and
    https://site2.com/app/feature

    have identical tag and attributes, but just tests fails because URLs are different

    May be workaround will be if is possible to compare only URL structure after domain part

    /app/feature

    Michael Mintz
    @mdmintz
    @ivan-borisov I'll create a workaround in the next version of SeleniumBase where you can bypass the domain check.
    Praveen Raj
    @praveenraj123
    @mdmintz thanks for your quick response
    @mdmintz how to re run only failed tests in jenkin job
    Michael Mintz
    @mdmintz
    @praveenraj123 That's a pytest command: https://docs.pytest.org/en/latest/how-to/cache.html
    --lf, --last-failed - to only re-run the failures.
    
    --ff, --failed-first - to run the failures first and then the rest of the tests.
    nramisetty7
    @nramisetty7
    Hey @mdmintz . Any idea on how to make a test run at the very end of the test suite? If you recall my idea on parallelizing the tests, with your help of using --dashboard and the json I was able to make tearDown to wait until all the other tests in the suite are done. I have also marked that tearDown as pytest.mark to make it run as the last test for that worker browser. I am running into this issue where all the workers are completing execution and exiting while this worker that has the tearDown runs the tearDown even though there are 2 or 3 tests (from a different module and I am using --dist=loadfile). tearDown won't do anything as there are 2 or 3 tests remaining and they are assigned to this browser. So it won't get out of tearDown and tearDown won't complete because there are other tests remaining. How do I get over this issue? I used pytest.mark.last and also pasted the test at the end of the particular module. same happens with --dist=loadscope. Any help is appreciated. Thank you!
    Had this issue before when I added new modules to the test suite. Then as I kept adding new modules it went away and now it is back. I don't know if it's happening because of the number of tests(71) is not perfectly divisible by number of workers (5) or modules (9) in the test suite.
    Michael Mintz
    @mdmintz

    @nramisetty7 First create a lock file:

    import fasteners
    my_lock_file = fasteners.InterProcessLock("my_lock_file.lock")
    with my_file_lock:
        # DO SOMETHING HERE

    Then in the "# DO SOMETHING HERE" section, create another file and write to it, incrementing the test count for each test completed. When all your tests are complete, (the count will reach the total test count), and you can perform that special tearDown that you wanted to do when all tests complete.

    The file lock is there so that two tests can't increment the counter at the same time, preventing the increment from tests that call that method at the same time.
    nramisetty7
    @nramisetty7
    No. I do not have the issue of making the tearDown wait until all tests are done before it does anything. The problem is even though I mark the tearDown as pytest.mark.last, it runs in the middle of the tests allocated for that worker.
    For simplicity lets say that I have used -n 5 and loadfile as --dist mode and 4 workers are doing what they are supposed to do. and the 5th worker has tests a,b,c,tearDown from module A and tests f,g,h from moduleB. tearDown in moduleA is marked pytest.mark.last. but the 5th worker runs tests a,b,c,tearDown and tearDown waits without doing anything because f,g,h are still untested. So tearDown is not actually happening at the end even if it's marked pytest.mark.last. Ideally I want worker 5 to run a,b,c from moduleA then f,g,h from moduleB and then tearDown from moduleA
    Michael Mintz
    @mdmintz
    @nramisetty7 The issue might be with pytest.mark.last as that might not take into account a combination with xdist (eg. -n 5). I didn't write that marker, so if there's an issue with it, that would be on pytest's end. However, you can call a tearDown that runs after all other tests have run if you use my earlier post on creating a lock file and using that to increment a counter so that you know for sure when all other tests have completed, and you can run a custom tearDown with all the browser methods that you need.
    nramisetty7
    @nramisetty7
    @mdmintz Yeah I understand that here is not the best place to ask about pytest issues. Wanted to see if you can think of an alternate way. Thanks for the idea. I will try to understand it and implement it
    Michael Mintz
    @mdmintz
    @ivan-borisov You can now exclude the domain from a visual layout comparison: https://github.com/seleniumbase/SeleniumBase/releases/tag/v1.65.3
    Ivan Borisov
    @ivan-borisov
    Great!
    Praveen Raj
    @praveenraj123
    @mdmintz we are triggered jenkin job on hour before our jobs getting pass but now our jobs are throw below mentioned error " selenium.common.exceptions.WebDriverException: Message: unknown error: net::ERR_NAME_NOT_RESOLVED
    (Session info: headless chrome=92.0.4515.131)" kindly help us how to fix it
    Michael Mintz
    @mdmintz
    @praveenraj123 That's a DNS error that occurs when the site isn't properly mapping to an IP Address. It's not related to the automation, but to the website itself. There are a few articles on it: https://www.ionos.com/digitalguide/hosting/technical-matters/err-name-not-resolved-error/ and https://www.drivereasy.com/knowledge/how-to-fix-err-name-not-resolved-error/
    Praveen Raj
    @praveenraj123
    hi @mdmintz im try to use Action class perform click operation but i'm facing "self = <selenium.webdriver.remote.errorhandler.ErrorHandler object at 0x000001906BFB50A0>
    response = {'status': 500, 'value': '{"value":{"error":"unknown error","message":"Element \u003Cdiv role=\"presentation\" cell...cribeWnfStateChangeNotification [0x777A1B69+1081]\n\tRtlSubscribeWnfStateChangeNotification [0x777A1B34+1028]\n"}}'}" my chrome driver version 93.0.4577.63 (Latest)
    Michael Mintz
    @mdmintz
    @praveenraj123 Is there a reason you can't use self.click(selector) to perform a click?
    Praveen Raj
    @praveenraj123
    @mdmintz thanks for your response but self.click method is not working my application it script click successfully but my application not working most of the time and i perform multi-select its only possible mouse action some day before i facing issue some one suggest update chrome driver but now no luck again i facing same issue kindly provide any solution
    Michael Mintz
    @mdmintz
    @praveenraj123 self.js_click() can get around issues that a regular click could get stuck on.
    Praveen Raj
    @praveenraj123
    @mdmintz thanks for your updated
    angelaDer
    @angelaDer
    Hi! My HTML has a div like this:
    <div id="result" ></div> where result is printed on the screen. How can I get text from this div using seleniumbase? I know that the string which will appear is "PASS", however is_text_visible doesn't work.
    angelaDer
    @angelaDer
    @mdmintz in selenium I use res = driver.find_elements_by_xpath("//div[@id='result']") and then result[0].text to get the text, so I'm looking for something like this in SeleniumBase to get this value
    nramisetty7
    @nramisetty7
    @angelaDer I usually use get_text() method and specify the selector and By (default is CSS selector) to get the text. You can also use self.find_element(selector, By).text to get the text. Both work for me
    Michael Mintz
    @mdmintz
    Hi @angelaDer There's self.get_text("#result") if the element is visible. If it's hidden, you can probably use self.get_attribute("#result", "value")
    SykLuk
    @SykLuk
    @mdmintz do you plan to add support for Cucumber?
    Michael Mintz
    @mdmintz
    Hi @SykLuk Are you looking for https://pypi.org/project/pytest-bdd/ ? pytest is the framework that runs SeleniumBase tests, so things of that nature would be covered by existing pytest plugins. Also, some pytest plugins require the use of the SeleniumBase sb fixture format for compatibility reasons. See syntax formats 3, 4, 6, 7, and 8 from https://seleniumbase.io/help_docs/syntax_formats/ .
    And also see https://github.com/pytest-dev/pytest-bdd for the BDD/Cucumber plugin details.
    Michael Mintz
    @mdmintz
    In general, test framework features that are unrelated to browser actions are under the scope of pytest and all of its existing plugins. Good examples of that are test parameterization, multi-threading, structure, looping/rerunning tests, and plenty of others. This makes SeleniumBase easily extendable, just like any plugin that extends pytest functionality.
    Michael Mintz
    @mdmintz
    @SykLuk You’ll need to use the sb fixture for that. See syntax formats 3, 4, 6, 7, and 8 from https://seleniumbase.io/help_docs/syntax_formats/ (What you did in your code was import BaseCase as sb, which isn’t the same)
    SykLuk
    @SykLuk
    @mdmintz thanks, it works now. Another question, how I can now change webdriver options? In previous implementation I was creating webdriver instance in my test file, now I'm not sure where to find this, since sb opens browser automatically. I need this to pass and load chrome extension.
    Michael Mintz
    @mdmintz
    @SykLuk You can pass the zip of the Chrome extension as a pytest command-line option with:
    --extension-zip=ZIP
    Michael Mintz
    @mdmintz
    SeleniumBase Recorder Mode has launched! It's a standalone replacement to Selenium IDE. Record browser actions and create test scripts of that. Available in SeleniumBase 1.66.0.
    https://seleniumbase.io/help_docs/recorder_mode/
    _
    @RIPfrank_white_twitter
    @mdmintz any chance there is a way to get reporting metrics on the number of Assertions executed? As opposed to the number of tests ... since one test can test multiple things
    Michael Mintz
    @mdmintz
    @RIPfrank_white_twitter That depends on how you count assertions. A click() method, for example, first asserts that an element is visible before clicking on it.
    2 replies
    Ivan Borisov
    @ivan-borisov
    Any way to throw custom message for example i want to throw custom message if elements is not visible
    def task_panel_is_visible(self): self.assert_element(Bo.task_panel_css)
    Not standart Element was not present after 6 seconds!
    It is possible in any way
    Michael Mintz
    @mdmintz
    @ivan-borisov Yes, that's possible. But it requires a bit of work. Similar to how you can create custom setUp() and tearDown() steps in https://github.com/seleniumbase/SeleniumBase/blob/master/examples/boilerplates/base_test_case.py You can override any SeleniumBase method you want with a custom method, that could just modify a message.
    go000o
    @go000o
    @mdmintz hi, I want to print the log in the code and i try to write code as below in base_case.py

    tHandler = logging.StreamHandler()

    tHandler .setLevel(logging.INFO)

    formatter = logging.Formatter('%(name)-12s: %(levelname)-8s %(message)s')

    tHandler .setFormatter(formatter)

    logging.getLogger().addHandler(tHandler )

    tLogger = logging.getLogger("tlog") and then let self.log = ochartLogger in init function of base_case.py, then I use self.log.info(msg) in my own testcase, then I click run button to run the case and wait for the log printed out, but no log can be printed out. I don't know how to make the log shown.

    Michael Mintz
    @mdmintz

    @go000o There are a few reasons that your logging data might not be shown. You may need to change the level first, example:

    logging.getLogger("requests").setLevel(logging.INFO)
    logging.getLogger("urllib3").setLevel(logging.INFO)

    Or if you're running multithreaded tests, (-n=3 for example), then logging won't get displayed by default because the tests would be running in separate subprocesses. There's a Stack Overflow article on that: https://stackoverflow.com/a/46111048

    Michael Mintz
    @mdmintz
    SeleniumBase v1.66.3 has been released! Includes improvements to --recorder mode.