Skip to content

Commit

Permalink
can add steps from main UI
Browse files Browse the repository at this point in the history
  • Loading branch information
liujordan committed Feb 4, 2018
1 parent 50cd3df commit d5019f7
Show file tree
Hide file tree
Showing 15 changed files with 179 additions and 62 deletions.
23 changes: 0 additions & 23 deletions TestYourTech/migrations/0009_auto_20180204_0611.py

This file was deleted.

14 changes: 14 additions & 0 deletions TestYourTech/migrations/0010_merge_20180204_0401.py
@@ -0,0 +1,14 @@
# Generated by Django 2.0.2 on 2018-02-04 09:01

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('TestYourTech', '0008_merge_20180204_0608'),
('TestYourTech', '0009_auto_20180204_0134'),
]

operations = [
]
@@ -1,4 +1,4 @@
# Generated by Django 2.0.2 on 2018-02-04 06:46
# Generated by Django 2.0.2 on 2018-02-04 09:04

from django.db import migrations, models
import django.db.models.deletion
Expand All @@ -7,7 +7,7 @@
class Migration(migrations.Migration):

dependencies = [
('TestYourTech', '0009_auto_20180204_0134'),
('TestYourTech', '0010_merge_20180204_0401'),
]

operations = [
Expand All @@ -21,6 +21,20 @@ class Migration(migrations.Migration):
model_name='action',
name='prev_action',
),
migrations.RemoveField(
model_name='action',
name='results',
),
migrations.AddField(
model_name='action',
name='result',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='TestYourTech.Result'),
),
migrations.AlterField(
model_name='action',
name='action_type',
field=models.CharField(choices=[('click', 'CLICK'), ('type', 'TYPE'), ('url', 'GO TO URL'), ('submit', 'SUBMIT')], default='click', max_length=256),
),
migrations.AddField(
model_name='actionlink',
name='after',
Expand Down
18 changes: 18 additions & 0 deletions TestYourTech/migrations/0012_result_value.py
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-02-04 09:08

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('TestYourTech', '0011_auto_20180204_0404'),
]

operations = [
migrations.AddField(
model_name='result',
name='value',
field=models.CharField(blank=True, max_length=256),
),
]
18 changes: 18 additions & 0 deletions TestYourTech/migrations/0013_auto_20180204_0409.py
@@ -0,0 +1,18 @@
# Generated by Django 2.0.2 on 2018-02-04 09:09

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('TestYourTech', '0012_result_value'),
]

operations = [
migrations.AlterField(
model_name='result',
name='selector',
field=models.CharField(max_length=256),
),
]
32 changes: 32 additions & 0 deletions TestYourTech/migrations/0014_auto_20180204_0553.py
@@ -0,0 +1,32 @@
# Generated by Django 2.0.2 on 2018-02-04 10:53

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('TestYourTech', '0013_auto_20180204_0409'),
]

operations = [
migrations.RemoveField(
model_name='action',
name='testcases',
),
migrations.AlterField(
model_name='action',
name='action_type',
field=models.CharField(blank=True, choices=[('click', 'CLICK'), ('type', 'TYPE'), ('url', 'GO TO URL'), ('submit', 'SUBMIT')], default='click', max_length=256),
),
migrations.AlterField(
model_name='action',
name='name',
field=models.CharField(blank=True, max_length=256),
),
migrations.AlterField(
model_name='action',
name='selector',
field=models.CharField(blank=True, max_length=256),
),
]
12 changes: 5 additions & 7 deletions TestYourTech/models.py
Expand Up @@ -29,19 +29,17 @@ class Result(models.Model):
def __str__(self):
return self.name
name = models.CharField(max_length=256)
selector = models.ForeignKey(Selector, on_delete=models.CASCADE)
selector = models.CharField(max_length=256)
value = models.CharField(max_length=256, blank=True)


class Action(models.Model):
def __str__(self):
return self.name
name = models.CharField(max_length=256)
action_type = models.CharField(max_length=256, choices=ACTION_TYPES, default='click')
selector = models.CharField(max_length=256) #ONLY XPATH
name = models.CharField(max_length=256, blank=True)
action_type = models.CharField(max_length=256, blank=True, choices=ACTION_TYPES, default='click')
selector = models.CharField(max_length=256, blank=True) #ONLY XPATH
value = models.CharField(max_length=256, blank=True, null=True)
testcases = models.ManyToManyField(
TestCase,
blank=True)
result = models.ForeignKey(Result, on_delete=models.CASCADE, null=True, blank=True)
action_link = models.ManyToManyField('self', through='ActionLink', symmetrical=False)

Expand Down
2 changes: 0 additions & 2 deletions TestYourTech/serializers.py
Expand Up @@ -17,8 +17,6 @@ class Meta:
model = Result
fields = '__all__'
class ActionSerializer(serializers.ModelSerializer):
testcases = TestCaseSerializer(many=True)
results = ResultSerializer(many=True)
class Meta:
model = Action
fields = '__all__'
Expand Down
1 change: 0 additions & 1 deletion TestYourTech/urls.py
Expand Up @@ -22,7 +22,6 @@
path('', HomeView.as_view(), name='home'),
path('action/run/', runView, name='run'),
path('action/run_test/', runTestView.as_view()),
path('actions/', ActionView.as_view()),
path('action/<int:action_pk>/result/', action_result_list),
path('action/<int:action_pk>/result/<int:result_pk>/', action_result_detail),
]
Expand Down
51 changes: 28 additions & 23 deletions TestYourTech/views.py
Expand Up @@ -52,42 +52,46 @@ def open_url(browser1, selector1, value1):
elif function == 'submit':
function = submit
return function(browser, selector, value)
def find_paths(path_so_far, cur_action_id):
out = []
paths_to_take = ActionLink.objects.filter(id=cur_action_id)
if len(paths_to_take) == 0:
return [cur_action_id]
for path in paths_to_take:
out += find_paths(path_so_far + [cur_action_id], path.id)
return out
def _validate(browser, selector, value):
if not value:
print("Result validate value not set")
return True
element = WebDriverWait(browser1, 10).until(
EC.presence_of_element_located((By.XPATH, selector1))
)
return element.text == value
@csrf_exempt
def runView(request):
if request.method == 'POST':
message = ""
# initiate the browser
webdriver_dir = SystemVariable.objects.get(pk='webdriver_dir').value
computer_type = SystemVariable.objects.get(pk='computer_type').value

# initiate the actions
try:
action = Action.objects.get(id=int(request.POST.get("action_id", 0)))
except Action.DoesNotExist:
return HttpResponse(status=404)
browser = webdriver.Chrome(os.path.join(os.path.join(webdriver_dir, computer_type), "chromedriver.exe"))
paths = find_paths([], action.id)
pprint(paths)
# while True:
# print("Action now: ", action.name)
# function = action.action_type
# selector = action.selector
# value = action.value
# _execute(browser, function, selector, value)
# try:
# new_id = ActionLink.objects.get(this=action.id).after.id
# print("new id ", new_id)
# action = Action.objects.get(id=new_id)
# except:
# break
while True:
print("Action now: ", action.name)
function = action.action_type
selector = action.selector
value = action.value
_execute(browser, function, selector, value)

if _validate(browser, action.result.selector, action.result.value):
message += action.name + ": Success\n"
else:
message += action.name + ": Fail\n"
try:
new_id = ActionLink.objects.get(this=action.id).after.id
action = Action.objects.get(id=new_id)
except:
break
browser.quit()
if message:
return HttpResponse(message)
return HttpResponse('Ran test without errors')

class runTestView(View):
Expand Down Expand Up @@ -122,6 +126,7 @@ def model_list(request, Model, ModelSerializer):
serializer = ModelSerializer(model, many=True)
return JsonResponse(serializer.data, safe=False)
elif request.method == 'POST':
pprint(request.POST)
data = JSONParser().parse(request)
serializer = ModelSerializer(data=data)
if serializer.is_valid():
Expand Down
11 changes: 11 additions & 0 deletions scripts/click.py
@@ -0,0 +1,11 @@
class Click(ActionBase):
def _execute(self):
try:
element = WebDriverWait(browser1, 10).until(
EC.presence_of_element_located((By.XPATH, selector1))
)
element.click()
return True
except:
print("timedout", function, selector1, value1)
return False
20 changes: 20 additions & 0 deletions scripts/core.py
@@ -0,0 +1,20 @@
import traceback
class ActionBase(object):
def __init__(self, *args, **kwargs):
pass
def _setup(self):
pass
def _execute(self):
pass
def _cleanup(self):
pass

def run(self):
try:
self._setup()
result = self._execute()
self._cleanup()
except:
result = False
traceback.print_exc()
return result
1 change: 1 addition & 0 deletions scripts/submit.py
@@ -0,0 +1 @@

16 changes: 14 additions & 2 deletions static/TestYourTech/js/box.js
Expand Up @@ -26,8 +26,10 @@ var actionBox = '<div class="step col-md-3 rp"><div class="box action new">\
</div>\
<div class="col-xs-8 rp">\
<select class="box-type">\
<option value="form">Form</option>\
<option value="click">Click</option>\
<option value="">--Select One--</option>\
<option value="url">URL</option>\
<option value="type">Typing</option>\
<option value="click" selected="">Click</option>\
</select>\
<input class="selector" type="text">\
</div>\
Expand All @@ -47,6 +49,16 @@ $(document).ready(function() {
function actionBoxListener(box) {
box.find(".box-btn.next-action").click(function() {
// generate the html of the new actionbox
var actionId = $(this).closest(".box").attr("id").split('-')[1];
$.post('actions/',JSON.stringify({"name":"what"}), function(data, status) {
alert("Data: " + data + "\nStatus: " + status);
$.post(
'action_link/',
JSON.stringify({"this":actionId , "after":data['id']}),
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
});
});
$(this).closest(".step.col-md-3").after(actionBox);
// attach all listeners to it
actionBoxListener($(".box.action.new"));
Expand Down
4 changes: 2 additions & 2 deletions static/TestYourTech/js/send.js
Expand Up @@ -24,9 +24,9 @@ function attachRunListener() {
$(".box.action .box-btn.run-box").click(function() {
var actionId = $(this).closest(".box").attr("id");
$.post(
'action/run_test/',
'action/run/',
{
'action_id':actionId
'action_id':actionId.split('-')[1]
},
function(data, status){
alert("Data: " + data + "\nStatus: " + status);
Expand Down

0 comments on commit d5019f7

Please sign in to comment.