Vrtgs / thirtyfour

Selenium WebDriver client for Rust, for automated testing of websites
Other
1.06k stars 78 forks source link

Error with choosing the browser from CLI input #246

Closed icecat89 closed 3 weeks ago

icecat89 commented 1 month ago

I used this function to return the type of browser as DesiredCapabilities, using the CLI command, means the user will choose which browser will be used:

fn marge_caps<T>(cli : Arc<Cli>) -> DesiredCapabilities{
    match cli.browser{
        BrowserSupported::Chrome => return DesiredCapabilities::chrome(),
        BrowserSupported::FireFox => return DesiredCapabilities::firefox(),
        BrowserSupported::Edge => return DesiredCapabilities::edge(),

    };
}

the problem is that i got an error:

error[E0308]: mismatched types
  --> src\crap.rs:10:44
   |
8  | fn marge_caps(cli : Arc<Cli>) -> DesiredCapabilities {
   |                                  ------------------- expected `thirtyfour::DesiredCapabilities` because of return type
9  |     match cli.browser{
10 |         BrowserSupported::Chrome => return DesiredCapabilities::chrome(),
   |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `DesiredCapabilities`, found `ChromeCapabilities`

@Vrtgs , I searched everywhere to solve this error, but i couldn't, please, if you have an idea just tell me tho and thanks ^^

Vrtgs commented 3 weeks ago

DesiredCapabilities can be thought of as just a name space 🙃, you can use Capabilities for if you want to return the actual capabilities, just do DesiredCapabilities::chrome().into() and so on

otherwise if you want to chnage options generically on many Capabilities I would suggest just making your enum that implents from Capabilities

enum Caps {
    Chrome(ChromeCapabilities),
    Edge(EdgeCapabilities),
    FireFox (FirefoxCapabilities),
}

// impl logic for caps here

impl From<Caps> for Capabilities {
    fn from(value: Caps) {
         match value {
             Chrome(c) => c.into(),
             Edge(c) => c.into(),
             FireFox(c) => c.into()
         }
    }
}

and sorry for the late response I was busy with midterms

icecat89 commented 3 weeks ago

no problem at all, i already solve it )) thank u man let me ur contact method if u can )) would be really thankfull ^^

Vrtgs commented 1 week ago

Email: vrtgs or better yet, on discord, my username is also just vrtgs there