Father and husband; Android Engineer and Quality Advocate; For fun, I enjoy playing video games, guitar, and table top games. I also dabble in hobby game dev and pixel arts.
For Selenium in Java I was using a singleton pattern to setup the WebDriver instance. Since switching to Kotlin, I was having issues with it working reliably with the object way. I was getting multiple browsers opened, which is contrary to the singleton pattern purpose.
How are you using this pattern with or without the object concept in Android?
Could it be that your code was getting called multiple times or in multiple threads? I'm not sure but I can imagine that with Selenium. You might want to search for "thread-safe singleton" in Kotlin when trying to fix it again, quite possible the object approach isn't by default, but I'm sure there's an easy fix.
Father and husband; Android Engineer and Quality Advocate; For fun, I enjoy playing video games, guitar, and table top games. I also dabble in hobby game dev and pixel arts.
Father and husband; Android Engineer and Quality Advocate; For fun, I enjoy playing video games, guitar, and table top games. I also dabble in hobby game dev and pixel arts.
That is what I thought, but if it is spinning up multiple threads, maybe that is why it is spinning up multiple browser instances. I’ll have to look into it again when I get time away from Android studies lol.
Oh, That's very weird. I don't know anything about Selenium. I've always used the object keyword whenever I need to use the Singleton pattern but you can try this. It should work.
Father and husband; Android Engineer and Quality Advocate; For fun, I enjoy playing video games, guitar, and table top games. I also dabble in hobby game dev and pixel arts.
For Selenium in Java I was using a singleton pattern to setup the WebDriver instance. Since switching to Kotlin, I was having issues with it working reliably with the object way. I was getting multiple browsers opened, which is contrary to the singleton pattern purpose.
How are you using this pattern with or without the object concept in Android?
Could it be that your code was getting called multiple times or in multiple threads? I'm not sure but I can imagine that with Selenium. You might want to search for "thread-safe singleton" in Kotlin when trying to fix it again, quite possible the
object
approach isn't by default, but I'm sure there's an easy fix.Ah that is a good point to make. It is possible I set it up with parallel running without thinking about it! Will do and thanks for the tip!
That makes a lot of sense. Thanks Cihat for the explanation. Although, kotlin
object
is actually thread safe. kotlinlang.org/docs/object-declara...That is what I thought, but if it is spinning up multiple threads, maybe that is why it is spinning up multiple browser instances. I’ll have to look into it again when I get time away from Android studies lol.
Oh, That's very weird. I don't know anything about Selenium. I've always used the object keyword whenever I need to use the Singleton pattern but you can try this. It should work.
Let me know if it does
If and when I get back to the project, I can try it! Thanks!