cancel
Showing results for 
Search instead for 
Did you mean: 

opening a browser in script extension

Super Contributor

opening a browser in script extension

Browsers.Item(btIExplorer).Run("http://smartbear.com/"); 

 

The above would be what I use in my project. How would one do the equivalent in a script extension? Thanks

11 REPLIES 11
Community Hero

Re: opening a browser in script extension

The Browsers object is not accessible within an extension so you can't do exactly the same thing.

What you will have to do is write code to use the WshShell object and the Run method to run the desired browser executable.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Super Contributor

Re: opening a browser in script extension

Hrrrrrm. Can't find an edge executable. But I shall seek on. Thanks.

Community Manager

Re: opening a browser in script extension

@vthomeschoolmom, please share with us the code you'll create with the WScript.Shell object.

---------
Tanya Gorbunova
SmartBear Community Manager

Did my reply answer your question? Give Kudos or Accept it as a Solution to help others.↓↓↓↓↓
Super Contributor

Re: opening a browser in script extension

I am not including all the logic I am going to use to randomize which browser.... but just to load the browser window and navigate to the page

 

    WshShell.Run("powershell - file C:\\VSI Script Extensions\\RecTrac\\edge.bat");
	Sys.Browser(ProjectSuite.Variables.BrowserUnderTest).ToUrl(Project.Variables.Url);
Super Contributor

Re: opening a browser in script extension

Of course, it worked once then stopped working. What I am seeing now is that the browser load appears to load which I see with the flicker of the pinned shortcut. But it does not remain loaded. Any thoughts?

 

Sort of a righteous bummer that the browser object is not exposed to script extensions.

Community Hero

Re: opening a browser in script extension

Possibly the browser is still loaded and running as a hidden process...  Windows 10 environments are NOTORIOUS for "suspended" applications.  Before running a browser, I usually check to see if it's already running... if it is, kill the process so that, when I start the browser, it starts brand new.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Super Contributor

Re: opening a browser in script extension

Yes. I did that. Alas that is not it. 

Community Hero

Re: opening a browser in script extension

Can I go back to square one for a moment?

Why do you want to move the execution of the browser from your code to an extension?  The automation code for running browsers, even in a loop, is relatively simple.  Help me understand what you're trying to achieve... there may be a better way.


Robert Martin
[Community Expert Group]
Please consider giving a Kudo if I write good stuff
----

Why automate?  I do automated testing because there's only so much a human being can do and remain healthy.  Sleep is a requirement.  So, while people sleep, automation that I create does what I've described above in order to make sure that nothing gets past the final defense of the testing group.
I love good food, good books, good friends, and good fun.

Mysterious Gremlin Master
Extensions available
Super Contributor

Re: opening a browser in script extension

To answer yuor question, basically the encapsulation of a number of operations that are done consistently at the start of every test in a manner that is super simple for the test creators. 

 

As to the solution, using the command directly rather than in batch was the thing. A little snip:

 

    var runCommand = "";
    //iexplore firefox chrome edge
    switch (ProjectSuite.Variables.BrowserUnderTest) {
    case "edge":
        runCommand = "cmd.exe /C start microsoft-edge:http://www.microsoft.com";
        break;
    case "chrome":
        runCommand = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe"
        break;
    default:
        runCommand = "cmd.exe /C start microsoft-edge:http://www.microsoft.com";
    }
	

	WshShell.Run(runCommand);
New Here?
Join us and watch the welcome video:
6 / 7 API Testing Mistakes Video
Top Kudoed Authors