Reputation: 63
I have a web application which I need to test whether it can simulate user behavior for many users logged in at the same time and perform multiple file uploads and downloads. There are multiple entry points for the uploads as well as downloads. I went ahead with using Selenium for imitating user behavior. Integrated Java, Selenium, TestNG, AutoIT and also using Selenium Grid to connect to various VMs for browser compatibility testing. Browsers supported are Chrome, Firefox, IE 8,9,10,11. Everything works fine except the handling of windows dialogs in parallel. Any tool that I came across which handles windows dialogs requires the window to be in the front. This is not possible when I am running say 100 instances. Please suggest.
I am adding the code snippets. They wont run because they are configured for Selenium Grid.
Here is my java class:
public class Test {
RemoteWebDriver driver;
@Test
public void testDownload() {
driver.findElement(By.id("Download")).click();
Runtime.getRuntime().exec("C:\\IE11.exe");
}
@BeforeTest
@Parameters({"browser","version","environment","username","password"})
public void launchBrowserAndLogin(String browser, String version, String environment, String username, String password) throws MalformedURLException, InterruptedException {
DesiredCapabilities caps = new DesiredCapabilities();
if(browser.equalsIgnoreCase("chrome")){
System.setProperty("webdriver.chrome.driver", "C://chromedriver.exe");
caps = DesiredCapabilities.chrome();
}
if(browser.equalsIgnoreCase("ie")){
System.setProperty("webdriver.ie.driver", "C://IEDriverServer.exe");
caps = DesiredCapabilities.internetExplorer();
caps.setVersion(version);
}
switch(environment){
case "trunk" : baseURL = "http://trunk-url"; break;
case "prod" : baseURL = "https://prod-url"; break;
default : baseURL = ""; break;
}
driver = new RemoteWebDriver(new URL("http://localhost/wd/hub"), caps);
driver.navigate().to(baseURL); //go to selected URL
driver.manage().window().maximize(); //maximize window
Thread.sleep(7000);
driver.findElement(By.xpath(".//*[@id='username']")).sendKeys(username); //enter Username
driver.findElement(By.xpath(".//*[@id='password']")).sendKeys(password); //enter Password
driver.findElement(By.xpath(".//*[@id='login']")).click(); //click on Login
Thread.sleep(7000);
Assert.assertEquals(driver.getTitle(), "Order History");
}
@AfterTest
public void logoutAndTerminateBrowser() throws InterruptedException {
driver.findElement(By.xpath(".//*[@id='login-menu']/a")).click(); //click on Logout
Thread.sleep(7000);
driver.quit();
}
}
As you can see, the
Runtime.getRuntime().exec("C:\IE11.exe");
runs the AutoIt script. The AutoIt script simply contains:
Send("!s")
This just sends Alt+S (command to save in IE download pop up bar). And this is the area where parallel execution fails.
Here is my TestNG xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="TestSuite" verbose="2" parallel="tests" thread-count="2">
<test name="IE11_1">
<parameter name="browser" value="ie"/> <parameter name="version" value="11"/> <parameter name="environment" value="trunk"/> <parameter name="username" value="User1"/> <parameter name="password" value="Pass1"/>
<classes><class name="Test"/></classes>
</test>
<test name="IE11_2">
<parameter name="browser" value="ie"/> <parameter name="version" value="11"/> <parameter name="environment" value="trunk"/> <parameter name="username" value="User2"/> <parameter name="password" value="Pass2"/>
<classes><class name="Test"/></classes>
</test>
Upvotes: 0
Views: 3628
Reputation: 63
After trying a hell lot of things, I have come to the conclusion that the parallel execution is possible through selenium grid, and the file upload and download works fine if I run my tests only on Chrome or Firefox. Selenium is not for performance testing, and other tools (like JMeter) might be more helpful.
Upvotes: 0
Reputation: 2981
I would just circumvent the windows dialogs altogether and simulate the network traffic on the backend using HTTP Requests.
Use something like Fiddler2 to capture the exact traffic, parameterize it, and voila.
I have an example of it on another post, one sec:
Selenium Webdriver doesn't really support this. Interacting with non-browser windows (such as native file upload dialogs and basic auth dialogs) has been a topic of much discussion on the WebDriver discussion board, but there has been little to no progress on the subject.
I have, in the past, been able to work around this by capturing the underlying request with a tool such as Fiddler2, and then just sending the request with the specified file attached as a byte blob.
If you need cookies from an authenticated session, WebDriver.magage().getCookies() should help you in that aspect.
edit: I have code for this somewhere that worked, I'll see if I can get ahold of something that you can use.
public RosterPage UploadRosterFile(String filePath){
Face().Log("Importing Roster...");
LoginRequest login = new LoginRequest();
login.username = Prefs.EmailLogin;
login.password = Prefs.PasswordLogin;
login.rememberMe = false;
login.forward = "";
login.schoolId = "";
//Set up request data
String url = "http://www.foo.bar.com" + "/ManageRoster/UploadRoster";
String javaScript = "return $('#seasons li.selected') .attr('data-season-id');";
String seasonId = (String)((IJavaScriptExecutor)Driver().GetBaseDriver()).ExecuteScript(javaScript);
javaScript = "return Foo.Bar.data.selectedTeamId;";
String teamId = (String)((IJavaScriptExecutor)Driver().GetBaseDriver()).ExecuteScript(javaScript);
//Send Request and parse the response into the new Driver URL
MultipartForm form = new MultipartForm(url);
form.SetField("teamId", teamId);
form.SetField("seasonId", seasonId);
form.SendFile(filePath,LoginRequest.sendLoginRequest(login));
String response = form.ResponseText.ToString();
String newURL = StaticBaseTestObjs.RemoveStringSubString("http://www.foo.bar.com" + response.Split('"')[1].Split('"')[0],"amp;");
Face().Log("Navigating to URL: "+ newURL);
Driver().GoTo(new Uri(newURL));
return this;
}
Where MultiPartForm is: MultiPartForm
And LoginRequest/Response: LoginRequest LoginResponse
The code above is in C#, but there are equivalent base classes in Java that will do what you need them to do to mimic this functionality.
The most important part of all of that code is the MultiPartForm.SendFile method, which is where the magic happens.
Upvotes: 0