Coder Social home page Coder Social logo

Comments (7)

stevepryde avatar stevepryde commented on July 21, 2024

There is no need to specify features if you just want to use the default which is tokio/async.

It seems that the feature flags are tripping some people up, and unfortunately any official documentation on "features" in Rust is very difficult to find. There is reasonable documentation for doing conditional compilation using feature flags in a library, but very little in the way of how to use feature flags when importing a crate in your own project.

I think I will need to add some more example projects rather than just example files. That will help people to see how to use this in a complete project a little easier.

What you have above should work, however.

If you want to just use the async interface, this is the default. You don't need to specify features at all. Just import the crate as you normally would, i.e. in Cargo.toml:

thirtyfour = "0.12.0"

If you want to use the sync interface instead, you need to enable the "blocking" feature, which you do like this:

thirtyfour = {version = "0.12.0", features = ["blocking"]}

If you want to use the async-std runtime instead of tokio (if you don't know what this means, ignore this part), you can do this:

thirtyfour = {version = "0.12.0", default-features = false, features = ["async-std-runtime"]}

Hope that helps. Let me know if anything is unclear and I will elaborate. Also let me know which parts were most helpful and I will try to update the documentation and relevant examples.

from thirtyfour.

steadylearner avatar steadylearner commented on July 21, 2024

Thanks for the help.

I edited the project but still get this error with $Cargo run while it passes with $cargo check.

https://github.com/steadylearner/Rust-Full-Stack/blob/master/selenium/login/error.png

Can you test it in your local machine? Like I do by downloading the crate with Cargo.toml?

What am I missing here? I pasted the sync example at main.rs and used the feature inside the Cargo.toml

Selenium is active with Docker.

CONTAINER ID        IMAGE                                            COMMAND                  CREATED             STATUS                      PORTS                                            NAMES
c3bce0ca61da        selenium/standalone-chrome-debug:3.141.59-zinc   "/opt/bin/entry_poin…"   12 minutes ago      Up 12 minutes               0.0.0.0:4444->4444/tcp, 0.0.0.0:5900->5900/tcp   selenium-server

from thirtyfour.

stevepryde avatar stevepryde commented on July 21, 2024

I think I found the issue. Somewhere along the way I changed the examples to use chromedriver directly rather than selenium. There is a separate example specifically for selenium. Unfortunately the error message is extremely unhelpful. I'm going to see if I can make this much nicer especially on the request for a new session.

For now you should be able to point the example at http://localhost:4444/wd/hub for selenium and that should work (it worked for me).

from thirtyfour.

stevepryde avatar stevepryde commented on July 21, 2024

Try now with v0.13.0. It should now give you a slightly less cryptic error saying the server returned an unknown response. Also note the documentation has changed slightly. The actual fix is as I mentioned above - use http://localhost:4444/wd/hub when connecting to selenium.

I have tested all of the examples and they all work on my PC. Instructions for running each example are included in the comments at the top of each file.

from thirtyfour.

steadylearner avatar steadylearner commented on July 21, 2024

Thanks for the update.

I could make it compile and show the title at https://github.com/steadylearner/Rust-Full-Stack/blob/master/selenium/login/src/main.rs

I have one last question. Currently, I can't see the google chrome browser pop up when I decide to install Selenium and Chrome Driver following this command.

docker run --rm -d -p 4444:4444 -p 5900:5900 --name selenium-server -v /dev/shm:/dev/shm selenium/standalone-chrome-debug:3.141.59-zinc

Is this expected behavior? How can I make the google-chrome browser show? I haven't set headless in the Rust code and I am confused because with Python Selenium library I could see the browser also.

from selenium.webdriver import Chrome
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options

opts = Options()
opts.headless = False

driver = Chrome(ChromeDriverManager().install(), options=opts)
driver.get('https://github.com/stevepryde/thirtyfour')

driver.close()
quit()

from thirtyfour.

stevepryde avatar stevepryde commented on July 21, 2024

When you use the docker container, it runs Chrome inside xvfb (X Virtual Frame Buffer) which means it is not visible on your normal X (or Wayland) display. It is a convenient way to run selenium in the background without it suddenly stealing input focus or anything like that. Also since you are running the -debug docker image, you can still view the Chrome window via VNC. If you have a VNC viewer, you can attach to localhost:5900 and view your selenium session there.

Alternatively, if you want something closer to what Python does, you can download selenium from selenium.dev and then just run the JAR file directly, like this:

java -jar selenium-server-standalone-3.141.59.jar

As long as you have chromedriver somewhere in your PATH, you will be able to start Chrome as usual. By default selenium will start on port 4444 so your code would remain the same. In this case, you will see the Chrome browser (unless you specify headless) but be aware that it may suddenly capture your keyboard or mouse inputs so that if you were typing in another window, you may end up accidentally typing in the Chrome window and messing up your test/script. Also screenshot captures will bring Chrome to the front as well. I prefer the docker container approach but you may find this more convenient.

There is a third option that Python Selenium supports but thirtyfour doesn't (yet?). That is the ability to implicitly start chromedriver in the background and then shut it down when the session ends. If you specify that you want to run selenium locally in python, that is exactly what it will do (although many users of python-selenium are not aware of this).

For now the closest you can get to this is to just run chromedriver yourself. The main documentation in the README for thirtyfour now follows this approach by default. Note that selenium is really just a proxy that manages running instances of chromedriver/geckodriver etc. If you want to start chromedriver or geckodriver yourself, then you don't need selenium server.

from thirtyfour.

steadylearner avatar steadylearner commented on July 21, 2024

Thanks for all the technical details and fast updates. I just wanted to know what is making the difference and your explanation is very helpful.

I will test your crate with the approach you told.

from thirtyfour.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.