简体   繁体   English

想要在Selenium Web驱动程序中执行单个步骤

[英]Want to execute single step in selenium web driver

I am using selenium webdriver to do automation of web application.(I am using eclipse) In my test, I have written the code to login the page by credential, then click some links and go to a particular page.Now on that page i am filling fields through drop down and all and its not working. 我正在使用Selenium Webdriver来实现Web应用程序的自动化。(我正在使用eclipse)在我的测试中,我编写了代码以凭凭据登录页面,然后单击一些链接并转到特定页面。正在通过下拉菜单填充字段,并且全部不起作用。

So My question is if i changing my code to work with drop down,then to test this again i need to run test case from starting.Means again it it will login page will load and go through various links and then reach to that page. 所以我的问题是如果我更改代码以使用下拉菜单,然后再次进行测试,则需要从开始运行测试用例。再次说明,它将登录页面加载并通过各种链接,然后到达该页面。 So can not directly execute that steps only like we do in selenium IDE??? 因此,不能像在Selenium IDE中那样直接执行那些步骤???

Again and again executing from starting is really screwing my time...?? 从头开始一遍又一遍地执行确实浪费了我的时间... ??

Is there any way/shortcut?? 有什么办法/捷径吗? Please suggest me. 请给我建议。

Thanks 谢谢

Selenium IDE is in-browser, it's then normal you can run at any step. Selenium IDE在浏览器中,因此可以在任何步骤运行都是正常的。 But if your cookies have expired, you'll have to reauthent. 但是,如果您的Cookie已过期,则必须重新进行身份验证。 It's not a Selenium problem, it's how websites work. 这不是硒问题,而是网站的工作方式。 In your tests, you'll always have to start from scratch if your cases involve athent process, unless you manage to get a fine control over your cookies. 在您的测试中,如果您的案件涉及到其他程序,则始终必须从头开始,除非您设法对Cookie进行很好的控制。

You can always make a quick http call to the website you want to connect to with HTTPClient for example, just to get the cookie back, then use it in webdriver with something like 例如,您始终可以快速拨打HTTP呼叫要与HTTPClient连接的网站,只是要取回cookie,然后在webdriver中将其与类似

driver.manage().addCookie(new Cookie("foo", "bar", "www.domain.com", "/", null));

then go to the page you need. 然后转到您需要的页面。 Notice that this solution solves the Authent problem only, and does not control the state of the tested web-application (data previously posted, etc...). 请注意,此解决方案仅解决了Authent问题,并且不控制测试的Web应用程序的状态 (先前发布的数据等)。

At our company, we make an extensive use of selenium, and have a lot of tests relying on it, it's therefore a problem we know something about and we are aware of the frustation it can cause. 在我们的公司中,我们广泛使用硒,并且有大量的测试依赖于硒,因此我们知道这一问题,并且已经意识到硒会造成的麻烦。

We use a pretty different solution to get a productivity boost on tests. 我们使用完全不同的解决方案来提高测试的生产率。 In fact, we're using a Groovy Shell -based solution which allows us to go back and forth while developping the tests and keep our browsers open. 实际上,我们使用的是基于Groovy Shell的解决方案,该解决方案使我们能够在开发测试的同时来回移动并保持浏览器保持打开状态。 Groovy is a JVM scripting language that is really easy for a Java dev (almost all Java code is valid Groovy code) and it's really dynamic. Groovy是一种JVM脚本语言,对于Java开发人员来说非常容易(几乎所有Java代码都是有效的Groovy代码),并且它是动态的。

So you can download groovy, run groovy shell ( groovysh is the command), then line by line you can launch and interact with the browser xhile your written code is saved to a buffer. 因此,您可以下载groovy,运行groovy shell( groovysh是命令),然后可以逐行启动并与浏览器进行交互,而将编写的代码保存到缓冲区中。 When you've done with your test, export the code and put it in Eclipse. 完成测试后,导出代码并将其放入Eclipse。 It's faster than restarting every time from scratch. 这比每次从头开始重新启动都要快。 Magic lines for starting with selenium are 以硒开头的魔咒是

groovy.grape.Grape.grab(autoDownload: true, group : 'org.seleniumhq.selenium', module : 'selenium-firefox-driver', version : '2.37.1')
import org.openqa.selenium.*
import org.openqa.selenium.firefox.*
driver = new FirefoxDriver()
driver.get("http://my-website.com")

From this point, the browser window is always open, and you develop right in groovy (or java). 从这一点开始,浏览器窗口始终处于打开状态,并且您可以直接使用groovy(或Java)进行开发。 It's like a selenium-ide, but in groovy, and can be integrated in your developement workflow (but there is a bit of work to do) This example works for Firefox (as you've probably guessed ;-)) but you can adapt it as you like. 它就像硒元素一样,但是很时髦,并且可以集成到您的开发工作流中(但是还有很多工作要做)。此示例适用于Firefox(您可能已经猜到了;-),但是您可以适应随便你。 We have from this constructed a bunch of tools to develop our tests quickly and iteratively. 由此,我们构建了许多工具来快速且迭代地开发我们的测试。 We found this to be a great savior. 我们发现这是一个伟大的救星。

In the case you described, the tests will always return to step 1, therefore, you need to execute your automation suite from the beginning. 在您描述的情况下,测试将始终返回到步骤1,因此,您需要从头开始执行自动化套件。

Tip for the future, separate your test cases to shorter ones (as Alexander suggested), so you if you need, you can easily use only the cases that needed and relevant to the module you currently working on. 未来的技巧是,将测试用例与较短的用例分开(如Alexander所建议的),因此,如果需要,您可以轻松地仅使用需要且与当前工作的模块相关的用例。

There is nothing different answer..runs from first step... 第一步没有什么不同..运行...
And my kind advice is that to use a break point in eclipse at which ur guess of failing...and run the eclipse program in debug mode vth continuously pressing F6 key. 我的建议是在eclipse中使用一个断点,在该处您可能会失败...并连续按F6键以调试模式运行eclipse程序。
The excecution will be slowed and display will be step by step mode which u can easily trace the exact location at which ur code is breaking... 执行将变慢,显示将是逐步的模式,您可以轻松地找到您的代码被破坏的确切位置...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM